ToCamelCase() when kLowerCamel now converts first char to lower. (#7838)

ToCamelCase(input, true) converts first char to upper case, but
ToCamelCase(input, false) keeps the case of the first char. We are
changing its behavior to force a lower case.

Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
Paulo Pinheiro
2023-03-15 02:09:24 +01:00
committed by GitHub
parent d4d355d883
commit d3d7e2ef99
4 changed files with 16 additions and 9 deletions

View File

@@ -86,11 +86,18 @@ static bool LoadFileRaw(const char *name, bool binary, std::string *buf) {
LoadFileFunction g_load_file_function = LoadFileRaw;
FileExistsFunction g_file_exists_function = FileExistsRaw;
static std::string ToCamelCase(const std::string &input, bool first) {
static std::string ToCamelCase(const std::string &input, bool is_upper) {
std::string s;
for (size_t i = 0; i < input.length(); i++) {
if (!i && first)
s += CharToUpper(input[i]);
if (!i && input[i] == '_') {
s += input[i];
// we ignore leading underscore but make following
// alphabet char upper.
if (i + 1 < input.length() && is_alpha(input[i + 1]))
s += CharToUpper(input[++i]);
}
else if (!i)
s += is_upper ? CharToUpper(input[i]) : CharToLower(input[i]);
else if (input[i] == '_' && i + 1 < input.length())
s += CharToUpper(input[++i]);
else