MCPcopy
hub / github.com/sqlc-dev/sqlc / extractDollarTag

Function extractDollarTag

internal/sql/sqlfile/split.go:199–222  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

197// Returns empty string if no valid dollar tag is found.
198// Valid tags: $$ or $identifier$ where identifier contains only alphanumeric and underscore.
199func 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.
225func isValidDollarTagContent(s string) bool {

Callers 2

TestExtractDollarTagFunction · 0.85
SplitFunction · 0.85

Calls 2

isValidDollarTagContentFunction · 0.85
isValidDollarTagCharFunction · 0.85

Tested by 1

TestExtractDollarTagFunction · 0.68