diff options
Diffstat (limited to 'spec/grammar/util.go')
-rw-r--r-- | spec/grammar/util.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/grammar/util.go b/spec/grammar/util.go new file mode 100644 index 0000000..bf3f233 --- /dev/null +++ b/spec/grammar/util.go @@ -0,0 +1,21 @@ +package grammar + +import "strings" + +var rep = strings.NewReplacer( + `.`, `\.`, + `*`, `\*`, + `+`, `\+`, + `?`, `\?`, + `|`, `\|`, + `(`, `\(`, + `)`, `\)`, + `[`, `\[`, + `\`, `\\`, +) + +// EscapePattern escapes the special characters. +// For example, EscapePattern(`+`) returns `\+`. +func EscapePattern(s string) string { + return rep.Replace(s) +} |