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

Function newASCIISetStringScanner

stringprefixfilter.go:83–109  ·  view source on GitHub ↗
(set syntax.FixedDistanceSet)

Source from the content-addressed store, hash-verified

81}
82
83func newASCIISetStringScanner(set syntax.FixedDistanceSet) (asciiSetStringScanner, bool) {
84 if set.Negated || set.Distance < 0 {
85 return asciiSetStringScanner{}, false
86 }
87 if set.Range != nil {
88 if set.Range.First < 0 || set.Range.Last > utf8.RuneSelf-1 {
89 return asciiSetStringScanner{}, false
90 }
91 return asciiSetStringScanner{
92 first: byte(set.Range.First),
93 last: byte(set.Range.Last),
94 useRange: true,
95 distance: set.Distance,
96 }, true
97 }
98 if len(set.Chars) == 0 {
99 return asciiSetStringScanner{}, false
100 }
101 chars := make([]byte, len(set.Chars))
102 for i, ch := range set.Chars {
103 if ch < 0 || ch > utf8.RuneSelf-1 {
104 return asciiSetStringScanner{}, false
105 }
106 chars[i] = byte(ch)
107 }
108 return asciiSetStringScanner{chars: string(chars), distance: set.Distance}, true
109}
110
111func stringFixedDistanceSetFilter(set syntax.FixedDistanceSet, minRequiredLength int) StringPrefixFilter {
112 scanner, ok := newASCIISetStringScanner(set)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected