MCPcopy
hub / github.com/caddyserver/caddy / firstSplit

Method firstSplit

modules/caddyhttp/fileserver/matcher.go:579–591  ·  view source on GitHub ↗

firstSplit returns the first result where the path can be split in two by a value in m.SplitPath. The return values are the first piece of the path that ends with the split substring and the remainder. If the path cannot be split, the path is returned as-is (with no remainder).

(path string)

Source from the content-addressed store, hash-verified

577// If the path cannot be split, the path is returned
578// as-is (with no remainder).
579func (m MatchFile) firstSplit(path string) (splitPart, remainder string) {
580 for _, split := range m.SplitPath {
581 if idx := indexFold(path, split); idx > -1 {
582 pos := idx + len(split)
583 // skip the split if it's not the final part of the filename
584 if pos != len(path) && !strings.HasPrefix(path[pos:], "/") {
585 continue
586 }
587 return path[:pos], path[pos:]
588 }
589 }
590 return path, ""
591}
592
593// There is no strings.IndexFold() function like there is strings.EqualFold(),
594// but we can use strings.EqualFold() to build our own case-insensitive

Callers 2

selectFileMethod · 0.95
TestFirstSplitFunction · 0.95

Calls 1

indexFoldFunction · 0.85

Tested by 1

TestFirstSplitFunction · 0.76