forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
42 lines (36 loc) · 762 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package sdk
import (
"strings"
"unicode"
)
func LowerTitle(s string) string {
if s == "" {
return s
}
a := []rune(s)
a[0] = unicode.ToLower(a[0])
return string(a)
}
func Title(s string) string {
return strings.Title(s)
}
// Go string literals cannot contain backtick. If a string contains
// a backtick, replace it the following way:
//
// input:
//
// SELECT `group` FROM foo
//
// output:
//
// SELECT ` + "`" + `group` + "`" + ` FROM foo
//
// # The escaped string must be rendered inside an existing string literal
//
// A string cannot be escaped twice
func EscapeBacktick(s string) string {
return strings.Replace(s, "`", "`+\"`\"+`", -1)
}
func DoubleSlashComment(s string) string {
return "// " + strings.ReplaceAll(s, "\n", "\n// ")
}