summaryrefslogtreecommitdiff
path: root/lib/bytes/parser_example_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-04-09 15:52:30 +0700
committerShulhan <ms@kilabit.info>2023-04-09 19:06:01 +0700
commitaf0eb7e03872e759527e00a004df066a0b03a871 (patch)
tree2d9a5f645a3ff3b5d805498129dda7ed91f244e9 /lib/bytes/parser_example_test.go
parentd90ce9219bf3822fa78e713fdd9f6677e08dbc74 (diff)
downloadpakakeh.go-af0eb7e03872e759527e00a004df066a0b03a871.tar.xz
lib/bytes: return the number of skipped chars on Skip(Horizontal)Spaces
Diffstat (limited to 'lib/bytes/parser_example_test.go')
-rw-r--r--lib/bytes/parser_example_test.go38
1 files changed, 20 insertions, 18 deletions
diff --git a/lib/bytes/parser_example_test.go b/lib/bytes/parser_example_test.go
index 25ee6ba1..c62258fe 100644
--- a/lib/bytes/parser_example_test.go
+++ b/lib/bytes/parser_example_test.go
@@ -209,25 +209,26 @@ func ExampleParser_SkipHorizontalSpaces() {
content = []byte(" \t\r\fA. \nB.")
delims = []byte{'.'}
parser = libbytes.NewParser(content, delims)
+ n int
)
- parser.SkipHorizontalSpaces()
+ n, _ = parser.SkipHorizontalSpaces()
token, d := parser.Read()
- fmt.Printf("token:%s delim:%c\n", token, d)
+ fmt.Printf("n:%d token:%s delim:%c\n", n, token, d)
- parser.SkipHorizontalSpaces()
+ n, _ = parser.SkipHorizontalSpaces()
token, d = parser.Read() // The token include \n.
- fmt.Printf("token:%s delim:%c\n", token, d)
+ fmt.Printf("n:%d token:%s delim:%c\n", n, token, d)
- parser.SkipHorizontalSpaces()
+ n, _ = parser.SkipHorizontalSpaces()
token, d = parser.Read() // The token include \n.
- fmt.Printf("token:%s delim:%d\n", token, d)
+ fmt.Printf("n:%d token:%s delim:%d\n", n, token, d)
// Output:
- // token:A delim:.
- // token:
+ // n:4 token:A delim:.
+ // n:1 token:
// B delim:.
- // token: delim:0
+ // n:0 token: delim:0
}
func ExampleParser_SkipSpaces() {
@@ -235,24 +236,25 @@ func ExampleParser_SkipSpaces() {
content = []byte(" \t\r\fA. \nB.")
delims = []byte{'.'}
parser = libbytes.NewParser(content, delims)
+ n int
)
- parser.SkipSpaces()
+ n, _ = parser.SkipSpaces()
token, d := parser.Read()
- fmt.Printf("token:%s delim:%c\n", token, d)
+ fmt.Printf("n:%d token:%s delim:%c\n", n, token, d)
- parser.SkipSpaces()
+ n, _ = parser.SkipSpaces()
token, d = parser.Read() // The token include \n.
- fmt.Printf("token:%s delim:%c\n", token, d)
+ fmt.Printf("n:%d token:%s delim:%c\n", n, token, d)
- parser.SkipSpaces()
+ n, _ = parser.SkipSpaces()
token, d = parser.Read() // The token include \n.
- fmt.Printf("token:%s delim:%d\n", token, d)
+ fmt.Printf("n:%d token:%s delim:%d\n", n, token, d)
// Output:
- // token:A delim:.
- // token:B delim:.
- // token: delim:0
+ // n:4 token:A delim:.
+ // n:2 token:B delim:.
+ // n:0 token: delim:0
}
func ExampleParser_Stop() {