Fix silly regexp pattern

This commit is contained in:
Patrick O'brien 2016-08-03 15:31:59 +10:00
parent afedc92224
commit 0a2507178e

View file

@ -15,15 +15,8 @@ import (
var (
idAlphabet = []byte("abcdefghijklmnopqrstuvwxyz")
uppercaseWords = []*regexp.Regexp{
regexp.MustCompile(`^id[0-9]*$`),
regexp.MustCompile(`^uid[0-9]*$`),
regexp.MustCompile(`^uuid[0-9]*$`),
regexp.MustCompile(`^guid[0-9]*$`),
regexp.MustCompile(`^ssn[0-9]*$`),
regexp.MustCompile(`^tz[0-9]*$`),
}
smartQuoteRgx = regexp.MustCompile(`^(?i)"?[a-z_][_a-z0-9]*"?(\."?[_a-z][_a-z0-9]*"?)*$`)
uppercaseWords = regexp.MustCompile(`^(?i)(id|uid|uuid|guid|ssn|tz)[0-9]*$`)
smartQuoteRgx = regexp.MustCompile(`^(?i)"?[a-z_][_a-z0-9]*"?(\."?[_a-z][_a-z0-9]*"?)*$`)
)
// IdentQuote attempts to quote simple identifiers in SQL tatements
@ -95,16 +88,8 @@ func TitleCase(name string) string {
splits := strings.Split(name, "_")
for i, split := range splits {
found := false
for _, uc := range uppercaseWords {
if uc.MatchString(split) {
splits[i] = strings.ToUpper(split)
found = true
break
}
}
if found {
if uppercaseWords.MatchString(split) {
splits[i] = strings.ToUpper(split)
continue
}
@ -126,21 +111,13 @@ func CamelCase(name string) string {
continue
}
found := false
if i > 0 {
for _, uc := range uppercaseWords {
if uc.MatchString(split) {
splits[i] = strings.ToUpper(split)
found = true
break
}
if uppercaseWords.MatchString(split) {
splits[i] = strings.ToUpper(split)
continue
}
}
if found {
continue
}
splits[i] = strings.Title(split)
}