aboutsummaryrefslogtreecommitdiff
path: root/src/strconv
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2021-07-22 15:41:53 -0700
committerJoseph Tsai <joetsai@digital-static.net>2023-10-13 22:57:37 +0000
commit34f2365d883ddaab5da9f12d6cbe349d70d8deee (patch)
tree5a4c06892b2d932bc947cf4cedce3fb33af1a76d /src/strconv
parent74f47206cfd004829b6e09f42c2eadd0c1a958cb (diff)
downloadgo-34f2365d883ddaab5da9f12d6cbe349d70d8deee.tar.xz
strconv: add example for QuotedPrefix
Example can sometimes be more informative than additional prose. Fixes #46829 Change-Id: Ia5a5b121ad0b891026e77420d5f7f1b2c4a407da Reviewed-on: https://go-review.googlesource.com/c/go/+/336749 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/strconv')
-rw-r--r--src/strconv/example_test.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/strconv/example_test.go b/src/strconv/example_test.go
index b02392de6a..428fde4e66 100644
--- a/src/strconv/example_test.go
+++ b/src/strconv/example_test.go
@@ -369,6 +369,23 @@ func ExampleQuoteToGraphic() {
// "\" This is a ☺ \\n \""
}
+func ExampleQuotedPrefix() {
+ s, err := strconv.QuotedPrefix("not a quoted string")
+ fmt.Printf("%q, %v\n", s, err)
+ s, err = strconv.QuotedPrefix("\"double-quoted string\" with trailing text")
+ fmt.Printf("%q, %v\n", s, err)
+ s, err = strconv.QuotedPrefix("`or backquoted` with more trailing text")
+ fmt.Printf("%q, %v\n", s, err)
+ s, err = strconv.QuotedPrefix("'\u263a' is also okay")
+ fmt.Printf("%q, %v\n", s, err)
+
+ // Output:
+ // "", invalid syntax
+ // "\"double-quoted string\"", <nil>
+ // "`or backquoted`", <nil>
+ // "'☺'", <nil>
+}
+
func ExampleUnquote() {
s, err := strconv.Unquote("You can't unquote a string without quotes")
fmt.Printf("%q, %v\n", s, err)