parseAttributes parses a string of XML attributes into a map.
(attrsStr string)
| 76 | |
| 77 | // parseAttributes parses a string of XML attributes into a map. |
| 78 | func parseAttributes(attrsStr string) map[string]string { |
| 79 | attrs := make(map[string]string) |
| 80 | if attrsStr == "" { |
| 81 | return attrs |
| 82 | } |
| 83 | |
| 84 | // Match attribute="value" or attribute='value' patterns |
| 85 | attrRegex := regexp.MustCompile(`(\S+)=["']([^"']*)["']`) |
| 86 | matches := attrRegex.FindAllStringSubmatch(attrsStr, -1) |
| 87 | |
| 88 | for _, match := range matches { |
| 89 | if len(match) >= 3 { |
| 90 | key := strings.TrimSpace(match[1]) |
| 91 | value := match[2] |
| 92 | attrs[key] = value |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return attrs |
| 97 | } |
no test coverage detected