utils.go 762 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package sdk
  2. import (
  3. "strings"
  4. "unicode"
  5. )
  6. func LowerTitle(s string) string {
  7. if s == "" {
  8. return s
  9. }
  10. a := []rune(s)
  11. a[0] = unicode.ToLower(a[0])
  12. return string(a)
  13. }
  14. func Title(s string) string {
  15. return strings.Title(s)
  16. }
  17. // Go string literals cannot contain backtick. If a string contains
  18. // a backtick, replace it the following way:
  19. //
  20. // input:
  21. //
  22. // SELECT `group` FROM foo
  23. //
  24. // output:
  25. //
  26. // SELECT ` + "`" + `group` + "`" + ` FROM foo
  27. //
  28. // # The escaped string must be rendered inside an existing string literal
  29. //
  30. // A string cannot be escaped twice
  31. func EscapeBacktick(s string) string {
  32. return strings.Replace(s, "`", "`+\"`\"+`", -1)
  33. }
  34. func DoubleSlashComment(s string) string {
  35. return "// " + strings.ReplaceAll(s, "\n", "\n// ")
  36. }