MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / ToCamelCase

Function ToCamelCase

pkg/codegen/utils.go:226–248  ·  view source on GitHub ↗

ToCamelCase will convert query-arg style strings to CamelCase. We will use `., -, +, :, ;, _, ~, ' ', (, ), {, }, [, ]` as valid delimiters for words. So, "word.word-word+word:word;word_word~word word(word)word{word}[word]" would be converted to WordWordWordWordWordWordWordWordWordWordWordWordWord

(str string)

Source from the content-addressed store, hash-verified

224// So, "word.word-word+word:word;word_word~word word(word)word{word}[word]"
225// would be converted to WordWordWordWordWordWordWordWordWordWordWordWordWord
226func ToCamelCase(str string) string {
227 s := strings.Trim(str, " ")
228
229 var n strings.Builder
230 capNext := true
231 for _, v := range s {
232 if unicode.IsUpper(v) {
233 n.WriteString(string(v))
234 }
235 if unicode.IsDigit(v) {
236 n.WriteString(string(v))
237 }
238 if unicode.IsLower(v) {
239 if capNext {
240 n.WriteString(strings.ToUpper(string(v)))
241 } else {
242 n.WriteString(string(v))
243 }
244 }
245 _, capNext = separatorSet[v]
246 }
247 return n.String()
248}
249
250// ToCamelCaseWithDigits function will convert query-arg style strings to CamelCase. We will
251// use `., -, +, :, ;, _, ~, ' ', (, ), {, }, [, ]` as valid delimiters for words.

Callers 3

detectPackageNameFunction · 0.92
TestToCamelCaseFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

TestToCamelCaseFunction · 0.68