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)
| 328 | // Find end of the data structure, array or object. |
| 329 | // For array openSym and closeSym will be '[' and ']', for object '{' and '}' |
| 330 | func blockEnd(data []byte, openSym byte, closeSym byte) int { |
| 331 | level := 0 |
| 332 | i := 0 |
| 333 | ln := len(data) |
| 334 | |
| 335 | for i < ln { |
| 336 | switch data[i] { |
| 337 | case '"': // If inside string, skip it |
| 338 | se, _ := stringEnd(data[i+1:]) |
| 339 | if se == -1 { |
| 340 | return -1 |
| 341 | } |
| 342 | i += se |
| 343 | case openSym: // If open symbol, increase level |
| 344 | level++ |
| 345 | case closeSym: // If close symbol, increase level |
| 346 | level-- |
| 347 | |
| 348 | // If we have returned to the original level, we're done |
| 349 | if level == 0 { |
| 350 | return i + 1 |
| 351 | } |
| 352 | } |
| 353 | i++ |
| 354 | } |
| 355 | |
| 356 | return -1 |
| 357 | } |
| 358 | |
| 359 | // SYS-REQ-001, SYS-REQ-020, SYS-REQ-021, SYS-REQ-022, SYS-REQ-023, SYS-REQ-047, SYS-REQ-111 |
| 360 | func searchKeys(data []byte, keys ...string) int { |