| 109 | } |
| 110 | |
| 111 | func 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 | |
| 141 | func (s asciiSetStringScanner) index(input string) int { |
| 142 | if !s.useRange { |