mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
889 B
36 lines
889 B
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package regexp implements a simple regular expression library.
|
|
|
|
// QuoteMeta func is copied here to avoid linking the entire Regexp library.
|
|
|
|
package rubex
|
|
|
|
func special(c int) bool {
|
|
for _, r := range `\.+*?()|[]^$` {
|
|
if c == int(r) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// QuoteMeta returns a string that quotes all regular expression metacharacters
|
|
// inside the argument text; the returned string is a regular expression matching
|
|
// the literal text. For example, QuoteMeta(`[foo]`) returns `\[foo\]`.
|
|
func QuoteMeta(s string) string {
|
|
b := make([]byte, 2*len(s))
|
|
|
|
// A byte loop is correct because all metacharacters are ASCII.
|
|
j := 0
|
|
for i := 0; i < len(s); i++ {
|
|
if special(int(s[i])) {
|
|
b[j] = '\\'
|
|
j++
|
|
}
|
|
b[j] = s[i]
|
|
j++
|
|
}
|
|
return string(b[0:j])
|
|
}
|
|
|