hasComponent returns whether the pathComponent is a path component of fullpath. i.e it is a part of fullpath that fits exactly between two path separators.
(component, fullpath string)
| 574 | // fullpath. i.e it is a part of fullpath that fits exactly between two path |
| 575 | // separators. |
| 576 | func hasComponent(component, fullpath string) bool { |
| 577 | // trim Windows volume name |
| 578 | fullpath = strings.TrimPrefix(fullpath, filepath.VolumeName(fullpath)) |
| 579 | for { |
| 580 | i := strings.Index(fullpath, component) |
| 581 | if i == -1 { |
| 582 | return false |
| 583 | } |
| 584 | if i != 0 && fullpath[i-1] == filepath.Separator { |
| 585 | componentEnd := i + len(component) |
| 586 | if componentEnd == len(fullpath) { |
| 587 | return true |
| 588 | } |
| 589 | if fullpath[componentEnd] == filepath.Separator { |
| 590 | return true |
| 591 | } |
| 592 | } |
| 593 | fullpath = fullpath[i+1:] |
| 594 | } |
| 595 | } |
no test coverage detected