aboutsummaryrefslogtreecommitdiff
path: root/src/urubu/spec/grammar/util.go
blob: bf3f233f019416358f37fd21aa5f8c36b3541204 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)
}