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

Function stringFixedDistanceSetFilter

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

Source from the content-addressed store, hash-verified

96}
97
98func stringFixedDistanceSetFilter(set syntax.FixedDistanceSet, minRequiredLength int) StringPrefixFilter {
99 scanner, ok := newASCIISetStringScanner(set)
100 if !ok {
101 return nil
102 }
103
104 return func(input string, startAt int) (candidateByteIndex int, ok bool) {
105 if !hasMinRequiredBytes(input, startAt, minRequiredLength) {
106 return 0, false
107 }
108
109 for searchAt := startAt; searchAt < len(input); {
110 offset := scanner.index(input[searchAt:])
111 if offset < 0 {
112 return 0, false
113 }
114 setByteIndex := searchAt + offset
115 candidateByteIndex, valid := stringFixedDistanceCandidateStart(input, startAt, setByteIndex, scanner.distance)
116 if valid && hasMinRequiredBytes(input, candidateByteIndex, minRequiredLength) {
117 return candidateByteIndex, true
118 }
119 if valid {
120 return 0, false
121 }
122 searchAt = setByteIndex + 1
123 }
124 return 0, false
125 }
126}
127
128func (s asciiSetStringScanner) index(input string) int {
129 if !s.useRange {

Calls 4

newASCIISetStringScannerFunction · 0.85
hasMinRequiredBytesFunction · 0.85
indexMethod · 0.45