diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2021-09-13 10:42:44 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2021-09-13 10:42:44 +0200 |
commit | 1c3e21ace6a197f3b083c5bb3b4a0c4a8c914783 (patch) | |
tree | 8dccdbbdbe88a39e23448efb35e717bb67d5bb26 | |
parent | c609ac8358dc4a5a5d247802b60f043982da20ee (diff) |
Use globals for compiled regular expressions (anon5)
-rw-r--r-- | content.go | 7 | ||||
-rw-r--r-- | formspec.go | 10 |
2 files changed, 9 insertions, 8 deletions
@@ -17,6 +17,8 @@ import ( //go:generate go run gen_textures.go +var disallowedChars = regexp.MustCompile("[^a-zA-Z0-9-_.:]") + var b64 = base64.StdEncoding type mediaFile struct { @@ -502,9 +504,8 @@ func isDefaultNode(s string) bool { func prependRaw(prep string, s *string, isTexture bool) { if !isDefaultNode(*s) { - reg := regexp.MustCompile("[^a-zA-Z0-9-_.:]") - subs := reg.Split(*s, -1) - seps := reg.FindAllString(*s, -1) + subs := disallowedChars.Split(*s, -1) + seps := disallowedChars.FindAllString(*s, -1) for i, sub := range subs { if !isTexture || strings.Contains(sub, ".") { diff --git a/formspec.go b/formspec.go index 12553f1..a8a1ea2 100644 --- a/formspec.go +++ b/formspec.go @@ -5,14 +5,14 @@ import ( "strings" ) +var textureName = regexp.MustCompile("[a-zA-Z0-9-_.]*\\.[a-zA-Z-_.]+") + func (sc *ServerConn) prependFormspec(fs *string) { - reg := regexp.MustCompile("[^a-zA-Z0-9-_.:]") - reg2 := regexp.MustCompile("[a-zA-Z0-9-_.]*\\.[a-zA-Z-_.]+") - subs := reg.Split(*fs, -1) - seps := reg.FindAllString(*fs, -1) + subs := disallowedChars.Split(*fs, -1) + seps := disallowedChars.FindAllString(*fs, -1) for i, sub := range subs { - if reg2.MatchString(sub) && !strings.Contains(sub, " ") { + if textureName.MatchString(sub) && !strings.Contains(sub, " ") { prepend(sc.name, &subs[i]) } } |