aboutsummaryrefslogtreecommitdiff
path: root/src/strings
diff options
context:
space:
mode:
authorhopehook <hopehook.com@gmail.com>2022-03-30 15:47:57 +0800
committerEmmanuel Odeke <emmanuel@orijtech.com>2022-04-02 06:48:45 +0000
commitf8e70fc9a6d2a88d51d36208e64b12a236fce1b1 (patch)
tree68f2a999787ff3c92a76410c07b852d7bcf7ca49 /src/strings
parent153c18a515c90a78bf4c90a56e4ba5b700f407b1 (diff)
downloadgo-f8e70fc9a6d2a88d51d36208e64b12a236fce1b1.tar.gz
go-f8e70fc9a6d2a88d51d36208e64b12a236fce1b1.zip
strings: document the use of simple case-folding in EqualFold
Fixes #52022 Change-Id: I077fc062dfd02f79eb83713490efbe0bdc783d8b Reviewed-on: https://go-review.googlesource.com/c/go/+/396616 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/strings')
-rw-r--r--src/strings/example_test.go7
-rw-r--r--src/strings/strings.go4
2 files changed, 9 insertions, 2 deletions
diff --git a/src/strings/example_test.go b/src/strings/example_test.go
index 94aa167f90..2a59512ceb 100644
--- a/src/strings/example_test.go
+++ b/src/strings/example_test.go
@@ -95,7 +95,12 @@ func ExampleCut() {
func ExampleEqualFold() {
fmt.Println(strings.EqualFold("Go", "go"))
- // Output: true
+ fmt.Println(strings.EqualFold("AB", "ab")) // true because comparison uses simple case-folding
+ fmt.Println(strings.EqualFold("ß", "ss")) // false because comparison does not use full case-folding
+ // Output:
+ // true
+ // true
+ // false
}
func ExampleFields() {
diff --git a/src/strings/strings.go b/src/strings/strings.go
index ed3184b59c..74e505338e 100644
--- a/src/strings/strings.go
+++ b/src/strings/strings.go
@@ -1041,8 +1041,10 @@ func ReplaceAll(s, old, new string) string {
}
// EqualFold reports whether s and t, interpreted as UTF-8 strings,
-// are equal under Unicode case-folding, which is a more general
+// are equal under simple Unicode case-folding, which is a more general
// form of case-insensitivity.
+//
+// EqualFold(s, t) is equivalent to Tolower(s) == Tolower(t).
func EqualFold(s, t string) bool {
for s != "" && t != "" {
// Extract first rune from each string.