1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:54:40 -07:00

path/filepath: steer people away from HasPrefix

The strikes against it are:

1. It does not take path boundaries into account.
2. It assumes that Windows==case-insensitive file system
and non-Windows==case-sensitive file system, neither of
which is always true.
3. Comparing ToLower against ToLower is not a correct
implementation of a case-insensitive string comparison.
4. If it returns true on Windows you still don't know how long
the matching prefix is in bytes, so you can't compute what
the suffix is.

R=golang-dev, r, dsymonds, r
CC=golang-dev
https://golang.org/cl/5712045
This commit is contained in:
Russ Cox 2012-02-29 16:37:40 -05:00
parent 8c5290502f
commit fc268acf05
3 changed files with 3 additions and 4 deletions

View File

@ -17,7 +17,7 @@ func VolumeName(path string) string {
return ""
}
// HasPrefix tests whether the path p begins with prefix.
// HasPrefix exists for historical compatibility and should not be used.
func HasPrefix(p, prefix string) bool {
return strings.HasPrefix(p, prefix)
}

View File

@ -19,7 +19,7 @@ func VolumeName(path string) string {
return ""
}
// HasPrefix tests whether the path p begins with prefix.
// HasPrefix exists for historical compatibility and should not be used.
func HasPrefix(p, prefix string) bool {
return strings.HasPrefix(p, prefix)
}

View File

@ -67,8 +67,7 @@ func VolumeName(path string) (v string) {
return ""
}
// HasPrefix tests whether the path p begins with prefix.
// It ignores case while comparing.
// HasPrefix exists for historical compatibility and should not be used.
func HasPrefix(p, prefix string) bool {
if strings.HasPrefix(p, prefix) {
return true