From dff8d3f4295a343990974b8ea8eac52e4eccf4e4 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 9 Apr 2023 19:47:42 +0700 Subject: lib/bytes: add method ReadLine to Parser The ReadLine method read until it found new line ('\n') or end of content, ignoring all delimiters. The returned line will not contain '\n'. --- lib/bytes/parser_example_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/bytes/parser_example_test.go') diff --git a/lib/bytes/parser_example_test.go b/lib/bytes/parser_example_test.go index c62258fe..a30bda5a 100644 --- a/lib/bytes/parser_example_test.go +++ b/lib/bytes/parser_example_test.go @@ -37,6 +37,24 @@ func ExampleParser_Delimiters() { // =; } +func ExampleParser_ReadLine() { + var ( + content = []byte("a=b;\nc=d;") + delims = []byte{'=', ';'} + parser = libbytes.NewParser(content, delims) + ) + + token, c := parser.ReadLine() + fmt.Printf("token:%s c:%d\n", token, c) + + token, c = parser.ReadLine() + fmt.Printf("token:%s c:%d\n", token, c) + + // Output: + // token:a=b; c:10 + // token:c=d; c:0 +} + func ExampleParser_ReadN() { var ( content = []byte(`a=b;c=d;`) -- cgit v1.3