Add enum string parsing
This commit is contained in:
parent
cb6de17ea6
commit
d27823de53
2 changed files with 30 additions and 0 deletions
strmangle
|
@ -16,6 +16,8 @@ import (
|
|||
var (
|
||||
idAlphabet = []byte("abcdefghijklmnopqrstuvwxyz")
|
||||
smartQuoteRgx = regexp.MustCompile(`^(?i)"?[a-z_][_a-z0-9]*"?(\."?[_a-z][_a-z0-9]*"?)*(\.\*)?$`)
|
||||
|
||||
rgxEnum = regexp.MustCompile(`^enum\((,?'[^']+')+\)$`)
|
||||
)
|
||||
|
||||
var uppercaseWords = map[string]struct{}{
|
||||
|
@ -574,3 +576,16 @@ func GenerateIgnoreTags(tags []string) string {
|
|||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// ParseEnum takes a string that looks like:
|
||||
// enum('one','two') and returns the strings one, two
|
||||
func ParseEnum(s string) []string {
|
||||
if !rgxEnum.MatchString(s) {
|
||||
return nil
|
||||
}
|
||||
|
||||
s = strings.TrimPrefix(s, "enum('")
|
||||
s = strings.TrimSuffix(s, "')")
|
||||
|
||||
return strings.Split(s, "','")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue