From e604254e38118bc4d46d55d0351ef07b2887a7d5 Mon Sep 17 00:00:00 2001
From: Eli Bendersky
Date: Sat, 5 Feb 2022 07:11:37 -0800
Subject: [PATCH] Tweaks to other samples to accommodate strings-and-runes
Add a link to the range sample, and remove partial mentions of this
topic in string-functions since it's now covered well in
strings-and-runes
---
examples/range/range.go | 2 +
examples/range/range.hash | 4 +-
examples/string-functions/string-functions.go | 13 -----
.../string-functions/string-functions.hash | 4 +-
examples/string-functions/string-functions.sh | 3 --
public/range | 6 ++-
public/string-functions | 51 ++-----------------
7 files changed, 14 insertions(+), 69 deletions(-)
diff --git a/examples/range/range.go b/examples/range/range.go
index 011af67..ec44c3f 100644
--- a/examples/range/range.go
+++ b/examples/range/range.go
@@ -42,6 +42,8 @@ func main() {
// `range` on strings iterates over Unicode code
// points. The first value is the starting byte index
// of the `rune` and the second the `rune` itself.
+ // See [Strings and Runes](strings-and-runes) for more
+ // details.
for i, c := range "go" {
fmt.Println(i, c)
}
diff --git a/examples/range/range.hash b/examples/range/range.hash
index f6e5a86..f2e2c7b 100644
--- a/examples/range/range.hash
+++ b/examples/range/range.hash
@@ -1,2 +1,2 @@
-c7d9ae9ed081fb4bbf27ef45242fbb39bbae3d4c
-pdZOtv4g-7J
+c8da490660d234fc420f39d9b8a4aba27f8aba46
+kRsyWNmLFLz
diff --git a/examples/string-functions/string-functions.go b/examples/string-functions/string-functions.go
index 676e904..5686f71 100644
--- a/examples/string-functions/string-functions.go
+++ b/examples/string-functions/string-functions.go
@@ -35,17 +35,4 @@ func main() {
p("ToLower: ", s.ToLower("TEST"))
p("ToUpper: ", s.ToUpper("test"))
p()
-
- // Not part of `strings`, but worth mentioning here, are
- // the mechanisms for getting the length of a string in
- // bytes and getting a byte by index.
- p("Len: ", len("hello"))
- p("Char:", "hello"[1])
}
-
-// Note that `len` and indexing above work at the byte level.
-// Go uses UTF-8 encoded strings, so this is often useful
-// as-is. If you're working with potentially multi-byte
-// characters you'll want to use encoding-aware operations.
-// See [strings, bytes, runes and characters in Go](https://blog.golang.org/strings)
-// for more information.
diff --git a/examples/string-functions/string-functions.hash b/examples/string-functions/string-functions.hash
index 68fb9a4..5f85212 100644
--- a/examples/string-functions/string-functions.hash
+++ b/examples/string-functions/string-functions.hash
@@ -1,2 +1,2 @@
-33b15b8c999ba65564b965b96cbfeadac0d1637d
-fZ_FqN5WlSz
+2201eba7e3b9339a6e700a4faa9b085c43dd1ed2
+pE_KNt12Zv9
diff --git a/examples/string-functions/string-functions.sh b/examples/string-functions/string-functions.sh
index b83688d..a38da5e 100644
--- a/examples/string-functions/string-functions.sh
+++ b/examples/string-functions/string-functions.sh
@@ -11,6 +11,3 @@ Replace: f0o
Split: [a b c d e]
ToLower: test
ToUpper: TEST
-
-Len: 5
-Char: 101
diff --git a/public/range b/public/range
index c151ca2..f1fb5b4 100644
--- a/public/range
+++ b/public/range
@@ -43,7 +43,7 @@ of the data structures we’ve already learned.
- 
+ 
package main
|
@@ -146,7 +146,9 @@ the indexes though.
range on strings iterates over Unicode code
points. The first value is the starting byte index
-of the rune and the second the rune itself.
+of the rune and the second the rune itself.
+See Strings and Runes for more
+details.
|
diff --git a/public/string-functions b/public/string-functions
index bb363ac..19849cd 100644
--- a/public/string-functions
+++ b/public/string-functions
@@ -43,7 +43,7 @@ to give you a sense of the package.
|
- 
+ 
package main
|
@@ -99,7 +99,7 @@ functions in the strings
package docs.
-
+ |
p("Contains: ", s.Contains("test", "es"))
@@ -115,43 +115,11 @@ package docs.
p("ToLower: ", s.ToLower("TEST"))
p("ToUpper: ", s.ToUpper("test"))
p()
-
- |
-
-
-
-
- Not part of strings , but worth mentioning here, are
-the mechanisms for getting the length of a string in
-bytes and getting a byte by index.
-
- |
-
-
-
- p("Len: ", len("hello"))
- p("Char:", "hello"[1])
}
|
-
-
- Note that len and indexing above work at the byte level.
-Go uses UTF-8 encoded strings, so this is often useful
-as-is. If you’re working with potentially multi-byte
-characters you’ll want to use encoding-aware operations.
-See strings, bytes, runes and characters in Go
-for more information.
-
- |
-
-
-
- |
-
-
@@ -160,7 +128,7 @@ for more information.
|
-
+ |
$ go run string-functions.go
Contains: true
@@ -178,17 +146,6 @@ for more information.
|
-
-
-
- |
-
-
- Len: 5
-Char: 101
- |
-
-
@@ -204,7 +161,7 @@ for more information.