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