mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 05:16:35 +08:00
Replace Index*, SplitN with Cut
This commit is contained in:
parent
8fe209a447
commit
e1f453c27e
@ -369,11 +369,8 @@ func setTimeDuration(val string, value reflect.Value) error {
|
||||
}
|
||||
|
||||
func head(str, sep string) (head string, tail string) {
|
||||
idx := strings.Index(str, sep)
|
||||
if idx < 0 {
|
||||
return str, ""
|
||||
}
|
||||
return str[:idx], str[idx+len(sep):]
|
||||
head, tail, _ = strings.Cut(str, sep)
|
||||
return head, tail
|
||||
}
|
||||
|
||||
func setFormMap(ptr any, form map[string][]string) error {
|
||||
|
@ -562,10 +562,10 @@ func (c *Context) get(m map[string][]string, key string) (map[string]string, boo
|
||||
dicts := make(map[string]string)
|
||||
exist := false
|
||||
for k, v := range m {
|
||||
if i := strings.IndexByte(k, '['); i >= 1 && k[0:i] == key {
|
||||
if j := strings.IndexByte(k[i+1:], ']'); j >= 1 {
|
||||
if before, after, found := strings.Cut(k, "["); found && before == key {
|
||||
if before, _, found := strings.Cut(after, "]"); found && before != "" {
|
||||
exist = true
|
||||
dicts[k[i+1:][:j]] = v[0]
|
||||
dicts[before] = v[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
tree.go
7
tree.go
@ -241,9 +241,10 @@ walk:
|
||||
// Wildcard conflict
|
||||
pathSeg := path
|
||||
if n.nType != catchAll {
|
||||
pathSeg = strings.SplitN(pathSeg, "/", 2)[0]
|
||||
pathSeg, _, _ = strings.Cut(pathSeg, "/")
|
||||
}
|
||||
prefix := fullPath[:strings.Index(fullPath, pathSeg)] + n.path
|
||||
prefix, _, _ := strings.Cut(fullPath, pathSeg)
|
||||
prefix = prefix + n.path
|
||||
panic("'" + pathSeg +
|
||||
"' in new path '" + fullPath +
|
||||
"' conflicts with existing wildcard '" + n.path +
|
||||
@ -351,7 +352,7 @@ func (n *node) insertChild(path string, fullPath string, handlers HandlersChain)
|
||||
}
|
||||
|
||||
if len(n.path) > 0 && n.path[len(n.path)-1] == '/' {
|
||||
pathSeg := strings.SplitN(n.children[0].path, "/", 2)[0]
|
||||
pathSeg, _, _ := strings.Cut(n.children[0].path, "/")
|
||||
panic("catch-all wildcard '" + path +
|
||||
"' in new path '" + fullPath +
|
||||
"' conflicts with existing path segment '" + pathSeg +
|
||||
|
4
utils.go
4
utils.go
@ -104,8 +104,8 @@ func parseAccept(acceptHeader string) []string {
|
||||
parts := strings.Split(acceptHeader, ",")
|
||||
out := make([]string, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
if i := strings.IndexByte(part, ';'); i > 0 {
|
||||
part = part[:i]
|
||||
if before, _, found := strings.Cut(part, ";"); found {
|
||||
part = before
|
||||
}
|
||||
if part = strings.TrimSpace(part); part != "" {
|
||||
out = append(out, part)
|
||||
|
Loading…
x
Reference in New Issue
Block a user