summaryrefslogtreecommitdiff
path: root/vendor/github.com/go-openapi/inflect/inflect.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-openapi/inflect/inflect.go')
-rw-r--r--vendor/github.com/go-openapi/inflect/inflect.go37
1 files changed, 18 insertions, 19 deletions
diff --git a/vendor/github.com/go-openapi/inflect/inflect.go b/vendor/github.com/go-openapi/inflect/inflect.go
index 3008844ca..9d8ca6dbd 100644
--- a/vendor/github.com/go-openapi/inflect/inflect.go
+++ b/vendor/github.com/go-openapi/inflect/inflect.go
@@ -19,12 +19,11 @@ type Rule struct {
// a Ruleset is the config of pluralization rules
// you can extend the rules with the Add* methods
type Ruleset struct {
- uncountables map[string]bool
- plurals []*Rule
- singulars []*Rule
- humans []*Rule
- acronyms []*Rule
- acronymMatcher *regexp.Regexp
+ uncountables map[string]bool
+ plurals []*Rule
+ singulars []*Rule
+ humans []*Rule
+ acronyms []*Rule
}
// create a blank ruleset. Unless you are going to
@@ -282,7 +281,7 @@ func (rs *Ruleset) AddHuman(suffix, replacement string) {
rs.humans = append([]*Rule{r}, rs.humans...)
}
-// Add any inconsistant pluralizing/sinularizing rules
+// Add any inconsistent pluralizing/sinularizing rules
// to the set here.
func (rs *Ruleset) AddIrregular(singular, plural string) {
delete(rs.uncountables, singular)
@@ -387,7 +386,7 @@ func (rs *Ruleset) Titleize(word string) string {
func (rs *Ruleset) safeCaseAcronyms(word string) string {
// convert an acroymn like HTML into Html
for _, rule := range rs.acronyms {
- word = strings.Replace(word, rule.suffix, rule.replacement, -1)
+ word = strings.ReplaceAll(word, rule.suffix, rule.replacement)
}
return word
}
@@ -409,7 +408,7 @@ func (rs *Ruleset) Humanize(word string) string {
word = replaceLast(word, "_id", "") // strip foreign key kinds
// replace and strings in humans list
for _, rule := range rs.humans {
- word = strings.Replace(word, rule.suffix, rule.replacement, -1)
+ word = strings.ReplaceAll(word, rule.suffix, rule.replacement)
}
sentance := rs.seperatedWords(word, " ")
return strings.ToUpper(sentance[:1]) + sentance[1:]
@@ -430,19 +429,19 @@ func (rs *Ruleset) Tableize(word string) string {
return rs.Pluralize(rs.Underscore(rs.Typeify(word)))
}
-var notUrlSafe *regexp.Regexp = regexp.MustCompile(`[^\w\d\-_ ]`)
+var notURLSafe = regexp.MustCompile(`[^\w\d\-_ ]`)
// param safe dasherized names like "my-param"
func (rs *Ruleset) Parameterize(word string) string {
return ParameterizeJoin(word, "-")
}
-// param safe dasherized names with custom seperator
+// param safe dasherized names with custom separator
func (rs *Ruleset) ParameterizeJoin(word, sep string) string {
word = strings.ToLower(word)
word = rs.Asciify(word)
- word = notUrlSafe.ReplaceAllString(word, "")
- word = strings.Replace(word, " ", sep, -1)
+ word = notURLSafe.ReplaceAllString(word, "")
+ word = strings.ReplaceAll(word, " ", sep)
if len(sep) > 0 {
squash, err := regexp.Compile(sep + "+")
if err == nil {
@@ -453,7 +452,7 @@ func (rs *Ruleset) ParameterizeJoin(word, sep string) string {
return word
}
-var lookalikes map[string]*regexp.Regexp = map[string]*regexp.Regexp{
+var lookalikes = map[string]*regexp.Regexp{
"A": regexp.MustCompile(`À|Á|Â|Ã|Ä|Å`),
"AE": regexp.MustCompile(`Æ`),
"C": regexp.MustCompile(`Ç`),
@@ -487,7 +486,7 @@ func (rs *Ruleset) Asciify(word string) string {
return word
}
-var tablePrefix *regexp.Regexp = regexp.MustCompile(`^[^.]*\.`)
+var tablePrefix = regexp.MustCompile(`^[^.]*\.`)
// "something_like_this" -> "SomethingLikeThis"
func (rs *Ruleset) Typeify(word string) string {
@@ -642,13 +641,13 @@ func reverse(s string) string {
func isSpacerChar(c rune) bool {
switch {
- case c == rune("_"[0]):
+ case c == '_':
return true
- case c == rune(" "[0]):
+ case c == ':':
return true
- case c == rune(":"[0]):
+ case c == '-':
return true
- case c == rune("-"[0]):
+ case unicode.IsSpace(c):
return true
}
return false