| 96 | } |
| 97 | |
| 98 | func 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 | |
| 128 | func (s asciiSetStringScanner) index(input string) int { |
| 129 | if !s.useRange { |