SYS-REQ-046 Find end of the data structure, array or object. For array openSym and closeSym will be '[' and ']', for object '{' and '}'
(data []byte, openSym byte, closeSym byte)
| 199 | // Find end of the data structure, array or object. |
| 200 | // For array openSym and closeSym will be '[' and ']', for object '{' and '}' |
| 201 | func blockEnd(data []byte, openSym byte, closeSym byte) int { |
| 202 | level := 0 |
| 203 | i := 0 |
| 204 | ln := len(data) |
| 205 | |
| 206 | for i < ln { |
| 207 | switch data[i] { |
| 208 | case '"': // If inside string, skip it |
| 209 | se, _ := stringEnd(data[i+1:]) |
| 210 | if se == -1 { |
| 211 | return -1 |
| 212 | } |
| 213 | i += se |
| 214 | case openSym: // If open symbol, increase level |
| 215 | level++ |
| 216 | case closeSym: // If close symbol, increase level |
| 217 | level-- |
| 218 | |
| 219 | // If we have returned to the original level, we're done |
| 220 | if level == 0 { |
| 221 | return i + 1 |
| 222 | } |
| 223 | } |
| 224 | i++ |
| 225 | } |
| 226 | |
| 227 | return -1 |
| 228 | } |
| 229 | |
| 230 | // SYS-REQ-001, SYS-REQ-020, SYS-REQ-021, SYS-REQ-022, SYS-REQ-023, SYS-REQ-047 |
| 231 | func searchKeys(data []byte, keys ...string) int { |
searching dependent graphs…