mirror of https://github.com/mickael-menu/zk
Remove dependency on `libicu` (#213)
parent
1167cb99ae
commit
3c634fb00a
@ -1,19 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package icu
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/mickael-menu/zk/internal/util/test/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestEscapePAttern(t *testing.T) {
|
|
||||||
tests := map[string]string{
|
|
||||||
`foo bar`: `foo bar`,
|
|
||||||
`\a`: `\\a`,
|
|
||||||
`.`: `\.`,
|
|
||||||
`^`: `\^`,
|
|
||||||
`$`: `\$`,
|
|
||||||
`(`: `\(`,
|
|
||||||
`)`: `\)`,
|
|
||||||
`[`: `\[`,
|
|
||||||
`]`: `\]`,
|
|
||||||
`{`: `\{`,
|
|
||||||
`}`: `\}`,
|
|
||||||
`|`: `\|`,
|
|
||||||
`*`: `\*`,
|
|
||||||
`+`: `\+`,
|
|
||||||
`?`: `\?`,
|
|
||||||
`(?:[A-Za-z0-9]+[._]?){1,}[A-Za-z0-9]+\@(?:(?:[A-Za-z0-9]+[-]?){1,}[A-Za-z0-9]+\.){1,}`: `\(\?:\[A-Za-z0-9\]\+\[\._\]\?\)\{1,\}\[A-Za-z0-9\]\+\\@\(\?:\(\?:\[A-Za-z0-9\]\+\[-\]\?\)\{1,\}\[A-Za-z0-9\]\+\\\.\)\{1,\}`,
|
|
||||||
}
|
|
||||||
|
|
||||||
for input, expected := range tests {
|
|
||||||
assert.Equal(t, EscapePattern(input), expected)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue