mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-04 20:48:59 +00:00
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:
13
src/util.cpp
13
src/util.cpp
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user