aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/apparentlymart/go-textseg/textseg/all_tokens.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/apparentlymart/go-textseg/textseg/all_tokens.go')
-rw-r--r--vendor/github.com/apparentlymart/go-textseg/textseg/all_tokens.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/github.com/apparentlymart/go-textseg/textseg/all_tokens.go b/vendor/github.com/apparentlymart/go-textseg/textseg/all_tokens.go
new file mode 100644
index 0000000..5752e9e
--- /dev/null
+++ b/vendor/github.com/apparentlymart/go-textseg/textseg/all_tokens.go
@@ -0,0 +1,30 @@
1package textseg
2
3import (
4 "bufio"
5 "bytes"
6)
7
8// AllTokens is a utility that uses a bufio.SplitFunc to produce a slice of
9// all of the recognized tokens in the given buffer.
10func AllTokens(buf []byte, splitFunc bufio.SplitFunc) ([][]byte, error) {
11 scanner := bufio.NewScanner(bytes.NewReader(buf))
12 scanner.Split(splitFunc)
13 var ret [][]byte
14 for scanner.Scan() {
15 ret = append(ret, scanner.Bytes())
16 }
17 return ret, scanner.Err()
18}
19
20// TokenCount is a utility that uses a bufio.SplitFunc to count the number of
21// recognized tokens in the given buffer.
22func TokenCount(buf []byte, splitFunc bufio.SplitFunc) (int, error) {
23 scanner := bufio.NewScanner(bytes.NewReader(buf))
24 scanner.Split(splitFunc)
25 var ret int
26 for scanner.Scan() {
27 ret++
28 }
29 return ret, scanner.Err()
30}