1234567891011121314151617181920212223242526272829303132 |
- package svg
- import "encoding/xml"
- import "strings"
- type Style map[string]string
- func ParseStyle(str string) (Style, error) {
- res := make(Style)
- rules := strings.Split(";", str)
- for _, rule := range rules {
- parts := strings.SplitN(rule, ":", 2)
- key := parts[0]
- value := "true"
- if len(parts) > 1 {
- value = parts[1]
- }
- res[key] = value
- }
- return res, nil
- }
- func (s *Style) UnmarshalXMLAttr(attr xml.Attr) error {
- style, err := ParseStyle(attr.Value)
- if err != nil {
- return err
- }
- *s = style
- return nil
- }
- var _ xml.UnmarshalerAttr = &Style{}
|