Use ConvertCase instead of Make{Upper,Lower,Snake} implementations (#7127)

* Unified name case conversion to single method

* Convert bfbs_gen to use ConvertCase

* convert rust to use ConvertCase

* Convert idl_parser to use ConvertCase

* Convert MakeScreamingCamel to ConvertCase

* Replaced MakeCamel with ConvertCase

* minor fixes
This commit is contained in:
Derek Bailey
2022-02-23 16:08:11 -08:00
committed by GitHub
parent 0471fa807c
commit 3694b830a2
20 changed files with 617 additions and 396 deletions

View File

@@ -93,33 +93,6 @@ static bool IsLowerSnakeCase(const std::string &str) {
return true;
}
// Convert an underscore_based_identifier in to camelCase.
// Also uppercases the first character if first is true.
std::string MakeCamel(const std::string &in, bool first) {
std::string s;
for (size_t i = 0; i < in.length(); i++) {
if (!i && first)
s += CharToUpper(in[0]);
else if (in[i] == '_' && i + 1 < in.length())
s += CharToUpper(in[++i]);
else
s += in[i];
}
return s;
}
// Convert an underscore_based_identifier in to screaming snake case.
std::string MakeScreamingCamel(const std::string &in) {
std::string s;
for (size_t i = 0; i < in.length(); i++) {
if (in[i] != '_')
s += CharToUpper(in[i]);
else
s += in[i];
}
return s;
}
void DeserializeDoc(std::vector<std::string> &doc,
const Vector<Offset<String>> *documentation) {
if (documentation == nullptr) return;
@@ -2856,7 +2829,7 @@ CheckedError Parser::ParseProtoFields(StructDef *struct_def, bool isextend,
if (IsIdent("group") || oneof) {
if (!oneof) NEXT();
if (oneof && opts.proto_oneof_union) {
auto name = MakeCamel(attribute_, true) + "Union";
auto name = ConvertCase(attribute_, Case::kUpperCamel) + "Union";
ECHECK(StartEnum(name, true, &oneof_union));
type = Type(BASE_TYPE_UNION, nullptr, oneof_union);
} else {