aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ettle
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/ettle')
-rw-r--r--vendor/github.com/ettle/strcase/.golangci.yml8
-rw-r--r--vendor/github.com/ettle/strcase/.readme.tmpl8
-rw-r--r--vendor/github.com/ettle/strcase/Makefile9
-rw-r--r--vendor/github.com/ettle/strcase/README.md143
-rw-r--r--vendor/github.com/ettle/strcase/assert.go24
-rw-r--r--vendor/github.com/ettle/strcase/caser.go16
-rw-r--r--vendor/github.com/ettle/strcase/convert.go29
-rw-r--r--vendor/github.com/ettle/strcase/doc.go181
-rw-r--r--vendor/github.com/ettle/strcase/split.go1
9 files changed, 228 insertions, 191 deletions
diff --git a/vendor/github.com/ettle/strcase/.golangci.yml b/vendor/github.com/ettle/strcase/.golangci.yml
index 4d31fcc5b..b7ce85d42 100644
--- a/vendor/github.com/ettle/strcase/.golangci.yml
+++ b/vendor/github.com/ettle/strcase/.golangci.yml
@@ -14,8 +14,6 @@ linters-settings:
- ifElseChain
- whyNoLint
- wrapperFunc
- golint:
- min-confidence: 0.5
govet:
check-shadowing: true
lll:
@@ -37,7 +35,6 @@ linters:
disable-all: true
enable:
- bodyclose
- - deadcode
- depguard
- dogsled
- dupl
@@ -47,26 +44,23 @@ linters:
- gocyclo
- gofmt
- goimports
- - golint
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- - interfacer
- lll
- misspell
- nakedret
- nolintlint
+ - revive
- rowserrcheck
- staticcheck
- - structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- - varcheck
- whitespace
# don't enable:
diff --git a/vendor/github.com/ettle/strcase/.readme.tmpl b/vendor/github.com/ettle/strcase/.readme.tmpl
index 135765c40..4d7a894f0 100644
--- a/vendor/github.com/ettle/strcase/.readme.tmpl
+++ b/vendor/github.com/ettle/strcase/.readme.tmpl
@@ -16,10 +16,10 @@ Convert strings to `snake_case`, `camelCase`, `PascalCase`, `kebab-case` and mor
## <a name="pkg-index">Index</a>{{if .Consts}}
* [Constants](#pkg-constants){{end}}{{if .Vars}}
* [Variables](#pkg-variables){{end}}{{- range .Funcs -}}{{$name_html := html .Name}}
-* [{{node_html $ .Decl false | sanitize}}](#{{$name_html}}){{- end}}{{- range .Types}}{{$tname_html := html .Name}}
-* [type {{$tname_html}}](#{{$tname_html}}){{- range .Funcs}}{{$name_html := html .Name}}
- * [{{node_html $ .Decl false | sanitize}}](#{{$name_html}}){{- end}}{{- range .Methods}}{{$name_html := html .Name}}
- * [{{node_html $ .Decl false | sanitize}}](#{{$tname_html}}.{{$name_html}}){{- end}}{{- end}}{{- if $.Notes}}{{- range $marker, $item := $.Notes}}
+* [{{node_html $ .Decl false | sanitize}}](#func-{{$name_html}}){{- end}}{{- range .Types}}{{$tname_html := html .Name}}
+* [type {{$tname_html}}](#type-{{$tname_html}}){{- range .Funcs}}{{$name_html := html .Name}}
+ * [{{node_html $ .Decl false | sanitize}}](#func-{{$name_html}}){{- end}}{{- range .Methods}}{{$name_html := html .Name}}
+ * [{{node_html $ .Decl false | sanitize}}](#type-{{$tname_html}}.{{$name_html}}){{- end}}{{- end}}{{- if $.Notes}}{{- range $marker, $item := $.Notes}}
* [{{noteTitle $marker | html}}s](#pkg-note-{{$marker}}){{end}}{{end}}
{{if $.Examples}}
#### <a name="pkg-examples">Examples</a>{{- range $.Examples}}
diff --git a/vendor/github.com/ettle/strcase/Makefile b/vendor/github.com/ettle/strcase/Makefile
index 462f8b473..ac98b4aa5 100644
--- a/vendor/github.com/ettle/strcase/Makefile
+++ b/vendor/github.com/ettle/strcase/Makefile
@@ -1,16 +1,19 @@
.PHONY: benchmark docs lint test
docs:
- which godoc2ghmd || ( go get github.com/DevotedHealth/godoc2ghmd && go mod tidy )
+ which godoc2ghmd || go get github.com/DevotedHealth/godoc2ghmd
godoc2ghmd -template .readme.tmpl github.com/ettle/strcase > README.md
+ go mod tidy
test:
go test -cover ./...
lint:
- which golangci-lint || ( go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.27.0 && go mod tidy )
+ which golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1
golangci-lint run
golangci-lint run benchmark/*.go
+ go mod tidy
benchmark:
- cd benchmark && go test -bench=. -test.benchmem && go mod tidy
+ cd benchmark && go test -bench=. -test.benchmem
+ go mod tidy
diff --git a/vendor/github.com/ettle/strcase/README.md b/vendor/github.com/ettle/strcase/README.md
index ee165e3e5..a984da80d 100644
--- a/vendor/github.com/ettle/strcase/README.md
+++ b/vendor/github.com/ettle/strcase/README.md
@@ -32,21 +32,24 @@ Example usage
strcase.ToSnake("FOOBar") // foo_bar
// Support Go initialisms
- strcase.ToGoCamel("http_response") // HTTPResponse
+ strcase.ToGoPascal("http_response") // HTTPResponse
// Specify case and delimiter
strcase.ToCase("HelloWorld", strcase.UpperCase, '.') // HELLO.WORLD
-### Why this package
+## Why this package
+
String strcase is pretty straight forward and there are a number of methods to
do it. This package is fully featured, more customizable, better tested, and
-faster* than other packages and what you would probably whip up yourself.
+faster than other packages and what you would probably whip up yourself.
### Unicode support
+
We work for with unicode strings and pay very little performance penalty for it
as we optimized for the common use case of ASCII only strings.
### Customization
+
You can create a custom caser that changes the behavior to what you want. This
customization also reduces the pressure for us to change the default behavior
which means that things are more stable for everyone involved. The goal is to
@@ -71,19 +74,22 @@ make the common path easy and fast, while making the uncommon path possible.
assert.Equal(t, "http_200", c.ToSnake("http200"))
### Initialism support
+
By default, we use the golint intialisms list. You can customize and override
the initialisms if you wish to add additional ones, such as "SSL" or "CMS" or
domain specific ones to your industry.
- ToGoCamel("http_response") // HTTPResponse
+ ToGoPascal("http_response") // HTTPResponse
ToGoSnake("http_response") // HTTP_response
### Test coverage
+
We have a wide ranging test suite to make sure that we understand our behavior.
Test coverage isn't everything, but we aim for 100% coverage.
### Fast
+
Optimized to reduce memory allocations with Builder. Benchmarked and optimized
around common cases.
@@ -96,56 +102,57 @@ Hopefully I was fair to each library and happy to rerun benchmarks differently
or reword my commentary based on suggestions or updates.
- // This package
- // Go intialisms and custom casers are slower
- BenchmarkToTitle-4 992491 1559 ns/op 32 B/op 1 allocs/op
- BenchmarkToSnake-4 1000000 1475 ns/op 32 B/op 1 allocs/op
- BenchmarkToSNAKE-4 1000000 1609 ns/op 32 B/op 1 allocs/op
- BenchmarkToGoSnake-4 275010 3697 ns/op 44 B/op 4 allocs/op
- BenchmarkToCustomCaser-4 342704 4191 ns/op 56 B/op 4 allocs/op
+ // This package - faster then almost all libraries
+ // Initialisms are more complicated and slightly slower, but still fast
+ BenchmarkToTitle-96 9617142 125.7 ns/op 16 B/op 1 allocs/op
+ BenchmarkToSnake-96 10659919 120.7 ns/op 16 B/op 1 allocs/op
+ BenchmarkToSNAKE-96 9018282 126.4 ns/op 16 B/op 1 allocs/op
+ BenchmarkToGoSnake-96 4903687 254.5 ns/op 26 B/op 4 allocs/op
+ BenchmarkToCustomCaser-96 4434489 265.0 ns/op 28 B/op 4 allocs/op
// Segment has very fast snake case and camel case libraries
// No features or customization, but very very fast
- BenchmarkSegment-4 1303809 938 ns/op 16 B/op 1 allocs/op
+ BenchmarkSegment-96 33625734 35.54 ns/op 16 B/op 1 allocs/op
- // Stdlib strings.Title for comparison, even though it only splits on spaces
- BenchmarkToTitleStrings-4 1213467 1164 ns/op 16 B/op 1 allocs/op
+ // Iancoleman has gotten some performance improvements, but remains
+ // without unicode support and lacks fine-grained customization
+ BenchmarkToSnakeIan-96 13141522 92.99 ns/op 16 B/op 1 allocs/op
+
+ // Stdlib strings.Title is deprecated; using golang.org/x.text
+ BenchmarkGolangOrgXTextCases-96 4665676 262.5 ns/op 272 B/op 2 allocs/op
// Other libraries or code snippets
// - Most are slower, by up to an order of magnitude
- // - None support initialisms or customization
+ // - No support for initialisms or customization
// - Some generate only camelCase or snake_case
// - Many lack unicode support
- BenchmarkToSnakeStoewer-4 973200 2075 ns/op 64 B/op 2 allocs/op
+ BenchmarkToSnakeStoewer-96 8095468 148.9 ns/op 64 B/op 2 allocs/op
// Copying small rune arrays is slow
- BenchmarkToSnakeSiongui-4 264315 4229 ns/op 48 B/op 10 allocs/op
- BenchmarkGoValidator-4 206811 5152 ns/op 184 B/op 9 allocs/op
+ BenchmarkToSnakeSiongui-96 2912593 401.7 ns/op 112 B/op 19 allocs/op
+ BenchmarkGoValidator-96 3493800 342.6 ns/op 184 B/op 9 allocs/op
// String alloction is slow
- BenchmarkToSnakeFatih-4 82675 12280 ns/op 392 B/op 26 allocs/op
- BenchmarkToSnakeIanColeman-4 83276 13903 ns/op 145 B/op 13 allocs/op
+ BenchmarkToSnakeFatih-96 1282648 945.1 ns/op 616 B/op 26 allocs/op
// Regexp is slow
- BenchmarkToSnakeGolangPrograms-4 74448 18586 ns/op 176 B/op 11 allocs/op
+ BenchmarkToSnakeGolangPrograms-96 778674 1495 ns/op 227 B/op 11 allocs/op
// These results aren't a surprise - my initial version of this library was
// painfully slow. I think most of us, without spending some time with
// profilers and benchmarks, would write also something on the slower side.
-### Why not this package
+### Zero dependencies
+
+That's right - zero. We only import the Go standard library. No hassles with
+dependencies, licensing, security alerts.
+
+## Why not this package
+
If every nanosecond matters and this is used in a tight loop, use segment.io's
libraries (<a href="https://github.com/segmentio/go-snakecase">https://github.com/segmentio/go-snakecase</a> and
<a href="https://github.com/segmentio/go-camelcase">https://github.com/segmentio/go-camelcase</a>). They lack features, but make up for
-it by being blazing fast. Alternatively, if you need your code to work slightly
-differently, fork them and tailor it for your use case.
-
-If you don't like having external imports, I get it. This package only imports
-packages for testing, otherwise it only uses the standard library. If that's
-not enough, you can use this repo as the foundation for your own. MIT Licensed.
+it by being blazing fast.
-This package is still relatively new and while I've used it for a while
-personally, it doesn't have the miles that other packages do. I've tested this
-code agains't their test cases to make sure that there aren't any surprises.
+## Migrating from other packages
-### Migrating from other packages
If you are migrating from from another package, you may find slight differences
in output. To reduce the delta, you may find it helpful to use the following
custom casers to mimic the behavior of the other package.
@@ -161,32 +168,32 @@ custom casers to mimic the behavior of the other package.
## <a name="pkg-index">Index</a>
-* [func ToCamel(s string) string](#ToCamel)
-* [func ToCase(s string, wordCase WordCase, delimiter rune) string](#ToCase)
-* [func ToGoCamel(s string) string](#ToGoCamel)
-* [func ToGoCase(s string, wordCase WordCase, delimiter rune) string](#ToGoCase)
-* [func ToGoKebab(s string) string](#ToGoKebab)
-* [func ToGoPascal(s string) string](#ToGoPascal)
-* [func ToGoSnake(s string) string](#ToGoSnake)
-* [func ToKEBAB(s string) string](#ToKEBAB)
-* [func ToKebab(s string) string](#ToKebab)
-* [func ToPascal(s string) string](#ToPascal)
-* [func ToSNAKE(s string) string](#ToSNAKE)
-* [func ToSnake(s string) string](#ToSnake)
-* [type Caser](#Caser)
- * [func NewCaser(goInitialisms bool, initialismOverrides map[string]bool, splitFn SplitFn) *Caser](#NewCaser)
- * [func (c *Caser) ToCamel(s string) string](#Caser.ToCamel)
- * [func (c *Caser) ToCase(s string, wordCase WordCase, delimiter rune) string](#Caser.ToCase)
- * [func (c *Caser) ToKEBAB(s string) string](#Caser.ToKEBAB)
- * [func (c *Caser) ToKebab(s string) string](#Caser.ToKebab)
- * [func (c *Caser) ToPascal(s string) string](#Caser.ToPascal)
- * [func (c *Caser) ToSNAKE(s string) string](#Caser.ToSNAKE)
- * [func (c *Caser) ToSnake(s string) string](#Caser.ToSnake)
-* [type SplitAction](#SplitAction)
-* [type SplitFn](#SplitFn)
- * [func NewSplitFn(delimiters []rune, splitOptions ...SplitOption) SplitFn](#NewSplitFn)
-* [type SplitOption](#SplitOption)
-* [type WordCase](#WordCase)
+* [func ToCamel(s string) string](#func-ToCamel)
+* [func ToCase(s string, wordCase WordCase, delimiter rune) string](#func-ToCase)
+* [func ToGoCamel(s string) string](#func-ToGoCamel)
+* [func ToGoCase(s string, wordCase WordCase, delimiter rune) string](#func-ToGoCase)
+* [func ToGoKebab(s string) string](#func-ToGoKebab)
+* [func ToGoPascal(s string) string](#func-ToGoPascal)
+* [func ToGoSnake(s string) string](#func-ToGoSnake)
+* [func ToKEBAB(s string) string](#func-ToKEBAB)
+* [func ToKebab(s string) string](#func-ToKebab)
+* [func ToPascal(s string) string](#func-ToPascal)
+* [func ToSNAKE(s string) string](#func-ToSNAKE)
+* [func ToSnake(s string) string](#func-ToSnake)
+* [type Caser](#type-Caser)
+ * [func NewCaser(goInitialisms bool, initialismOverrides map[string]bool, splitFn SplitFn) *Caser](#func-NewCaser)
+ * [func (c *Caser) ToCamel(s string) string](#type-Caser.ToCamel)
+ * [func (c *Caser) ToCase(s string, wordCase WordCase, delimiter rune) string](#type-Caser.ToCase)
+ * [func (c *Caser) ToKEBAB(s string) string](#type-Caser.ToKEBAB)
+ * [func (c *Caser) ToKebab(s string) string](#type-Caser.ToKebab)
+ * [func (c *Caser) ToPascal(s string) string](#type-Caser.ToPascal)
+ * [func (c *Caser) ToSNAKE(s string) string](#type-Caser.ToSNAKE)
+ * [func (c *Caser) ToSnake(s string) string](#type-Caser.ToSnake)
+* [type SplitAction](#type-SplitAction)
+* [type SplitFn](#type-SplitFn)
+ * [func NewSplitFn(delimiters []rune, splitOptions ...SplitOption) SplitFn](#func-NewSplitFn)
+* [type SplitOption](#type-SplitOption)
+* [type WordCase](#type-WordCase)
@@ -201,7 +208,7 @@ Also known as lowerCamelCase or mixedCase.
-## <a name="ToCase">func</a> [ToCase](./strcase.go#L70)
+## <a name="ToCase">func</a> [ToCase](./strcase.go#L72)
``` go
func ToCase(s string, wordCase WordCase, delimiter rune) string
```
@@ -209,18 +216,20 @@ ToCase returns words in given case and delimiter.
-## <a name="ToGoCamel">func</a> [ToGoCamel](./strcase.go#L65)
+## <a name="ToGoCamel">func</a> [ToGoCamel](./strcase.go#L67)
``` go
func ToGoCamel(s string) string
```
ToGoCamel returns words in camelCase (capitalized words concatenated together, with first word lower case).
Also known as lowerCamelCase or mixedCase.
-Respects Go's common initialisms (e.g. httpResponse -> HTTPResponse).
+Respects Go's common initialisms, but first word remains lowercased which is
+important for code generator use cases (e.g. toJson -> toJSON, httpResponse
+-> httpResponse).
-## <a name="ToGoCase">func</a> [ToGoCase](./strcase.go#L77)
+## <a name="ToGoCase">func</a> [ToGoCase](./strcase.go#L79)
``` go
func ToGoCase(s string, wordCase WordCase, delimiter rune) string
```
@@ -415,7 +424,7 @@ ToSnake returns words in snake_case (lower case words with underscores).
-## <a name="SplitAction">type</a> [SplitAction](./split.go#L110)
+## <a name="SplitAction">type</a> [SplitAction](./split.go#L111)
``` go
type SplitAction int
```
@@ -457,7 +466,7 @@ SplitFn defines how to split a string into words
-### <a name="NewSplitFn">func</a> [NewSplitFn](./split.go#L14-L17)
+### <a name="NewSplitFn">func</a> [NewSplitFn](./split.go#L15-L18)
``` go
func NewSplitFn(
delimiters []rune,
@@ -469,13 +478,12 @@ NewSplitFn returns a SplitFn based on the options provided.
NewSplitFn covers the majority of common options that other strcase
libraries provide and should allow you to simply create a custom caser.
For more complicated use cases, feel free to write your own SplitFn
-nolint:gocyclo
-## <a name="SplitOption">type</a> [SplitOption](./split.go#L93)
+## <a name="SplitOption">type</a> [SplitOption](./split.go#L94)
``` go
type SplitOption int
```
@@ -524,6 +532,9 @@ const (
// TitleCase - Only first letter upper cased (Example)
TitleCase
// CamelCase - TitleCase except lower case first word (exampleText)
+ // Notably, even if the first word is an initialism, it will be lower
+ // cased. This is important for code generators where capital letters
+ // mean exported functions. i.e. jsonString(), not JSONString()
CamelCase
)
```
diff --git a/vendor/github.com/ettle/strcase/assert.go b/vendor/github.com/ettle/strcase/assert.go
new file mode 100644
index 000000000..09344e40f
--- /dev/null
+++ b/vendor/github.com/ettle/strcase/assert.go
@@ -0,0 +1,24 @@
+package strcase
+
+// We use a lightweight replacement for testify/assert to reduce dependencies
+
+// testingT interface allows us to test our assert functions
+type testingT interface {
+ Logf(format string, args ...interface{})
+ Fail()
+}
+
+// assertTrue will fail if the value is not true
+func assertTrue(t testingT, value bool) {
+ if !value {
+ t.Fail()
+ }
+}
+
+// assertEqual will fail if the two strings are not equal
+func assertEqual(t testingT, expected, actual string) {
+ if expected != actual {
+ t.Logf("Expected: %s Actual: %s", expected, actual)
+ t.Fail()
+ }
+}
diff --git a/vendor/github.com/ettle/strcase/caser.go b/vendor/github.com/ettle/strcase/caser.go
index 891a67189..2e7eb955b 100644
--- a/vendor/github.com/ettle/strcase/caser.go
+++ b/vendor/github.com/ettle/strcase/caser.go
@@ -10,17 +10,17 @@ type Caser struct {
//
// A Caser should be created when you want fine grained control over how the words are split.
//
-// Notes on function arguments
+// Notes on function arguments
//
-// goInitialisms: Whether to use Golint's intialisms
+// goInitialisms: Whether to use Golint's intialisms
//
-// initialismOverrides: A mapping of extra initialisms
-// Keys must be in ALL CAPS. Merged with Golint's if goInitialisms is set.
-// Setting a key to false will override Golint's.
+// initialismOverrides: A mapping of extra initialisms
+// Keys must be in ALL CAPS. Merged with Golint's if goInitialisms is set.
+// Setting a key to false will override Golint's.
//
-// splitFn: How to separate words
-// Override the default split function. Consider using NewSplitFn to
-// configure one instead of writing your own.
+// splitFn: How to separate words
+// Override the default split function. Consider using NewSplitFn to
+// configure one instead of writing your own.
func NewCaser(goInitialisms bool, initialismOverrides map[string]bool, splitFn SplitFn) *Caser {
c := &Caser{
initialisms: golintInitialisms,
diff --git a/vendor/github.com/ettle/strcase/convert.go b/vendor/github.com/ettle/strcase/convert.go
index 70fedb144..cb901d079 100644
--- a/vendor/github.com/ettle/strcase/convert.go
+++ b/vendor/github.com/ettle/strcase/convert.go
@@ -29,6 +29,7 @@ const (
// Case 2: UpperCase words, which don't need to support initialisms since everything is in upper case
// convertWithoutInitialims only works for to UpperCase and LowerCase
+//
//nolint:gocyclo
func convertWithoutInitialisms(input string, delimiter rune, wordCase WordCase) string {
input = strings.TrimSpace(input)
@@ -38,7 +39,7 @@ func convertWithoutInitialisms(input string, delimiter rune, wordCase WordCase)
}
var b strings.Builder
- b.Grow(len(input) * 2) // In case we need to write delimiters where they weren't before
+ b.Grow(len(input) + 4) // In case we need to write delimiters where they weren't before
var prev, curr rune
next := runes[0] // 0 length will have already returned so safe to index
@@ -90,13 +91,14 @@ func convertWithoutInitialisms(input string, delimiter rune, wordCase WordCase)
// Must be original case
b.WriteRune(curr)
}
- inWord = inWord || true
+ inWord = true
}
return b.String()
}
// convertWithGoInitialisms changes a input string to a certain case with a
// delimiter, respecting go initialisms but not skip runes
+//
//nolint:gocyclo
func convertWithGoInitialisms(input string, delimiter rune, wordCase WordCase) string {
input = strings.TrimSpace(input)
@@ -106,7 +108,7 @@ func convertWithGoInitialisms(input string, delimiter rune, wordCase WordCase) s
}
var b strings.Builder
- b.Grow(len(input) * 2) // In case we need to write delimiters where they weren't before
+ b.Grow(len(input) + 4) // In case we need to write delimiters where they weren't before
firstWord := true
@@ -122,10 +124,15 @@ func convertWithGoInitialisms(input string, delimiter rune, wordCase WordCase) s
// Don't bother with initialisms if the word is longer than 5
// A quick proxy to avoid the extra memory allocations
if end-start <= 5 {
- key := strings.ToUpper(string(runes[start:end]))
- if golintInitialisms[key] {
+ var word strings.Builder
+ word.Grow(end - start)
+ for i := start; i < end; i++ {
+ word.WriteRune(toUpper(runes[i]))
+ }
+ w := word.String()
+ if golintInitialisms[w] {
if !firstWord || wordCase != CamelCase {
- b.WriteString(key)
+ b.WriteString(w)
firstWord = false
return
}
@@ -188,6 +195,7 @@ func convertWithGoInitialisms(input string, delimiter rune, wordCase WordCase) s
// convert changes a input string to a certain case with a delimiter,
// respecting arbitrary initialisms and skip characters
+//
//nolint:gocyclo
func convert(input string, fn SplitFn, delimiter rune, wordCase WordCase,
initialisms map[string]bool) string {
@@ -198,7 +206,7 @@ func convert(input string, fn SplitFn, delimiter rune, wordCase WordCase,
}
var b strings.Builder
- b.Grow(len(input) * 2) // In case we need to write delimiters where they weren't before
+ b.Grow(len(input) + 4) // In case we need to write delimiters where they weren't before
firstWord := true
var skipIndexes []int
@@ -221,13 +229,14 @@ func convert(input string, fn SplitFn, delimiter rune, wordCase WordCase,
// I'm open to it if there is a use case
if initialisms != nil {
var word strings.Builder
+ word.Grow(end - start)
for i := start; i < end; i++ {
word.WriteRune(toUpper(runes[i]))
}
- key := word.String()
- if initialisms[key] {
+ w := word.String()
+ if initialisms[w] {
if !firstWord || wordCase != CamelCase {
- b.WriteString(key)
+ b.WriteString(w)
firstWord = false
return
}
diff --git a/vendor/github.com/ettle/strcase/doc.go b/vendor/github.com/ettle/strcase/doc.go
index b898a4e45..c3bf14a8f 100644
--- a/vendor/github.com/ettle/strcase/doc.go
+++ b/vendor/github.com/ettle/strcase/doc.go
@@ -2,78 +2,78 @@
Package strcase is a package for converting strings into various word cases
(e.g. snake_case, camelCase)
- go get -u github.com/ettle/strcase
+ go get -u github.com/ettle/strcase
Example usage
- strcase.ToSnake("Hello World") // hello_world
- strcase.ToSNAKE("Hello World") // HELLO_WORLD
+ strcase.ToSnake("Hello World") // hello_world
+ strcase.ToSNAKE("Hello World") // HELLO_WORLD
- strcase.ToKebab("helloWorld") // hello-world
- strcase.ToKEBAB("helloWorld") // HELLO-WORLD
+ strcase.ToKebab("helloWorld") // hello-world
+ strcase.ToKEBAB("helloWorld") // HELLO-WORLD
- strcase.ToPascal("hello-world") // HelloWorld
- strcase.ToCamel("hello-world") // helloWorld
+ strcase.ToPascal("hello-world") // HelloWorld
+ strcase.ToCamel("hello-world") // helloWorld
- // Handle odd cases
- strcase.ToSnake("FOOBar") // foo_bar
+ // Handle odd cases
+ strcase.ToSnake("FOOBar") // foo_bar
- // Support Go initialisms
- strcase.ToGoPascal("http_response") // HTTPResponse
+ // Support Go initialisms
+ strcase.ToGoPascal("http_response") // HTTPResponse
- // Specify case and delimiter
- strcase.ToCase("HelloWorld", strcase.UpperCase, '.') // HELLO.WORLD
+ // Specify case and delimiter
+ strcase.ToCase("HelloWorld", strcase.UpperCase, '.') // HELLO.WORLD
-Why this package
+## Why this package
String strcase is pretty straight forward and there are a number of methods to
do it. This package is fully featured, more customizable, better tested, and
-faster* than other packages and what you would probably whip up yourself.
+faster than other packages and what you would probably whip up yourself.
-Unicode support
+### Unicode support
We work for with unicode strings and pay very little performance penalty for it
as we optimized for the common use case of ASCII only strings.
-Customization
+### Customization
You can create a custom caser that changes the behavior to what you want. This
customization also reduces the pressure for us to change the default behavior
which means that things are more stable for everyone involved. The goal is to
make the common path easy and fast, while making the uncommon path possible.
- c := NewCaser(
- // Use Go's default initialisms e.g. ID, HTML
- true,
- // Override initialisms (e.g. don't initialize HTML but initialize SSL
- map[string]bool{"SSL": true, "HTML": false},
- // Write your own custom SplitFn
- //
- NewSplitFn(
- []rune{'*', '.', ','},
- SplitCase,
- SplitAcronym,
- PreserveNumberFormatting,
- SplitBeforeNumber,
- SplitAfterNumber,
- ))
- assert.Equal(t, "http_200", c.ToSnake("http200"))
-
-Initialism support
+ c := NewCaser(
+ // Use Go's default initialisms e.g. ID, HTML
+ true,
+ // Override initialisms (e.g. don't initialize HTML but initialize SSL
+ map[string]bool{"SSL": true, "HTML": false},
+ // Write your own custom SplitFn
+ //
+ NewSplitFn(
+ []rune{'*', '.', ','},
+ SplitCase,
+ SplitAcronym,
+ PreserveNumberFormatting,
+ SplitBeforeNumber,
+ SplitAfterNumber,
+ ))
+ assert.Equal(t, "http_200", c.ToSnake("http200"))
+
+### Initialism support
By default, we use the golint intialisms list. You can customize and override
the initialisms if you wish to add additional ones, such as "SSL" or "CMS" or
domain specific ones to your industry.
- ToGoPascal("http_response") // HTTPResponse
- ToGoSnake("http_response") // HTTP_response
+ ToGoPascal("http_response") // HTTPResponse
+ ToGoSnake("http_response") // HTTP_response
-Test coverage
+### Test coverage
We have a wide ranging test suite to make sure that we understand our behavior.
Test coverage isn't everything, but we aim for 100% coverage.
-Fast
+### Fast
Optimized to reduce memory allocations with Builder. Benchmarked and optimized
around common cases.
@@ -86,70 +86,65 @@ common cases have a large performance impact.
Hopefully I was fair to each library and happy to rerun benchmarks differently
or reword my commentary based on suggestions or updates.
- // This package - faster then almost all libraries
- // Initialisms are more complicated and slightly slower, but still faster then other libraries that do less
- BenchmarkToTitle-4 7821166 221 ns/op 32 B/op 1 allocs/op
- BenchmarkToSnake-4 9378589 202 ns/op 32 B/op 1 allocs/op
- BenchmarkToSNAKE-4 6174453 223 ns/op 32 B/op 1 allocs/op
- BenchmarkToGoSnake-4 3114266 434 ns/op 44 B/op 4 allocs/op
- BenchmarkToCustomCaser-4 2973855 448 ns/op 56 B/op 4 allocs/op
-
- // Segment has very fast snake case and camel case libraries
- // No features or customization, but very very fast
- BenchmarkSegment-4 24003495 64.9 ns/op 16 B/op 1 allocs/op
-
- // Stdlib strings.Title for comparison, even though it only splits on spaces
- BenchmarkToTitleStrings-4 11259376 161 ns/op 16 B/op 1 allocs/op
-
- // Other libraries or code snippets
- // - Most are slower, by up to an order of magnitude
- // - None support initialisms or customization
- // - Some generate only camelCase or snake_case
- // - Many lack unicode support
- BenchmarkToSnakeStoewer-4 7103268 297 ns/op 64 B/op 2 allocs/op
- // Copying small rune arrays is slow
- BenchmarkToSnakeSiongui-4 3710768 413 ns/op 48 B/op 10 allocs/op
- BenchmarkGoValidator-4 2416479 1049 ns/op 184 B/op 9 allocs/op
- // String alloction is slow
- BenchmarkToSnakeFatih-4 1000000 2407 ns/op 624 B/op 26 allocs/op
- BenchmarkToSnakeIanColeman-4 1005766 1426 ns/op 160 B/op 13 allocs/op
- // Regexp is slow
- BenchmarkToSnakeGolangPrograms-4 614689 2237 ns/op 225 B/op 11 allocs/op
-
-
-
- // These results aren't a surprise - my initial version of this library was
- // painfully slow. I think most of us, without spending some time with
- // profilers and benchmarks, would write also something on the slower side.
-
-
-Why not this package
+ // This package - faster then almost all libraries
+ // Initialisms are more complicated and slightly slower, but still fast
+ BenchmarkToTitle-96 9617142 125.7 ns/op 16 B/op 1 allocs/op
+ BenchmarkToSnake-96 10659919 120.7 ns/op 16 B/op 1 allocs/op
+ BenchmarkToSNAKE-96 9018282 126.4 ns/op 16 B/op 1 allocs/op
+ BenchmarkToGoSnake-96 4903687 254.5 ns/op 26 B/op 4 allocs/op
+ BenchmarkToCustomCaser-96 4434489 265.0 ns/op 28 B/op 4 allocs/op
+
+ // Segment has very fast snake case and camel case libraries
+ // No features or customization, but very very fast
+ BenchmarkSegment-96 33625734 35.54 ns/op 16 B/op 1 allocs/op
+
+ // Iancoleman has gotten some performance improvements, but remains
+ // without unicode support and lacks fine-grained customization
+ BenchmarkToSnakeIan-96 13141522 92.99 ns/op 16 B/op 1 allocs/op
+
+ // Stdlib strings.Title is deprecated; using golang.org/x.text
+ BenchmarkGolangOrgXTextCases-96 4665676 262.5 ns/op 272 B/op 2 allocs/op
+
+ // Other libraries or code snippets
+ // - Most are slower, by up to an order of magnitude
+ // - No support for initialisms or customization
+ // - Some generate only camelCase or snake_case
+ // - Many lack unicode support
+ BenchmarkToSnakeStoewer-96 8095468 148.9 ns/op 64 B/op 2 allocs/op
+ // Copying small rune arrays is slow
+ BenchmarkToSnakeSiongui-96 2912593 401.7 ns/op 112 B/op 19 allocs/op
+ BenchmarkGoValidator-96 3493800 342.6 ns/op 184 B/op 9 allocs/op
+ // String alloction is slow
+ BenchmarkToSnakeFatih-96 1282648 945.1 ns/op 616 B/op 26 allocs/op
+ // Regexp is slow
+ BenchmarkToSnakeGolangPrograms-96 778674 1495 ns/op 227 B/op 11 allocs/op
+
+ // These results aren't a surprise - my initial version of this library was
+ // painfully slow. I think most of us, without spending some time with
+ // profilers and benchmarks, would write also something on the slower side.
+
+### Zero dependencies
+
+That's right - zero. We only import the Go standard library. No hassles with
+dependencies, licensing, security alerts.
+
+## Why not this package
If every nanosecond matters and this is used in a tight loop, use segment.io's
libraries (https://github.com/segmentio/go-snakecase and
https://github.com/segmentio/go-camelcase). They lack features, but make up for
-it by being blazing fast. Alternatively, if you need your code to work slightly
-differently, fork them and tailor it for your use case.
-
-If you don't like having external imports, I get it. This package only imports
-packages for testing, otherwise it only uses the standard library. If that's
-not enough, you can use this repo as the foundation for your own. MIT Licensed.
+it by being blazing fast.
-This package is still relatively new and while I've used it for a while
-personally, it doesn't have the miles that other packages do. I've tested this
-code agains't their test cases to make sure that there aren't any surprises.
-
-Migrating from other packages
+## Migrating from other packages
If you are migrating from from another package, you may find slight differences
in output. To reduce the delta, you may find it helpful to use the following
custom casers to mimic the behavior of the other package.
- // From https://github.com/iancoleman/strcase
- var c = NewCaser(false, nil, NewSplitFn([]rune{'_', '-', '.'}, SplitCase, SplitAcronym, SplitBeforeNumber))
-
- // From https://github.com/stoewer/go-strcase
- var c = NewCaser(false, nil, NewSplitFn([]rune{'_', '-'}, SplitCase), SplitAcronym)
+ // From https://github.com/iancoleman/strcase
+ var c = NewCaser(false, nil, NewSplitFn([]rune{'_', '-', '.'}, SplitCase, SplitAcronym, SplitBeforeNumber))
+ // From https://github.com/stoewer/go-strcase
+ var c = NewCaser(false, nil, NewSplitFn([]rune{'_', '-'}, SplitCase), SplitAcronym)
*/
package strcase
diff --git a/vendor/github.com/ettle/strcase/split.go b/vendor/github.com/ettle/strcase/split.go
index 84381106b..32bc29759 100644
--- a/vendor/github.com/ettle/strcase/split.go
+++ b/vendor/github.com/ettle/strcase/split.go
@@ -10,6 +10,7 @@ type SplitFn func(prev, curr, next rune) SplitAction
// NewSplitFn covers the majority of common options that other strcase
// libraries provide and should allow you to simply create a custom caser.
// For more complicated use cases, feel free to write your own SplitFn
+//
//nolint:gocyclo
func NewSplitFn(
delimiters []rune,