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

Function stringFixedDistanceSetFilter

stringprefixfilter.go:111–139  ·  view source on GitHub ↗
(set syntax.FixedDistanceSet, minRequiredLength int)

Source from the content-addressed store, hash-verified

109}
110
111func stringFixedDistanceSetFilter(set syntax.FixedDistanceSet, minRequiredLength int) StringPrefixFilter {
112 scanner, ok := newASCIISetStringScanner(set)
113 if !ok {
114 return nil
115 }
116
117 return func(input string, startAt int) (candidateByteIndex int, ok bool) {
118 if !hasMinRequiredBytes(input, startAt, minRequiredLength) {
119 return 0, false
120 }
121
122 for searchAt := startAt; searchAt < len(input); {
123 offset := scanner.index(input[searchAt:])
124 if offset < 0 {
125 return 0, false
126 }
127 setByteIndex := searchAt + offset
128 candidateByteIndex, valid := stringFixedDistanceCandidateStart(input, startAt, setByteIndex, scanner.distance)
129 if valid && hasMinRequiredBytes(input, candidateByteIndex, minRequiredLength) {
130 return candidateByteIndex, true
131 }
132 if valid {
133 return 0, false
134 }
135 searchAt = setByteIndex + 1
136 }
137 return 0, false
138 }
139}
140
141func (s asciiSetStringScanner) index(input string) int {
142 if !s.useRange {

Calls 4

newASCIISetStringScannerFunction · 0.85
hasMinRequiredBytesFunction · 0.85
indexMethod · 0.45