diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-07-22 16:22:03 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-07-22 16:22:03 +0900 |
commit | a30fe0c6abd9ffbaff20af3da00eeea50d407f42 (patch) | |
tree | 2a1b03a4736f20c98f0fb7563b2b08b2dafe98ef /spec/util.go | |
parent | Support passive mode transition (diff) | |
download | tre-a30fe0c6abd9ffbaff20af3da00eeea50d407f42.tar.gz tre-a30fe0c6abd9ffbaff20af3da00eeea50d407f42.tar.xz |
Add spec.EscapePattern function
Diffstat (limited to 'spec/util.go')
-rw-r--r-- | spec/util.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/util.go b/spec/util.go new file mode 100644 index 0000000..56e9121 --- /dev/null +++ b/spec/util.go @@ -0,0 +1,21 @@ +package spec + +import "strings" + +var rep = strings.NewReplacer( + `.`, `\.`, + `*`, `\*`, + `+`, `\+`, + `?`, `\?`, + `|`, `\|`, + `(`, `\(`, + `)`, `\)`, + `[`, `\[`, + `\`, `\\`, +) + +// EscapePattern escapes the special characters. +// For example, EscapePattern(`+`) returns `\+`. +func EscapePattern(s string) string { + return rep.Replace(s) +} |