From 8359c047aaebe274a2d811d61922b571ca7d10df Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 10 Dec 2024 12:29:03 -0300 Subject: Namespace packages with "urubu/" --- src/urubu/spec/grammar/util.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/urubu/spec/grammar/util.go (limited to 'src/urubu/spec/grammar/util.go') diff --git a/src/urubu/spec/grammar/util.go b/src/urubu/spec/grammar/util.go new file mode 100644 index 0000000..bf3f233 --- /dev/null +++ b/src/urubu/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) +} -- cgit v1.2.3