From b25d106cf8c62a6d9081f2e22dd5238de352ef9d Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Mon, 24 Feb 2020 12:31:42 +0100 Subject: [PATCH] utils/strcase: remove vendored package (#115) Closes https://github.com/ooni/probe/issues/1016. --- utils/strcase/LICENSE | 22 ------ utils/strcase/README.md | 23 ------ utils/strcase/camel.go | 75 ------------------ utils/strcase/camel_test.go | 68 ----------------- utils/strcase/numbers.go | 38 ---------- utils/strcase/snake.go | 94 ----------------------- utils/strcase/snake_test.go | 147 ------------------------------------ 7 files changed, 467 deletions(-) delete mode 100644 utils/strcase/LICENSE delete mode 100644 utils/strcase/README.md delete mode 100644 utils/strcase/camel.go delete mode 100644 utils/strcase/camel_test.go delete mode 100644 utils/strcase/numbers.go delete mode 100644 utils/strcase/snake.go delete mode 100644 utils/strcase/snake_test.go diff --git a/utils/strcase/LICENSE b/utils/strcase/LICENSE deleted file mode 100644 index 3e87ff7..0000000 --- a/utils/strcase/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Ian Coleman -Copyright (c) 2018 Ma_124, - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, Subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or Substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/utils/strcase/README.md b/utils/strcase/README.md deleted file mode 100644 index 978b46d..0000000 --- a/utils/strcase/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# strcase -[![Godoc Reference](https://godoc.org/github.com/iancoleman/strcase?status.svg)](http://godoc.org/github.com/iancoleman/strcase) -[![Build Status](https://travis-ci.org/iancoleman/strcase.svg)](https://travis-ci.org/iancoleman/strcase) -[![Coverage](http://gocover.io/_badge/github.com/iancoleman/strcase?0)](http://gocover.io/github.com/iancoleman/strcase) - -strcase is a go package for converting string case to [snake case](https://en.wikipedia.org/wiki/Snake_case) or [camel case](https://en.wikipedia.org/wiki/CamelCase). - -## Example - -```go -s := "AnyKind of_string" -``` - -| Function | Result | -|-----------------------------------|----------------------| -| `ToSnake(s)` | `any_kind_of_string` | -| `ToScreamingSnake(s)` | `ANY_KIND_OF_STRING` | -| `ToKebab(s)` | `any-kind-of-string` | -| `ToScreamingKebab(s)` | `ANY-KIND-OF-STRING` | -| `ToDelimited(s, '.')` | `any.kind.of.string` | -| `ToScreamingDelimited(s, '.')` | `ANY.KIND.OF.STRING` | -| `ToCamel(s)` | `AnyKindOfString` | -| `ToLowerCamel(s)` | `anyKindOfString` | diff --git a/utils/strcase/camel.go b/utils/strcase/camel.go deleted file mode 100644 index 7c2e2b7..0000000 --- a/utils/strcase/camel.go +++ /dev/null @@ -1,75 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Ian Coleman - * Copyright (c) 2018 Ma_124, - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, Subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or Substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package strcase - -import ( - "strings" -) - -// Converts a string to CamelCase -func toCamelInitCase(s string, initCase bool) string { - s = addWordBoundariesToNumbers(s) - s = strings.Trim(s, " ") - n := "" - capNext := initCase - for _, v := range s { - if v >= 'A' && v <= 'Z' { - n += string(v) - } - if v >= '0' && v <= '9' { - n += string(v) - } - if v >= 'a' && v <= 'z' { - if capNext { - n += strings.ToUpper(string(v)) - } else { - n += string(v) - } - } - if v == '_' || v == ' ' || v == '-' { - capNext = true - } else { - capNext = false - } - } - return n -} - -// Converts a string to CamelCase -func ToCamel(s string) string { - return toCamelInitCase(s, true) -} - -// Converts a string to lowerCamelCase -func ToLowerCamel(s string) string { - if s == "" { - return s - } - if r := rune(s[0]); r >= 'A' && r <= 'Z' { - s = strings.ToLower(string(r)) + s[1:] - } - return toCamelInitCase(s, false) -} diff --git a/utils/strcase/camel_test.go b/utils/strcase/camel_test.go deleted file mode 100644 index b62b9c4..0000000 --- a/utils/strcase/camel_test.go +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Ian Coleman - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, Subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or Substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package strcase - -import ( - "testing" -) - -func TestToCamel(t *testing.T) { - cases := [][]string{ - []string{"test_case", "TestCase"}, - []string{"test", "Test"}, - []string{"TestCase", "TestCase"}, - []string{" test case ", "TestCase"}, - []string{"", ""}, - []string{"many_many_words", "ManyManyWords"}, - []string{"AnyKind of_string", "AnyKindOfString"}, - []string{"odd-fix", "OddFix"}, - []string{"numbers2And55with000", "Numbers2And55With000"}, - } - for _, i := range cases { - in := i[0] - out := i[1] - result := ToCamel(in) - if result != out { - t.Error("'" + result + "' != '" + out + "'") - } - } -} - -func TestToLowerCamel(t *testing.T) { - cases := [][]string{ - []string{"foo-bar", "fooBar"}, - []string{"TestCase", "testCase"}, - []string{"", ""}, - []string{"AnyKind of_string", "anyKindOfString"}, - } - for _, i := range cases { - in := i[0] - out := i[1] - result := ToLowerCamel(in) - if result != out { - t.Error("'" + result + "' != '" + out + "'") - } - } -} diff --git a/utils/strcase/numbers.go b/utils/strcase/numbers.go deleted file mode 100644 index fdf07cb..0000000 --- a/utils/strcase/numbers.go +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Ian Coleman - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, Subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or Substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package strcase - -import ( - "regexp" -) - -var numberSequence = regexp.MustCompile(`([a-zA-Z])(\d+)([a-zA-Z]?)`) -var numberReplacement = []byte(`$1 $2 $3`) - -func addWordBoundariesToNumbers(s string) string { - b := []byte(s) - b = numberSequence.ReplaceAll(b, numberReplacement) - return string(b) -} diff --git a/utils/strcase/snake.go b/utils/strcase/snake.go deleted file mode 100644 index 1d2f520..0000000 --- a/utils/strcase/snake.go +++ /dev/null @@ -1,94 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Ian Coleman - * Copyright (c) 2018 Ma_124, - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, Subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or Substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -// Package strcase converts strings to snake_case or CamelCase -package strcase - -import ( - "strings" -) - -// Converts a string to snake_case -func ToSnake(s string) string { - return ToDelimited(s, '_') -} - -// Converts a string to SCREAMING_SNAKE_CASE -func ToScreamingSnake(s string) string { - return ToScreamingDelimited(s, '_', true) -} - -// Converts a string to kebab-case -func ToKebab(s string) string { - return ToDelimited(s, '-') -} - -// Converts a string to SCREAMING-KEBAB-CASE -func ToScreamingKebab(s string) string { - return ToScreamingDelimited(s, '-', true) -} - -// Converts a string to delimited.snake.case (in this case `del = '.'`) -func ToDelimited(s string, del uint8) string { - return ToScreamingDelimited(s, del, false) -} - -// Converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`) -func ToScreamingDelimited(s string, del uint8, screaming bool) string { - s = addWordBoundariesToNumbers(s) - s = strings.Trim(s, " ") - n := "" - for i, v := range s { - // treat acronyms as words, eg for JSONData -> JSON is a whole word - nextCaseIsChanged := false - if i+1 < len(s) { - next := s[i+1] - if (v >= 'A' && v <= 'Z' && next >= 'a' && next <= 'z') || (v >= 'a' && v <= 'z' && next >= 'A' && next <= 'Z') { - nextCaseIsChanged = true - } - } - - if i > 0 && n[len(n)-1] != del && nextCaseIsChanged { - // add underscore if next letter case type is changed - if v >= 'A' && v <= 'Z' { - n += string(del) + string(v) - } else if v >= 'a' && v <= 'z' { - n += string(v) + string(del) - } - } else if v == ' ' || v == '_' || v == '-' { - // replace spaces/underscores with delimiters - n += string(del) - } else { - n = n + string(v) - } - } - - if screaming { - n = strings.ToUpper(n) - } else { - n = strings.ToLower(n) - } - return n -} diff --git a/utils/strcase/snake_test.go b/utils/strcase/snake_test.go deleted file mode 100644 index 9c0f9d2..0000000 --- a/utils/strcase/snake_test.go +++ /dev/null @@ -1,147 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Ian Coleman - * Copyright (c) 2018 Ma_124, - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, Subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or Substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package strcase - -import ( - "testing" -) - -func TestToSnake(t *testing.T) { - cases := [][]string{ - []string{"testCase", "test_case"}, - []string{"TestCase", "test_case"}, - []string{"Test Case", "test_case"}, - []string{" Test Case", "test_case"}, - []string{"Test Case ", "test_case"}, - []string{" Test Case ", "test_case"}, - []string{"test", "test"}, - []string{"test_case", "test_case"}, - []string{"Test", "test"}, - []string{"", ""}, - []string{"ManyManyWords", "many_many_words"}, - []string{"manyManyWords", "many_many_words"}, - []string{"AnyKind of_string", "any_kind_of_string"}, - []string{"numbers2and55with000", "numbers_2_and_55_with_000"}, - []string{"JSONData", "json_data"}, - []string{"userID", "user_id"}, - []string{"AAAbbb", "aa_abbb"}, - } - for _, i := range cases { - in := i[0] - out := i[1] - result := ToSnake(in) - if result != out { - t.Error("'" + in + "'('" + result + "' != '" + out + "')") - } - } -} - -func TestToDelimited(t *testing.T) { - cases := [][]string{ - []string{"testCase", "test@case"}, - []string{"TestCase", "test@case"}, - []string{"Test Case", "test@case"}, - []string{" Test Case", "test@case"}, - []string{"Test Case ", "test@case"}, - []string{" Test Case ", "test@case"}, - []string{"test", "test"}, - []string{"test_case", "test@case"}, - []string{"Test", "test"}, - []string{"", ""}, - []string{"ManyManyWords", "many@many@words"}, - []string{"manyManyWords", "many@many@words"}, - []string{"AnyKind of_string", "any@kind@of@string"}, - []string{"numbers2and55with000", "numbers@2@and@55@with@000"}, - []string{"JSONData", "json@data"}, - []string{"userID", "user@id"}, - []string{"AAAbbb", "aa@abbb"}, - []string{"test-case", "test@case"}, - } - for _, i := range cases { - in := i[0] - out := i[1] - result := ToDelimited(in, '@') - if result != out { - t.Error("'" + in + "' ('" + result + "' != '" + out + "')") - } - } -} - -func TestToScreamingSnake(t *testing.T) { - cases := [][]string{ - []string{"testCase", "TEST_CASE"}, - } - for _, i := range cases { - in := i[0] - out := i[1] - result := ToScreamingSnake(in) - if result != out { - t.Error("'" + result + "' != '" + out + "'") - } - } -} - -func TestToKebab(t *testing.T) { - cases := [][]string{ - []string{"testCase", "test-case"}, - } - for _, i := range cases { - in := i[0] - out := i[1] - result := ToKebab(in) - if result != out { - t.Error("'" + result + "' != '" + out + "'") - } - } -} - -func TestToScreamingKebab(t *testing.T) { - cases := [][]string{ - []string{"testCase", "TEST-CASE"}, - } - for _, i := range cases { - in := i[0] - out := i[1] - result := ToScreamingKebab(in) - if result != out { - t.Error("'" + result + "' != '" + out + "'") - } - } -} - -func TestToScreamingDelimited(t *testing.T) { - cases := [][]string{ - []string{"testCase", "TEST.CASE"}, - } - for _, i := range cases { - in := i[0] - out := i[1] - result := ToScreamingDelimited(in, '.', true) - if result != out { - t.Error("'" + result + "' != '" + out + "'") - } - } -}