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

Function stringIndexPrefixFilter

stringprefixfilter.go:143–167  ·  view source on GitHub ↗
(prefix string, ignoreCase bool, minRequiredLength int)

Source from the content-addressed store, hash-verified

141}
142
143func stringIndexPrefixFilter(prefix string, ignoreCase bool, minRequiredLength int) StringPrefixFilter {
144 if prefix == "" {
145 return nil
146 }
147 if ignoreCase && !isASCIIString(prefix) {
148 return nil
149 }
150
151 return func(input string, startAt int) (candidateByteIndex int, ok bool) {
152 if !hasMinRequiredBytes(input, startAt, minRequiredLength) {
153 return 0, false
154 }
155
156 var offset int
157 if ignoreCase {
158 offset = helpers.IndexStringIgnoreCaseASCII(input[startAt:], prefix)
159 } else {
160 offset = strings.Index(input[startAt:], prefix)
161 }
162 if offset < 0 {
163 return 0, false
164 }
165 return startAt + offset, true
166 }
167}
168
169func stringIndexPrefixesFilter(prefixes []string, ignoreCase bool, minRequiredLength int) StringPrefixFilter {
170 if len(prefixes) == 0 {

Calls 3

isASCIIStringFunction · 0.85
hasMinRequiredBytesFunction · 0.85