MCPcopy Create free account
hub / github.com/dlclark/regexp2 / decodeStringInput

Method decodeStringInput

decode.go:76–100  ·  view source on GitHub ↗

decodeStringInput decodes into exact-size storage a returned match can own.

(s string, startAt int, pooled bool)

Source from the content-addressed store, hash-verified

74
75// decodeStringInput decodes into exact-size storage a returned match can own.
76func (re *Regexp) decodeStringInput(s string, startAt int, pooled bool) decodedInput {
77 maxCachedLength := 0
78 if pooled {
79 maxCachedLength = re.optimizations.MaxCachedRuneBufferLength
80 }
81 decodeFrom := max(0, min(re.decodeFrom(s, startAt), len(s)))
82 substr := s[decodeFrom:]
83 buf, pooledBuffer := pooledMatchRuneBuffers.getExact(len(substr), maxCachedLength)
84 n, ascii := helpers.DecodeString(substr, buf)
85 out := decodedInput{
86 runes: buf[:n],
87 pooled: pooledBuffer,
88 byteOffset: decodeFrom,
89 ascii: ascii,
90 runeStart: startRuneIndex(s, startAt, decodeFrom, n, ascii),
91 matchBuffer: true,
92 }
93 // Byte index equals rune index only when the skipped prefix is also ASCII.
94 if ascii && (decodeFrom == 0 || helpers.IsASCII(s[:decodeFrom])) {
95 out.runeOffset = decodeFrom
96 } else if decodeFrom > 0 {
97 out.runeOffset = utf8.RuneCountInString(s[:decodeFrom])
98 }
99 return out
100}
101
102// decodeInput converts s[decodeFrom:] to runes for internal scans, which do not
103// need original-string offsets. Keep decoding in this call: an extra helper

Calls 7

decodeFromMethod · 0.95
DecodeStringFunction · 0.92
IsASCIIFunction · 0.92
maxFunction · 0.85
minFunction · 0.85
startRuneIndexFunction · 0.85
getExactMethod · 0.80