You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zk/internal/util/icu/icu.go

20 lines
403 B
Go

package icu
// EscapePattern adds backslash escapes to protect any characters that would
// match as ICU pattern metacharacters.
//
// http://userguide.icu-project.org/strings/regexp
func EscapePattern(s string) string {
out := ""
for _, c := range s {
switch c {
case '\\', '.', '^', '$', '(', ')', '[', ']', '{', '}', '|', '*', '+', '?':
out += `\`
}
out += string(c)
}
return out
}