2023-03-12 15:37:02 +00:00
|
|
|
package main
|
|
|
|
|
2023-03-12 15:56:26 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"unicode"
|
|
|
|
|
|
|
|
"google.golang.org/protobuf/compiler/protogen"
|
|
|
|
)
|
2023-03-12 15:37:02 +00:00
|
|
|
|
|
|
|
// CamelCaseToUnderscore converts CamelCase to camel_case
|
|
|
|
func CamelCaseToUnderscore(str string) string {
|
|
|
|
var result string
|
|
|
|
for idx, ch := range str {
|
|
|
|
// first letter will just be lowered
|
|
|
|
if idx == 0 {
|
|
|
|
result = string(unicode.ToLower(ch))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// anywhere else
|
|
|
|
if unicode.IsUpper(ch) {
|
|
|
|
result = result + "_" + string(unicode.ToLower(ch))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// nothing to see here, just accept it
|
|
|
|
result += string(ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// CamelCaseToJavascriptCase convert CamelCase to camelCase
|
|
|
|
func CamelCaseToJavascriptCase(str string) string {
|
|
|
|
var result string
|
|
|
|
for idx, ch := range str {
|
|
|
|
if idx == 0 {
|
|
|
|
result = string(unicode.ToLower(ch))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
result += string(ch)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2023-03-12 15:56:26 +00:00
|
|
|
|
|
|
|
// JavascriptCaseToCamelCase convert camelCase to CamelCase
|
|
|
|
func JavascriptCaseToCamelCase(str string) string {
|
|
|
|
var result string
|
|
|
|
for idx, ch := range str {
|
|
|
|
if idx == 0 {
|
|
|
|
result = string(unicode.ToUpper(ch))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
result += string(ch)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func getCommentFromEnumItem(comment protogen.CommentSet) string {
|
|
|
|
c := strings.Trim(string(comment.Trailing), " \n\t\r")
|
|
|
|
if c == "" {
|
|
|
|
c = "unknown error"
|
|
|
|
}
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func separator(name string) string {
|
|
|
|
name = strings.ReplaceAll(name, "\\\\", "/")
|
|
|
|
return strings.ReplaceAll(name, "\\", "/")
|
|
|
|
}
|
|
|
|
|
|
|
|
func trim(s string) string {
|
|
|
|
return strings.Trim(s, "\r\t\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
func mkdir(p string) error {
|
|
|
|
_, err := os.Stat(p)
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
err := os.MkdirAll(p, os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|