aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/golangci/misspell/case.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-07-04 11:12:55 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-07-04 15:05:30 +0200
commitc7d7f10bdff703e4a3c0414e8a33d4e45c91eb35 (patch)
tree0dff0ee1f98dbfa3ad8776112053a450d176592b /vendor/github.com/golangci/misspell/case.go
parent9573094ce235bd9afe88f5da27a47dd6bcc1e13b (diff)
go.mod: vendor golangci-lint
Diffstat (limited to 'vendor/github.com/golangci/misspell/case.go')
-rw-r--r--vendor/github.com/golangci/misspell/case.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/github.com/golangci/misspell/case.go b/vendor/github.com/golangci/misspell/case.go
new file mode 100644
index 000000000..2ea3850df
--- /dev/null
+++ b/vendor/github.com/golangci/misspell/case.go
@@ -0,0 +1,59 @@
+package misspell
+
+import (
+ "strings"
+)
+
+// WordCase is an enum of various word casing styles
+type WordCase int
+
+// Various WordCase types.. likely to be not correct
+const (
+ CaseUnknown WordCase = iota
+ CaseLower
+ CaseUpper
+ CaseTitle
+)
+
+// CaseStyle returns what case style a word is in
+func CaseStyle(word string) WordCase {
+ upperCount := 0
+ lowerCount := 0
+
+ // this iterates over RUNES not BYTES
+ for i := 0; i < len(word); i++ {
+ ch := word[i]
+ switch {
+ case ch >= 'a' && ch <= 'z':
+ lowerCount++
+ case ch >= 'A' && ch <= 'Z':
+ upperCount++
+ }
+ }
+
+ switch {
+ case upperCount != 0 && lowerCount == 0:
+ return CaseUpper
+ case upperCount == 0 && lowerCount != 0:
+ return CaseLower
+ case upperCount == 1 && lowerCount > 0 && word[0] >= 'A' && word[0] <= 'Z':
+ return CaseTitle
+ }
+ return CaseUnknown
+}
+
+// CaseVariations returns
+// If AllUpper or First-Letter-Only is upcased: add the all upper case version
+// If AllLower, add the original, the title and upcase forms
+// If Mixed, return the original, and the all upcase form
+//
+func CaseVariations(word string, style WordCase) []string {
+ switch style {
+ case CaseLower:
+ return []string{word, strings.ToUpper(word[0:1]) + word[1:], strings.ToUpper(word)}
+ case CaseUpper:
+ return []string{strings.ToUpper(word)}
+ default:
+ return []string{word, strings.ToUpper(word)}
+ }
+}