summaryrefslogtreecommitdiff
path: root/lib/bytes/parser_example_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-02-07 01:32:44 +0700
committerShulhan <ms@kilabit.info>2025-04-18 13:59:35 +0700
commit5cc78f0f88433bca520a15e77c1ff97e27219ce9 (patch)
treed047949715dea37e3e65ce606cda45967acf4967 /lib/bytes/parser_example_test.go
parent503934b176c42eb9fed7bfa3c4c8823a0c037517 (diff)
downloadpakakeh.go-5cc78f0f88433bca520a15e77c1ff97e27219ce9.tar.xz
lib/bytes: add method Peek to Parser
The Peek method take a look on n bytes inside the buffer without using delimiters. The returned bytes may empty or have length less than n.
Diffstat (limited to 'lib/bytes/parser_example_test.go')
-rw-r--r--lib/bytes/parser_example_test.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/bytes/parser_example_test.go b/lib/bytes/parser_example_test.go
index b6582542..2f91c090 100644
--- a/lib/bytes/parser_example_test.go
+++ b/lib/bytes/parser_example_test.go
@@ -41,6 +41,22 @@ func ExampleParser_Delimiters() {
// =;
}
+func ExampleParser_Peek() {
+ var (
+ content = []byte("a = b; ")
+ delims = []byte{'=', ';'}
+ parser = libbytes.NewParser(content, delims)
+ )
+ var stream = parser.Peek(1)
+ fmt.Printf("peek=%q\n", stream)
+
+ stream = parser.Peek(len(content) + 1)
+ fmt.Printf("peek=%q\n", stream)
+ // Output:
+ // peek="a"
+ // peek="a = b; "
+}
+
func ExampleParser_Read() {
var (
content = []byte("a = b; ")