Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
This commit is contained in:
Cyril Tovena 2021-10-06 09:12:45 +02:00
parent d217825af8
commit 0bb2d1954b
No known key found for this signature in database
GPG key ID: FD8F768F9D633FB6

View file

@ -241,3 +241,32 @@ func optimizeConcatRegex(r *syntax.Regexp) (prefix, suffix, contains string) {
return
}
// todo remove anchors ^foo$
// .*POD.*
func contains(s, substr string) bool {
pos := strings.Index(s, substr)
if pos < 0 {
return false
}
return matchesAnyZeroOrMoreNotNL(s[:pos]) && matchesAnyZeroOrMoreNotNL(s[pos+len(substr):])
}
func matchesAnyZeroOrMoreNotNL(s string) bool {
for _, r := range s {
if r == '\n' {
return false
}
}
return true
}
func matchesOneZeroOrMoreNotNL(s string) bool {
for _, r := range s {
if r == '\n' {
return false
}
}
return len(s) > 0
}