[go] strings: document the use of simple case-folding in EqualFold

10 views
Skip to first unread message

Emmanuel Odeke (Gerrit)

unread,
Apr 2, 2022, 2:48:49 AM4/2/22
to hopehook, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Gopher Robot, Ian Lance Taylor, Robert Griesemer, Brad Fitzpatrick, golang-co...@googlegroups.com

Emmanuel Odeke submitted this change.

View Change


Approvals: Emmanuel Odeke: Looks good to me, approved Ian Lance Taylor: Looks good to me, approved; Run TryBots; Automatically submit change Gopher Robot: TryBots succeeded
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 <ia...@golang.org>
Run-TryBot: Ian Lance Taylor <ia...@golang.org>
Auto-Submit: Ian Lance Taylor <ia...@golang.org>
TryBot-Result: Gopher Robot <go...@golang.org>
Reviewed-by: Emmanuel Odeke <emma...@orijtech.com>
---
M src/strings/example_test.go
M src/strings/strings.go
2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/strings/example_test.go b/src/strings/example_test.go
index 94aa167..2a59512 100644
--- a/src/strings/example_test.go
+++ b/src/strings/example_test.go
@@ -95,7 +95,12 @@

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 ed3184b..74e5053 100644
--- a/src/strings/strings.go
+++ b/src/strings/strings.go
@@ -1041,8 +1041,10 @@
}

// 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.

To view, visit change 396616. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I077fc062dfd02f79eb83713490efbe0bdc783d8b
Gerrit-Change-Number: 396616
Gerrit-PatchSet: 5
Gerrit-Owner: hopehook <hope...@qq.com>
Gerrit-Reviewer: Emmanuel Odeke <emma...@orijtech.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
Gerrit-MessageType: merged
Reply all
Reply to author
Forward
0 new messages