tags: simplify parseTag, no need for len checking

This commit is contained in:
Fatih Arslan 2014-08-08 13:45:04 +03:00
parent 74f7a1f303
commit f59cd82529

16
tags.go
View File

@ -20,21 +20,13 @@ func (t tagOptions) Has(opt string) bool {
// which comes after a name. A tag is in the form of: "name,option1,option2". // which comes after a name. A tag is in the form of: "name,option1,option2".
// The name can be neglectected. // The name can be neglectected.
func parseTag(tag string) (string, tagOptions) { func parseTag(tag string) (string, tagOptions) {
res := strings.Split(tag, ",")
// tag = ""
if len(res) == 0 {
return tag, res
}
// tag = "name"
if len(res) == 1 {
return tag, res[1:]
}
// tag is one of followings: // tag is one of followings:
// ""
// "name"
// "name,opt" // "name,opt"
// "name,opt,opt2" // "name,opt,opt2"
// ",opt" // ",opt"
res := strings.Split(tag, ",")
return res[0], res[1:] return res[0], res[1:]
} }