From 7eacd3ade3ecc83ee59ca8ce14cb60c2082096a3 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Tue, 24 Sep 2019 22:22:02 +0700 Subject: bytes: add function get all indexes of token in string --- lib/bytes/bytes_example_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/bytes/bytes_example_test.go') diff --git a/lib/bytes/bytes_example_test.go b/lib/bytes/bytes_example_test.go index 141d7f17..bd6b41ea 100644 --- a/lib/bytes/bytes_example_test.go +++ b/lib/bytes/bytes_example_test.go @@ -54,6 +54,16 @@ func ExampleEncloseToken() { // '// Copyright 2016-2018 \"_Shulhan \"_. All rights reserved.' true } +func ExampleIndexes() { + s := []byte("moo moomoo") + token := []byte("moo") + + idxs := Indexes(s, token) + fmt.Println(idxs) + // Output: + // [0 4 7] +} + func ExampleIsTokenAt() { line := []byte("Hello, world") token := []byte("world") -- cgit v1.3