CamelCase produces the CamelCase version of the given string. It removes any non letter and non digit character. If firstUpper is true the first letter of the string is capitalized else the first letter is in lowercase. If acronym is true and a part of the string is a common acronym then it keeps
(name string, firstUpper, acronym bool)
| 103 | // then it keeps the part capitalized (firstUpper = true) |
| 104 | // (e.g. APIVersion) or lowercase (firstUpper = false) (e.g. apiVersion). |
| 105 | func CamelCase(name string, firstUpper, acronym bool) string { |
| 106 | if name == "" { |
| 107 | return "" |
| 108 | } |
| 109 | |
| 110 | // Use cache to avoid recomputing the same transformation |
| 111 | key := cacheKey{ |
| 112 | input: name, |
| 113 | firstUpper: firstUpper, |
| 114 | acronym: acronym, |
| 115 | operation: "camel", |
| 116 | } |
| 117 | return globalStringCache.getCached(key, func() string { |
| 118 | return camelCaseUncached(name, firstUpper, acronym) |
| 119 | }) |
| 120 | } |
| 121 | |
| 122 | // camelCaseUncached is the original implementation without caching. |
| 123 | func camelCaseUncached(name string, firstUpper, acronym bool) string { |