-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
38 lines (32 loc) · 774 Bytes
/
utils.go
File metadata and controls
38 lines (32 loc) · 774 Bytes
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
package mongoent
import (
"regexp"
"strings"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
func ConvertToCamelCase(s string) string {
words := strings.Split(s, "_")
for i := 1; i < len(words); i++ {
words[i] = cases.Title(language.Und).String(words[i])
}
return strings.Join(words, "")
}
func ToSnakeCase(input string) string {
// 匹配大写字母前面的位置
regex := regexp.MustCompile(`([A-Z])`)
snakeCase := regex.ReplaceAllString(input, "_$1")
snakeCase = strings.ToLower(snakeCase)
snakeCase = strings.TrimPrefix(snakeCase, "_")
return snakeCase
}
func OpSplit(s string) string {
split := strings.Split(s, "$")
if len(split) < 2 {
return ""
}
if split[1] == "regex" {
return "Regex"
}
return strings.ToUpper(split[1])
}