mirror of
https://github.com/golang/go.git
synced 2025-05-18 22:04:38 +00:00
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>
This commit is contained in:
parent
74f47206cf
commit
34f2365d88
@ -369,6 +369,23 @@ func ExampleQuoteToGraphic() {
|
|||||||
// "\" This is a ☺ \\n \""
|
// "\" 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() {
|
func ExampleUnquote() {
|
||||||
s, err := strconv.Unquote("You can't unquote a string without quotes")
|
s, err := strconv.Unquote("You can't unquote a string without quotes")
|
||||||
fmt.Printf("%q, %v\n", s, err)
|
fmt.Printf("%q, %v\n", s, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user