diff options
Diffstat (limited to 'formspec.go')
-rw-r--r-- | formspec.go | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/formspec.go b/formspec.go index 08cfa38..a465143 100644 --- a/formspec.go +++ b/formspec.go @@ -2,31 +2,16 @@ package proxy import ( "regexp" - "strings" ) -var itemName = regexp.MustCompile("(item_image\\[[0-9.]+,[0-9.]+;[0-9.]+,[0-9]+;)([a-zA-Z0-9-_.: ]+)(\\])") -var itemButtonName = regexp.MustCompile("(item_image_button\\[[0-9.]+,[0-9.]+;[0-9.]+,[0-9.]+;)([a-zA-Z0-9-_.: ]+)(;[a-zA-Z0-9-_.: ]+;[^\\[\\]]*\\])") -var textureName = regexp.MustCompile("[a-zA-Z0-9-_.]*\\.[a-zA-Z-_.]+") +var itemName = regexp.MustCompile("(item_image\\[[0-9.-]+,[0-9.-]+;[0-9.-]+,[0-9.-]+;)([a-zA-Z0-9-_.: ]+)(\\])") +var itemButtonName = regexp.MustCompile("(item_image_button\\[[0-9.-]+,[0-9.-]+;[0-9.-]+,[0-9.-]+;)([a-zA-Z0-9-_.: ]+)(;[a-zA-Z0-9-_.: ]+;[^\\[\\]]*\\])") +var textureName = regexp.MustCompile("([a-zA-Z0-9-_.]+\\.[a-zA-Z-_.]+)") func (sc *ServerConn) prependFormspec(fs *string) { - subs := disallowedChars.Split(*fs, -1) - seps := disallowedChars.FindAllString(*fs, -1) - - for i, sub := range subs { - if textureName.MatchString(sub) && !strings.Contains(sub, " ") { - prepend(sc.mediaPool, &subs[i]) - } - } - - *fs = "" - for i, sub := range subs { - *fs += sub - if i < len(seps) { - *fs += seps[i] - } - } - + *fs = ReplaceAllStringSubmatchFunc(textureName, *fs, func(groups []string) string { + return sc.mediaPool + "_" + groups[1] + }) *fs = ReplaceAllStringSubmatchFunc(itemName, *fs, func(groups []string) string { return groups[1] + sc.name + "_" + groups[2] + groups[3] }) |