Skip to content

Commit fe8fc41

Browse files
committed
created additional func to define all formatting options from str
1 parent a54d9f7 commit fe8fc41

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

formatter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,14 @@ func getItemAsStr(item *any, itemFormat *string) string {
575575
} else {
576576
return convertSliceToStrWithTypeDiscover(item, &separator)
577577
}
578+
case 'c', 'C':
579+
// c means code for apply stringFormatter.SetStyle()
580+
/* code formatting could be set as follows:
581+
* 1. {0:c:Camel} - stands for camel case with Capital letter at begin
582+
* 2. {0:c:camel} - stands for camel case with Capital letter at begin
583+
* 3. {0:c:Kebab}, {0:c:kebab}, {0:c:KEBAB} - 3 ways of Kebab formatting: first lower case with start Capital letter
584+
* 4. {0:c:Snake}, {0:c:snake}, {0:c:SNAKE} - 3 ways of Snake formatting: first lower case with start Capital letter
585+
*/
578586
default:
579587
base = 10
580588
}

stringstyle_formatter.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type styleInc struct {
2525
Style FormattingStyle
2626
}
2727

28-
var styles = map[rune]FormattingStyle{
28+
var styleSigns = map[rune]FormattingStyle{
2929
'_': Snake,
3030
'-': Kebab,
3131
}
@@ -115,6 +115,36 @@ func SetStyle(text *string, style FormattingStyle, firstSymbol CaseSetting, text
115115
return ""
116116
}
117117

118+
func GetFormattingStyleOptions(style string) (FormattingStyle, CaseSetting, CaseSetting) {
119+
styleLower := strings.ToLower(style)
120+
var formattingStyle FormattingStyle
121+
firstSymbolCase := ToLower
122+
textCase := NoChanges
123+
switch styleLower {
124+
case string(Camel):
125+
formattingStyle = Camel
126+
break
127+
case string(Snake):
128+
formattingStyle = Snake
129+
break
130+
case string(Kebab):
131+
formattingStyle = Kebab
132+
break
133+
}
134+
135+
runes := []rune(style)
136+
firstSymbolIsUpper := isSymbolIsUpper(runes[0])
137+
if firstSymbolIsUpper {
138+
firstSymbolCase = ToUpper
139+
}
140+
141+
if formattingStyle != Camel {
142+
143+
}
144+
145+
return formattingStyle, firstSymbolCase, textCase
146+
}
147+
118148
// defineFormattingStyle
119149
/* This function defines what formatting style is using in text
120150
* If there are no transitions between symbols then here we have NoFormatting style
@@ -130,11 +160,11 @@ func defineFormattingStyle(text *string) []styleInc {
130160
runes := []rune(*text)
131161
for pos, char := range runes {
132162
// define style and add stats
133-
style, ok := styles[char]
163+
style, ok := styleSigns[char]
134164
if !ok {
135165
// 1. Probably current symbol is not a sign and we should continue
136166
if pos > 0 && pos < len(runes)-1 {
137-
charIsUpperCase := isUpper(char)
167+
charIsUpperCase := isSymbolIsUpper(char)
138168
prevChar := runes[pos-1]
139169
prevCharIsUpperCase := unicode.IsUpper(prevChar)
140170
if charIsUpperCase && !prevCharIsUpperCase {
@@ -149,6 +179,16 @@ func defineFormattingStyle(text *string) []styleInc {
149179
return inclusions
150180
}
151181

152-
func isUpper(symbol rune) bool {
182+
func isSymbolIsUpper(symbol rune) bool {
153183
return unicode.IsUpper(symbol) && unicode.IsLetter(symbol)
154184
}
185+
186+
func isStringIsUpper(str []rune) bool {
187+
isUpper := true
188+
for _, r := range str {
189+
if unicode.IsLetter(r) {
190+
isUpper = isUpper && unicode.IsUpper(r)
191+
}
192+
}
193+
return isUpper
194+
}

0 commit comments

Comments
 (0)