Lowercase the first upper characters in a string for case of abbreviation. This assumes UTF-8, so we have to be careful with unicode, don't treat it as a byte array.
(str string)
| 201 | // Lowercase the first upper characters in a string for case of abbreviation. |
| 202 | // This assumes UTF-8, so we have to be careful with unicode, don't treat it as a byte array. |
| 203 | func LowercaseFirstCharacters(str string) string { |
| 204 | if str == "" { |
| 205 | return "" |
| 206 | } |
| 207 | |
| 208 | runes := []rune(str) |
| 209 | |
| 210 | for i := range runes { |
| 211 | next := i + 1 |
| 212 | if i != 0 && next < len(runes) && unicode.IsLower(runes[next]) { |
| 213 | break |
| 214 | } |
| 215 | |
| 216 | runes[i] = unicode.ToLower(runes[i]) |
| 217 | } |
| 218 | |
| 219 | return string(runes) |
| 220 | } |
| 221 | |
| 222 | // ToCamelCase will convert query-arg style strings to CamelCase. We will |
| 223 | // use `., -, +, :, ;, _, ~, ' ', (, ), {, }, [, ]` as valid delimiters for words. |
no outgoing calls