aboutsummaryrefslogtreecommitdiff
path: root/src/urubu/spec/grammar/util.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-12-10 12:29:03 -0300
committerEuAndreh <eu@euandre.org>2024-12-10 12:29:03 -0300
commit8359c047aaebe274a2d811d61922b571ca7d10df (patch)
tree070e0ed93d27a842776ada805eeb4270e7e3c806 /src/urubu/spec/grammar/util.go
parentStart building test files (diff)
downloadcotia-8359c047aaebe274a2d811d61922b571ca7d10df.tar.gz
cotia-8359c047aaebe274a2d811d61922b571ca7d10df.tar.xz
Namespace packages with "urubu/"
Diffstat (limited to 'src/urubu/spec/grammar/util.go')
-rw-r--r--src/urubu/spec/grammar/util.go21
1 files changed, 21 insertions, 0 deletions
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)
+}