]> Sergey Matveev's repositories - btrtrc.git/blob - bencode/tags.go
dcc088e4a05f476c5090db17ed85a5d64b6921a2
[btrtrc.git] / bencode / tags.go
1 package bencode
2
3 import (
4         "strings"
5 )
6
7 type tag_options string
8
9 func parse_tag(tag string) (string, tag_options) {
10         if idx := strings.Index(tag, ","); idx != -1 {
11                 return tag[:idx], tag_options(tag[idx+1:])
12         }
13         return tag, tag_options("")
14 }
15
16 func (opts tag_options) contains(option_name string) bool {
17         if len(opts) == 0 {
18                 return false
19         }
20
21         s := string(opts)
22         for s != "" {
23                 var next string
24                 i := strings.Index(s, ",")
25                 if i != -1 {
26                         s, next = s[:i], s[i+1:]
27                 }
28                 if s == option_name {
29                         return true
30                 }
31                 s = next
32         }
33         return false
34 }