| 1 |
package ascii |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/segmentio/asm/internal/unsafebytes" |
| 5 |
) |
| 6 |
|
| 7 |
// EqualFold is a version of bytes.EqualFold designed to work on ASCII input |
| 8 |
// instead of UTF-8. |
| 9 |
// |
| 10 |
// When the program has guarantees that the input is composed of ASCII |
| 11 |
// characters only, it allows for greater optimizations. |
| 12 |
func EqualFold(a, b []byte) bool { |
| 13 |
return EqualFoldString(unsafebytes.String(a), unsafebytes.String(b)) |
| 14 |
} |
| 15 |
|
| 16 |
func HasPrefixFold(s, prefix []byte) bool { |
| 17 |
return len(s) >= len(prefix) && EqualFold(s[:len(prefix)], prefix) |
| 18 |
} |
| 19 |
|
| 20 |
func HasSuffixFold(s, suffix []byte) bool { |
| 21 |
return len(s) >= len(suffix) && EqualFold(s[len(s)-len(suffix):], suffix) |
| 22 |
} |
| 23 |
|
| 24 |
func HasPrefixFoldString(s, prefix string) bool { |
| 25 |
return len(s) >= len(prefix) && EqualFoldString(s[:len(prefix)], prefix) |
| 26 |
} |
| 27 |
|
| 28 |
func HasSuffixFoldString(s, suffix string) bool { |
| 29 |
return len(s) >= len(suffix) && EqualFoldString(s[len(s)-len(suffix):], suffix) |
| 30 |
} |