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

Function CleanedComments

internal/source/code.go:138–171  ·  view source on GitHub ↗
(rawSQL string, cs CommentSyntax)

Source from the content-addressed store, hash-verified

136}
137
138func CleanedComments(rawSQL string, cs CommentSyntax) ([]string, error) {
139 s := bufio.NewScanner(strings.NewReader(strings.TrimSpace(rawSQL)))
140 var comments []string
141 for s.Scan() {
142 line := s.Text()
143 var prefix string
144 if strings.HasPrefix(line, "--") {
145 if !cs.Dash {
146 continue
147 }
148 prefix = "--"
149 }
150 if strings.HasPrefix(line, "/*") {
151 if !cs.SlashStar {
152 continue
153 }
154 prefix = "/*"
155 }
156 if strings.HasPrefix(line, "#") {
157 if !cs.Hash {
158 continue
159 }
160 prefix = "#"
161 }
162 if prefix == "" {
163 continue
164 }
165
166 rest := line[len(prefix):]
167 rest = strings.TrimSuffix(rest, "*/")
168 comments = append(comments, rest)
169 }
170 return comments, s.Err()
171}

Callers 1

parseQueryMethod · 0.92

Calls 2

ScanMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected