@@ -6,13 +6,20 @@ import (
66)
77
88type FormattingStyle string
9+ type CaseSetting int
910
1011const (
1112 Camel FormattingStyle = "camel"
1213 Snake FormattingStyle = "snake"
1314 Kebab FormattingStyle = "kebab"
1415)
1516
17+ const (
18+ ToUpper CaseSetting = 1
19+ ToLower CaseSetting = 2
20+ NoChanges CaseSetting = 3
21+ )
22+
1623type styleInc struct {
1724 Index int
1825 Style FormattingStyle
@@ -23,7 +30,22 @@ var styles = map[rune]FormattingStyle{
2330 '-' : Kebab ,
2431}
2532
26- func SetStyle (text * string , style FormattingStyle ) string {
33+ // SetStyle is a function that converts text with code to defined code style.
34+ /* Set text like a code style to on from FormattingStyle (Camel, Snake, or Kebab)
35+ * conversion of abbreviations like JSON, USB, and so on is going like a regular text
36+ * for current version, therefore they these abbreviations could be in a different
37+ * case after conversion.
38+ * Case settings apply in the following order : 1 - textCase, 2 - firstSymbol.
39+ * If you are not applying textCase to text converting from Camel to Snake or Kebab
40+ * result is lower case styled text. textCase does not apply to Camel style.
41+ * Parameters:
42+ * - text - pointer to text
43+ * - style - new code style
44+ * - firstSymbol - case settings for first symbol
45+ * - textCase - case settings for whole text except first symbol
46+ * Returns : new string with formatted line
47+ */
48+ func SetStyle (text * string , style FormattingStyle , firstSymbol CaseSetting , textCase CaseSetting ) string {
2749 if text == nil {
2850 return ""
2951 }
@@ -65,10 +87,32 @@ func SetStyle(text *string, style FormattingStyle) string {
6587 }
6688 }
6789 sb .WriteString ((* text )[startIndex :])
90+ result := strings.Builder {}
6891 if style != Camel {
69- return strings .ToLower (sb .String ())
92+ switch textCase {
93+ case ToUpper :
94+ result .WriteString (strings .ToUpper (sb .String ()[1 :]))
95+ break
96+ case ToLower :
97+ result .WriteString (strings .ToLower (sb .String ()[1 :]))
98+ break
99+ case NoChanges :
100+ result .WriteString (sb .String ()[1 :])
101+ break
102+ }
103+ } else {
104+ result .WriteString (sb .String ()[1 :])
105+ }
106+
107+ switch firstSymbol {
108+ case ToUpper :
109+ return strings .ToUpper (sb .String ()[:1 ]) + result .String ()
110+ case ToLower :
111+ return strings .ToLower (sb .String ()[:1 ]) + result .String ()
112+ case NoChanges :
113+ return sb .String ()[:1 ] + result .String ()
70114 }
71- return sb . String ()
115+ return ""
72116}
73117
74118// defineFormattingStyle
0 commit comments