From 1338d2d896b78dc9ca0a29c0b2c75f74678483e9 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Tue, 24 Sep 2019 23:08:05 +0700 Subject: bytes: add function to take snippets from string by indexes --- lib/bytes/bytes_example_test.go | 14 ++++++++++++++ 1 file changed, 14 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 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 . 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 . All rights reserved.") token := []byte("right") -- cgit v1.3-5-g9baa