SYS-REQ-115
(config Config, data []byte, openSym byte, closeSym byte)
| 380 | |
| 381 | // SYS-REQ-115 |
| 382 | func blockEndConfig(config Config, data []byte, openSym byte, closeSym byte) int { |
| 383 | level := 0 |
| 384 | i := 0 |
| 385 | ln := len(data) |
| 386 | |
| 387 | for i < ln { |
| 388 | // Fast-skip non-structural bytes before dispatching to the switch. |
| 389 | // Two categories are skipped in bulk with a single comparison each: |
| 390 | // 1. Control/whitespace bytes (<= 0x20): indentation, spaces, newlines. |
| 391 | // 2. Bytes > 0x5C that are not the open/close symbol: lowercase letters |
| 392 | // (true/false/null), and high UTF-8 bytes. |
| 393 | // The open/close symbols themselves (e.g. '{'=0x7B, '}'=0x7D, ']'=0x5D) |
| 394 | // are > 0x5C and must NOT be skipped, hence the explicit exclusions. |
| 395 | // '"' (0x22), '\'' (0x27) and '[' (0x5B) are <= 0x5C so they are never |
| 396 | // caught by the second clause and always reach the switch. |
| 397 | for i < ln { |
| 398 | c := data[i] |
| 399 | if c <= ' ' { |
| 400 | i++ |
| 401 | continue |
| 402 | } |
| 403 | if c > '\\' && c != openSym && c != closeSym { |
| 404 | i++ |
| 405 | continue |
| 406 | } |
| 407 | break |
| 408 | } |
| 409 | if i >= ln { |
| 410 | break |
| 411 | } |
| 412 | switch data[i] { |
| 413 | case '"', '\'': // If inside a configured string, skip it |
| 414 | quote := data[i] |
| 415 | if quote == '\'' && !config.AllowSingleQuotes { |
| 416 | break |
| 417 | } |
| 418 | se, _ := stringEndConfig(config, data[i+1:], quote) |
| 419 | if se == -1 { |
| 420 | return -1 |
| 421 | } |
| 422 | i += se |
| 423 | case openSym: // If open symbol, increase level |
| 424 | level++ |
| 425 | case closeSym: // If close symbol, increase level |
| 426 | level-- |
| 427 | |
| 428 | // If we have returned to the original level, we're done |
| 429 | if level == 0 { |
| 430 | return i + 1 |
| 431 | } |
| 432 | } |
| 433 | i++ |
| 434 | } |
| 435 | |
| 436 | return -1 |
| 437 | } |
| 438 | |
| 439 | // SYS-REQ-001, SYS-REQ-020, SYS-REQ-021, SYS-REQ-022, SYS-REQ-023, SYS-REQ-047, SYS-REQ-111 |
no test coverage detected