-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstrcase.go
81 lines (69 loc) · 2.84 KB
/
strcase.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package strcase
// ToSnake returns words in snake_case (lower case words with underscores).
func ToSnake(s string) string {
return convertWithoutInitialisms(s, '_', LowerCase)
}
// ToGoSnake returns words in snake_case (lower case words with underscores).
//
// Respects Go's common initialisms (e.g. http_response -> HTTP_response).
func ToGoSnake(s string) string {
return convertWithGoInitialisms(s, '_', LowerCase)
}
// ToSNAKE returns words in SNAKE_CASE (upper case words with underscores).
// Also known as SCREAMING_SNAKE_CASE or UPPER_CASE.
func ToSNAKE(s string) string {
return convertWithoutInitialisms(s, '_', UpperCase)
}
// ToKebab returns words in kebab-case (lower case words with dashes).
// Also known as dash-case.
func ToKebab(s string) string {
return convertWithoutInitialisms(s, '-', LowerCase)
}
// ToGoKebab returns words in kebab-case (lower case words with dashes).
// Also known as dash-case.
//
// Respects Go's common initialisms (e.g. http-response -> HTTP-response).
func ToGoKebab(s string) string {
return convertWithGoInitialisms(s, '-', LowerCase)
}
// ToKEBAB returns words in KEBAB-CASE (upper case words with dashes).
// Also known as SCREAMING-KEBAB-CASE or SCREAMING-DASH-CASE.
func ToKEBAB(s string) string {
return convertWithoutInitialisms(s, '-', UpperCase)
}
// ToPascal returns words in PascalCase (capitalized words concatenated together).
// Also known as UpperPascalCase.
func ToPascal(s string) string {
return convertWithoutInitialisms(s, 0, TitleCase)
}
// ToGoPascal returns words in PascalCase (capitalized words concatenated together).
// Also known as UpperPascalCase.
//
// Respects Go's common initialisms (e.g. HttpResponse -> HTTPResponse).
func ToGoPascal(s string) string {
return convertWithGoInitialisms(s, 0, TitleCase)
}
// ToCamel returns words in camelCase (capitalized words concatenated together, with first word lower case).
// Also known as lowerCamelCase or mixedCase.
func ToCamel(s string) string {
return convertWithoutInitialisms(s, 0, CamelCase)
}
// ToGoCamel returns words in camelCase (capitalized words concatenated together, with first word lower case).
// Also known as lowerCamelCase or mixedCase.
//
// Respects Go's common initialisms, but first word remains lowercased which is
// important for code generator use cases (e.g. toJson -> toJSON, httpResponse
// -> httpResponse).
func ToGoCamel(s string) string {
return convertWithGoInitialisms(s, 0, CamelCase)
}
// ToCase returns words in given case and delimiter.
func ToCase(s string, wordCase WordCase, delimiter rune) string {
return convertWithoutInitialisms(s, delimiter, wordCase)
}
// ToGoCase returns words in given case and delimiter.
//
// Respects Go's common initialisms (e.g. httpResponse -> HTTPResponse).
func ToGoCase(s string, wordCase WordCase, delimiter rune) string {
return convertWithGoInitialisms(s, delimiter, wordCase)
}