extractDollarTag extracts a dollar-quoted string tag from the beginning of s. Returns empty string if no valid dollar tag is found. Valid tags: $$ or $identifier$ where identifier contains only alphanumeric and underscore.
(s string)
| 197 | // Returns empty string if no valid dollar tag is found. |
| 198 | // Valid tags: $$ or $identifier$ where identifier contains only alphanumeric and underscore. |
| 199 | func extractDollarTag(s string) string { |
| 200 | if len(s) == 0 || s[0] != '$' { |
| 201 | return "" |
| 202 | } |
| 203 | |
| 204 | // Find the closing $ |
| 205 | for i := 1; i < len(s); i++ { |
| 206 | if s[i] == '$' { |
| 207 | tag := s[:i+1] |
| 208 | // Validate tag content (only alphanumeric and underscore allowed between $) |
| 209 | tagContent := tag[1 : len(tag)-1] |
| 210 | if isValidDollarTagContent(tagContent) { |
| 211 | return tag |
| 212 | } |
| 213 | return "" |
| 214 | } |
| 215 | // If we hit a character that's not allowed in a tag, it's not a dollar quote |
| 216 | if !isValidDollarTagChar(s[i]) { |
| 217 | return "" |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return "" |
| 222 | } |
| 223 | |
| 224 | // isValidDollarTagContent returns true if s contains only valid characters for a dollar tag. |
| 225 | func isValidDollarTagContent(s string) bool { |