decodeStringInput decodes into exact-size storage a returned match can own.
(s string, startAt int, pooled bool)
| 74 | |
| 75 | // decodeStringInput decodes into exact-size storage a returned match can own. |
| 76 | func (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 |