aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes/bytes_example_test.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2019-09-24 23:08:05 +0700
committerShulhan <m.shulhan@gmail.com>2019-09-25 00:43:59 +0700
commit1338d2d896b78dc9ca0a29c0b2c75f74678483e9 (patch)
treeeb28e1ba9d6d9e7175dddb7b95e95d97591b4f0c /lib/bytes/bytes_example_test.go
parent2011f07cc430a89879c326686ad0bdf9c7a314a7 (diff)
downloadpakakeh.go-1338d2d896b78dc9ca0a29c0b2c75f74678483e9.tar.xz
bytes: add function to take snippets from string by indexes
Diffstat (limited to 'lib/bytes/bytes_example_test.go')
-rw-r--r--lib/bytes/bytes_example_test.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/bytes/bytes_example_test.go b/lib/bytes/bytes_example_test.go
index bd6b41ea..06b96146 100644
--- a/lib/bytes/bytes_example_test.go
+++ b/lib/bytes/bytes_example_test.go
@@ -105,6 +105,20 @@ func ExampleSkipAfterToken() {
// 12 true
}
+func ExampleSnippetByIndexes() {
+ s := []byte("// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.")
+ indexes := []int{3, 20, len(s) - 4}
+
+ snippets := SnippetByIndexes(s, indexes, 5)
+ for _, snip := range snippets {
+ fmt.Printf("%s\n", snip)
+ }
+ // Output:
+ // // Copyr
+ // 18, Shulha
+ // reserved.
+}
+
func ExampleTokenFind() {
line := []byte("// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.")
token := []byte("right")