diff options
author | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
---|---|---|
committer | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
commit | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/mitchellh/go-wordwrap | |
parent | 07971ca38143c5faf951d152fba370ddcbe26ad5 (diff) | |
download | terraform-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/mitchellh/go-wordwrap')
-rw-r--r-- | vendor/github.com/mitchellh/go-wordwrap/LICENSE.md | 21 | ||||
-rw-r--r-- | vendor/github.com/mitchellh/go-wordwrap/README.md | 39 | ||||
-rw-r--r-- | vendor/github.com/mitchellh/go-wordwrap/wordwrap.go | 73 |
3 files changed, 133 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/go-wordwrap/LICENSE.md b/vendor/github.com/mitchellh/go-wordwrap/LICENSE.md new file mode 100644 index 0000000..2298515 --- /dev/null +++ b/vendor/github.com/mitchellh/go-wordwrap/LICENSE.md | |||
@@ -0,0 +1,21 @@ | |||
1 | The MIT License (MIT) | ||
2 | |||
3 | Copyright (c) 2014 Mitchell Hashimoto | ||
4 | |||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
6 | of this software and associated documentation files (the "Software"), to deal | ||
7 | in the Software without restriction, including without limitation the rights | ||
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
9 | copies of the Software, and to permit persons to whom the Software is | ||
10 | furnished to do so, subject to the following conditions: | ||
11 | |||
12 | The above copyright notice and this permission notice shall be included in | ||
13 | all copies or substantial portions of the Software. | ||
14 | |||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
21 | THE SOFTWARE. | ||
diff --git a/vendor/github.com/mitchellh/go-wordwrap/README.md b/vendor/github.com/mitchellh/go-wordwrap/README.md new file mode 100644 index 0000000..60ae311 --- /dev/null +++ b/vendor/github.com/mitchellh/go-wordwrap/README.md | |||
@@ -0,0 +1,39 @@ | |||
1 | # go-wordwrap | ||
2 | |||
3 | `go-wordwrap` (Golang package: `wordwrap`) is a package for Go that | ||
4 | automatically wraps words into multiple lines. The primary use case for this | ||
5 | is in formatting CLI output, but of course word wrapping is a generally useful | ||
6 | thing to do. | ||
7 | |||
8 | ## Installation and Usage | ||
9 | |||
10 | Install using `go get github.com/mitchellh/go-wordwrap`. | ||
11 | |||
12 | Full documentation is available at | ||
13 | http://godoc.org/github.com/mitchellh/go-wordwrap | ||
14 | |||
15 | Below is an example of its usage ignoring errors: | ||
16 | |||
17 | ```go | ||
18 | wrapped := wordwrap.WrapString("foo bar baz", 3) | ||
19 | fmt.Println(wrapped) | ||
20 | ``` | ||
21 | |||
22 | Would output: | ||
23 | |||
24 | ``` | ||
25 | foo | ||
26 | bar | ||
27 | baz | ||
28 | ``` | ||
29 | |||
30 | ## Word Wrap Algorithm | ||
31 | |||
32 | This library doesn't use any clever algorithm for word wrapping. The wrapping | ||
33 | is actually very naive: whenever there is whitespace or an explicit linebreak. | ||
34 | The goal of this library is for word wrapping CLI output, so the input is | ||
35 | typically pretty well controlled human language. Because of this, the naive | ||
36 | approach typically works just fine. | ||
37 | |||
38 | In the future, we'd like to make the algorithm more advanced. We would do | ||
39 | so without breaking the API. | ||
diff --git a/vendor/github.com/mitchellh/go-wordwrap/wordwrap.go b/vendor/github.com/mitchellh/go-wordwrap/wordwrap.go new file mode 100644 index 0000000..ac67205 --- /dev/null +++ b/vendor/github.com/mitchellh/go-wordwrap/wordwrap.go | |||
@@ -0,0 +1,73 @@ | |||
1 | package wordwrap | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "unicode" | ||
6 | ) | ||
7 | |||
8 | // WrapString wraps the given string within lim width in characters. | ||
9 | // | ||
10 | // Wrapping is currently naive and only happens at white-space. A future | ||
11 | // version of the library will implement smarter wrapping. This means that | ||
12 | // pathological cases can dramatically reach past the limit, such as a very | ||
13 | // long word. | ||
14 | func WrapString(s string, lim uint) string { | ||
15 | // Initialize a buffer with a slightly larger size to account for breaks | ||
16 | init := make([]byte, 0, len(s)) | ||
17 | buf := bytes.NewBuffer(init) | ||
18 | |||
19 | var current uint | ||
20 | var wordBuf, spaceBuf bytes.Buffer | ||
21 | |||
22 | for _, char := range s { | ||
23 | if char == '\n' { | ||
24 | if wordBuf.Len() == 0 { | ||
25 | if current+uint(spaceBuf.Len()) > lim { | ||
26 | current = 0 | ||
27 | } else { | ||
28 | current += uint(spaceBuf.Len()) | ||
29 | spaceBuf.WriteTo(buf) | ||
30 | } | ||
31 | spaceBuf.Reset() | ||
32 | } else { | ||
33 | current += uint(spaceBuf.Len() + wordBuf.Len()) | ||
34 | spaceBuf.WriteTo(buf) | ||
35 | spaceBuf.Reset() | ||
36 | wordBuf.WriteTo(buf) | ||
37 | wordBuf.Reset() | ||
38 | } | ||
39 | buf.WriteRune(char) | ||
40 | current = 0 | ||
41 | } else if unicode.IsSpace(char) { | ||
42 | if spaceBuf.Len() == 0 || wordBuf.Len() > 0 { | ||
43 | current += uint(spaceBuf.Len() + wordBuf.Len()) | ||
44 | spaceBuf.WriteTo(buf) | ||
45 | spaceBuf.Reset() | ||
46 | wordBuf.WriteTo(buf) | ||
47 | wordBuf.Reset() | ||
48 | } | ||
49 | |||
50 | spaceBuf.WriteRune(char) | ||
51 | } else { | ||
52 | |||
53 | wordBuf.WriteRune(char) | ||
54 | |||
55 | if current+uint(spaceBuf.Len()+wordBuf.Len()) > lim && uint(wordBuf.Len()) < lim { | ||
56 | buf.WriteRune('\n') | ||
57 | current = 0 | ||
58 | spaceBuf.Reset() | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | if wordBuf.Len() == 0 { | ||
64 | if current+uint(spaceBuf.Len()) <= lim { | ||
65 | spaceBuf.WriteTo(buf) | ||
66 | } | ||
67 | } else { | ||
68 | spaceBuf.WriteTo(buf) | ||
69 | wordBuf.WriteTo(buf) | ||
70 | } | ||
71 | |||
72 | return buf.String() | ||
73 | } | ||