使用utils.CutPrefix代替strings.CutPrefix

This commit is contained in:
GoEdgeLab
2023-11-13 18:17:32 +08:00
parent a142e187ad
commit e9173ad019
2 changed files with 15 additions and 1 deletions

View File

@@ -56,3 +56,16 @@ func EqualStrings(s1 []string, s2 []string) bool {
}
return true
}
// CutPrefix returns s without the provided leading prefix string
// and reports whether it found the prefix.
// If s doesn't start with prefix, CutPrefix returns s, false.
// If prefix is the empty string, CutPrefix returns s, true.
//
// copy from go source
func CutPrefix(s, prefix string) (after string, found bool) {
if !strings.HasPrefix(s, prefix) {
return s, false
}
return s[len(prefix):], true
}