diff options
| author | Shulhan <ms@kilabit.info> | 2023-03-11 11:38:31 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-03-12 11:34:23 +0700 |
| commit | 61786b2a6c1a7c9d11ee18cab4a804afdce9ffa5 (patch) | |
| tree | 391a1cdaba298272fa633954b9bae5f039de9634 /lib/parser/parser_example_test.go | |
| parent | d759b751c0b055b9cc592155e48280740558ad24 (diff) | |
| download | pakakeh.go-61786b2a6c1a7c9d11ee18cab4a804afdce9ffa5.tar.xz | |
lib/parser: add method TokenTrimSpace
The TokenTrimSpace read the next token until one of the delimiter found,
with leading and trailing spaces are ignored.
Diffstat (limited to 'lib/parser/parser_example_test.go')
| -rw-r--r-- | lib/parser/parser_example_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/parser/parser_example_test.go b/lib/parser/parser_example_test.go index e5419353..b4c4c9f5 100644 --- a/lib/parser/parser_example_test.go +++ b/lib/parser/parser_example_test.go @@ -27,3 +27,27 @@ func ExampleNew() { // "key" '=' // "value" '\x00' } + +func ExampleParser_TokenTrimSpace() { + var ( + content = " 1 , \r\t\f, 2 , 3 , 4 , " + p = New(content, `,`) + + tok string + r rune + ) + for { + tok, r = p.TokenTrimSpace() + fmt.Printf("%q\n", tok) + if r == 0 { + break + } + } + // Output: + // "1" + // "" + // "2" + // "3" + // "4" + // "" +} |
