package bencode
import (
+ "reflect"
"strings"
)
-type tag_options string
+func getTag(st reflect.StructTag) tag {
+ return parseTag(st.Get("bencode"))
+}
-func parse_tag(tag string) (string, tag_options) {
- if idx := strings.Index(tag, ","); idx != -1 {
- return tag[:idx], tag_options(tag[idx+1:])
- }
- return tag, tag_options("")
+type tag []string
+
+func parseTag(tagStr string) tag {
+ return strings.Split(tagStr, ",")
+}
+
+func (me tag) Ignore() bool {
+ return me[0] == "-"
+}
+
+func (me tag) Key() string {
+ return me[0]
}
-func (this tag_options) contains(option_name string) bool {
- if len(this) == 0 {
+func (me tag) HasOpt(opt string) bool {
+ if len(me) < 1 {
return false
}
-
- s := string(this)
- for s != "" {
- var next string
- i := strings.Index(s, ",")
- if i != -1 {
- s, next = s[:i], s[i+1:]
- }
- if s == option_name {
+ for _, s := range me[1:] {
+ if s == opt {
return true
}
- s = next
}
return false
}
+
+func (me tag) OmitEmpty() bool {
+ return me.HasOpt("omitempty")
+}
+
+func (me tag) IgnoreUnmarshalTypeError() bool {
+ return me.HasOpt("ignore_unmarshal_type_error")
+}