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)
| 577 | // If the path cannot be split, the path is returned |
| 578 | // as-is (with no remainder). |
| 579 | func (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 |