MCPcopy Create free account
hub / github.com/buger/jsonparser / stringEndConfig

Function stringEndConfig

parser.go:300–345  ·  view source on GitHub ↗

SYS-REQ-115

(_ Config, data []byte, quote byte)

Source from the content-addressed store, hash-verified

298
299// SYS-REQ-115
300func stringEndConfig(_ Config, data []byte, quote byte) (int, bool) {
301 // Fast path: SIMD-scan for the first matching quote or '\'. If no '\'
302 // precedes the first quote (the overwhelmingly common case for strings),
303 // the quote is unescaped and we return directly — skipping the per-byte
304 // escape-tracking loop. Bound: bytes.IndexByte finds the first match in
305 // either direction, so firstBackslash > firstQuote (or == -1) is exactly
306 // the condition "no backslash precedes the closing quote", which is
307 // equivalent to the slow loop's `escaped == false` state at the quote.
308 firstQuote := bytes.IndexByte(data, quote)
309 if firstQuote == -1 {
310 // Slow path's tail semantics: return -1 with escaped flag true iff
311 // at least one '\' was encountered before end-of-input.
312 return -1, bytes.IndexByte(data, '\\') != -1
313 }
314 firstBackslash := bytes.IndexByte(data, '\\')
315 if firstBackslash == -1 || firstBackslash > firstQuote {
316 return firstQuote + 1, false
317 }
318 // Slow path: at least one '\' precedes the first quote — the per-byte
319 // walker is needed to disambiguate escaped vs. unescaped quotes.
320 escaped := false
321 for i, c := range data {
322 if c == quote {
323 if !escaped {
324 return i + 1, false
325 } else {
326 j := i - 1
327 for {
328 if j < 0 || data[j] != '\\' {
329 return i + 1, true // even number of backslashes
330 }
331 j--
332 if j < 0 || data[j] != '\\' {
333 break // odd number of backslashes
334 }
335 j--
336
337 }
338 }
339 } else if c == '\\' {
340 escaped = true
341 }
342 }
343
344 return -1, escaped
345}
346
347// SYS-REQ-046
348// Find end of the data structure, array or object.

Callers 6

findKeyStartConfigFunction · 0.85
stringEndFunction · 0.85
blockEndConfigFunction · 0.85
searchKeysConfigFunction · 0.85
getTypeConfigFunction · 0.85
objectEachConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected