aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/apparentlymart/go-textseg/textseg/all_tokens.go
diff options
context:
space:
mode:
authorAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
committerAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
commit15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch)
tree255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/apparentlymart/go-textseg/textseg/all_tokens.go
parent07971ca38143c5faf951d152fba370ddcbe26ad5 (diff)
downloadterraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
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}