| 351 | } |
| 352 | |
| 353 | func stringFixedDistanceStringFilter(literal string, distance, minRequiredLength int) StringPrefixFilter { |
| 354 | if literal == "" || distance < 0 || len(literal) > maxStringFilterLiteralLen { |
| 355 | return nil |
| 356 | } |
| 357 | |
| 358 | return withRuneErrorFallback(func(input string, startAt int) (candidateByteIndex int, ok bool) { |
| 359 | if !hasMinRequiredBytes(input, startAt, minRequiredLength) { |
| 360 | return 0, false |
| 361 | } |
| 362 | |
| 363 | searchAt := startAt |
| 364 | for searchAt <= len(input)-len(literal) { |
| 365 | offset := strings.Index(input[searchAt:], literal) |
| 366 | if offset < 0 { |
| 367 | return 0, false |
| 368 | } |
| 369 | literalIndex := searchAt + offset |
| 370 | candidateByteIndex, ok := stringFixedDistanceCandidateStart(input, startAt, literalIndex, distance) |
| 371 | if ok && hasMinRequiredBytes(input, candidateByteIndex, minRequiredLength) { |
| 372 | return candidateByteIndex, true |
| 373 | } |
| 374 | if ok { |
| 375 | return 0, false |
| 376 | } |
| 377 | searchAt = literalIndex + 1 |
| 378 | } |
| 379 | return 0, false |
| 380 | }, literal) |
| 381 | } |
| 382 | |
| 383 | func stringLiteralAfterLoopFilter(literal *syntax.LiteralAfterLoop, minRequiredLength int) StringPrefixFilter { |
| 384 | if literal == nil || literal.LoopNode == nil || literal.LoopNode.Set == nil { |