github.com/avicd/go-utilx@v0.1.0/tokx/tags.go (about) 1 package tokx 2 3 import ( 4 "io" 5 "strings" 6 ) 7 8 func ParseTags(text string) map[string][]string { 9 rd := strings.NewReader(strings.TrimSpace(text)) 10 info := map[string][]string{} 11 buffer := &strings.Builder{} 12 var key string 13 var list []string 14 for { 15 ch, err := rd.ReadByte() 16 if err == io.EOF { 17 break 18 } 19 switch ch { 20 case ':': 21 if len(list) > 0 { 22 info[key] = list 23 list = nil 24 } 25 key = buffer.String() 26 buffer.Reset() 27 continue 28 case ',', ';': 29 list = append(list, buffer.String()) 30 buffer.Reset() 31 continue 32 } 33 buffer.WriteByte(ch) 34 } 35 if buffer.Len() > 0 { 36 list = append(list, buffer.String()) 37 } 38 if _, exist := info[key]; !exist { 39 info[key] = list 40 } 41 return info 42 }