all: Use strings.Cut

Updates #9687
This commit is contained in:
Bjørn Erik Pedersen 2022-03-17 21:58:54 +01:00
parent 5adb81ce39
commit 0e305d6958
3 changed files with 8 additions and 12 deletions

View file

@ -41,8 +41,8 @@ func SetEnvVars(oldVars *[]string, keyValues ...string) {
} }
func SplitEnvVar(v string) (string, string) { func SplitEnvVar(v string) (string, string) {
parts := strings.SplitN(v, "=", 2) name, value, _ := strings.Cut(v, "=")
return parts[0], parts[1] return name, value
} }
func setEnvVar(vars *[]string, key, value string) { func setEnvVar(vars *[]string, key, value string) {

View file

@ -402,11 +402,8 @@ func (m Mount) Component() string {
} }
func (m Mount) ComponentAndName() (string, string) { func (m Mount) ComponentAndName() (string, string) {
k := strings.Index(m.Target, fileSeparator) c, n, _ := strings.Cut(m.Target, fileSeparator)
if k == -1 { return c, n
return m.Target, ""
}
return m.Target[:k], m.Target[k+1:]
} }
func getStaticDirs(cfg config.Provider) []string { func getStaticDirs(cfg config.Provider) []string {

View file

@ -107,15 +107,14 @@ func applyFnToThis(ctx context.Context, fn, this reflect.Value, args ...any) (re
} }
func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) { func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) {
if !strings.ContainsRune(fname, '.') { namespace, methodName, ok := strings.Cut(fname, ".")
if !ok {
templ := ns.deps.Tmpl().(tpl.TemplateFuncGetter) templ := ns.deps.Tmpl().(tpl.TemplateFuncGetter)
return templ.GetFunc(fname) return templ.GetFunc(fname)
} }
ss := strings.SplitN(fname, ".", 2)
// Namespace // Namespace
nv, found := ns.lookupFunc(ss[0]) nv, found := ns.lookupFunc(namespace)
if !found { if !found {
return reflect.Value{}, false return reflect.Value{}, false
} }
@ -131,7 +130,7 @@ func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) {
nv = reflect.ValueOf(v) nv = reflect.ValueOf(v)
// method // method
m := hreflect.GetMethodByName(nv, ss[1]) m := hreflect.GetMethodByName(nv, methodName)
if m.Kind() == reflect.Invalid { if m.Kind() == reflect.Invalid {
return reflect.Value{}, false return reflect.Value{}, false