File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ func ToSnakeCase(input string) string {
41
41
return SplitJoin (input , CaseStrategyNever , '_' , false )
42
42
}
43
43
44
+ // ToHeaderField transforms a string in any form to An-HTTP-Header.
45
+ func ToHeaderField (input string ) string {
46
+ return SplitJoin (input , CaseStrategyTitle , '-' , true )
47
+ }
48
+
44
49
func SplitJoin (input string , caseStrategy CaseStrategy , separator rune , initialism bool ) string {
45
50
firstUpper := int (caseStrategy )
46
51
b := allocateBuilder (input , separator )
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ func Test_splitJoin(t *testing.T) {
106
106
pascal string
107
107
pascalGo string
108
108
snake string
109
+ header string
109
110
}{
110
111
{
111
112
// everything empty
@@ -115,30 +116,35 @@ func Test_splitJoin(t *testing.T) {
115
116
pascal : "A" ,
116
117
camel : "a" ,
117
118
snake : "a" ,
119
+ header : "A" ,
118
120
},
119
121
{
120
122
input : "A" ,
121
123
pascal : "A" ,
122
124
camel : "a" ,
123
125
snake : "a" ,
126
+ header : "A" ,
124
127
},
125
128
{
126
129
input : "a_a" ,
127
130
pascal : "AA" ,
128
131
camel : "aA" ,
129
132
snake : "a_a" ,
133
+ header : "A-A" ,
130
134
},
131
135
{
132
136
input : "__a___a_" ,
133
137
pascal : "AA" ,
134
138
camel : "aA" ,
135
139
snake : "a_a" ,
140
+ header : "A-A" ,
136
141
},
137
142
{
138
143
input : "aa_bbb" ,
139
144
pascal : "AaBbb" ,
140
145
camel : "aaBbb" ,
141
146
snake : "aa_bbb" ,
147
+ header : "Aa-Bbb" ,
142
148
},
143
149
{
144
150
input : "aa_id" ,
@@ -147,18 +153,21 @@ func Test_splitJoin(t *testing.T) {
147
153
camel : "aaId" ,
148
154
camelGo : "aaID" ,
149
155
snake : "aa_id" ,
156
+ header : "Aa-ID" ,
150
157
},
151
158
{
152
159
input : "fooBar" ,
153
160
pascal : "FooBar" ,
154
161
camel : "fooBar" ,
155
162
snake : "foo_bar" ,
163
+ header : "Foo-Bar" ,
156
164
},
157
165
{
158
166
input : "FooBAR" ,
159
167
pascal : "FooBar" ,
160
168
camel : "fooBar" ,
161
169
snake : "foo_bar" ,
170
+ header : "Foo-Bar" ,
162
171
},
163
172
{
164
173
input : "fooUrl" ,
@@ -167,6 +176,7 @@ func Test_splitJoin(t *testing.T) {
167
176
camel : "fooUrl" ,
168
177
camelGo : "fooURL" ,
169
178
snake : "foo_url" ,
179
+ header : "Foo-URL" ,
170
180
},
171
181
{
172
182
input : "fooURL" ,
@@ -175,13 +185,15 @@ func Test_splitJoin(t *testing.T) {
175
185
camel : "fooUrl" ,
176
186
camelGo : "fooURL" ,
177
187
snake : "foo_url" ,
188
+ header : "Foo-URL" ,
178
189
},
179
190
{
180
191
input : "url10" ,
181
192
pascal : "Url10" ,
182
193
pascalGo : "URL10" ,
183
194
camel : "url10" ,
184
195
snake : "url_10" ,
196
+ header : "URL-10" ,
185
197
},
186
198
{
187
199
input : "url_id" ,
@@ -190,6 +202,7 @@ func Test_splitJoin(t *testing.T) {
190
202
camel : "urlId" ,
191
203
camelGo : "urlID" ,
192
204
snake : "url_id" ,
205
+ header : "URL-ID" ,
193
206
},
194
207
}
195
208
for _ , tt := range tests {
You can’t perform that action at this time.
0 commit comments