[C++] flatc --cpp-field-case-style option to permit camel-case field names in C++ (#6669)

* flatc --cpp-field-case option to permit camel-case field names in C++

* fixed option name; cleaned up tabs

* formatting fixed to conform to CI

* resolved comments

* fixed white space indentation

* per PR comments

* rename snake case option to unchanged for clarity, per PR comments

* cleanup of unchanged case option in C++ codegen, per PR 6669 comments

* incorporated PR feedback from vglavnyy

* cleaned up to pass Travis CI / clang format

* bumped PR to retry transient CI failure

* bumped PR to retry transient CI failure

* bump PR

* assert union type field name length > suffix, per PR 6669 comments
This commit is contained in:
Huw Rogers
2021-06-08 19:23:05 +01:00
committed by GitHub
parent 021177af0d
commit f069396d1b
3 changed files with 45 additions and 0 deletions

View File

@@ -121,6 +121,11 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
" (see the --cpp-str-flex-ctor option to change this behavior).\n"
" --cpp-str-flex-ctor Don't construct custom string types by passing std::string\n"
" from Flatbuffers, but (char* + length).\n"
" --cpp-field-case-style STYLE Generate C++ fields using selected case style.\n"
" Supported STYLE values:\n"
" * 'unchanged' - leave unchanged (default);\n"
" * 'upper' - schema snake_case emits UpperCamel;\n"
" * 'lower' - schema snake_case emits lowerCamel.\n"
" --cpp-std CPP_STD Generate a C++ code using features of selected C++ standard.\n"
" Supported CPP_STD values:\n"
" * 'c++0x' - generate code compatible with old compilers;\n"
@@ -275,6 +280,17 @@ int FlatCompiler::Compile(int argc, const char **argv) {
opts.cpp_object_api_string_flexible_constructor = true;
} else if (arg == "--no-cpp-direct-copy") {
opts.cpp_direct_copy = false;
} else if (arg == "--cpp-field-case-style") {
if (++argi >= argc) Error("missing case style following: " + arg, true);
if (!strcmp(argv[argi], "unchanged"))
opts.cpp_object_api_field_case_style =
IDLOptions::CaseStyle_Unchanged;
else if (!strcmp(argv[argi], "upper"))
opts.cpp_object_api_field_case_style = IDLOptions::CaseStyle_Upper;
else if (!strcmp(argv[argi], "lower"))
opts.cpp_object_api_field_case_style = IDLOptions::CaseStyle_Lower;
else
Error("unknown case style: " + std::string(argv[argi]), true);
} else if (arg == "--gen-nullable") {
opts.gen_nullable = true;
} else if (arg == "--java-checkerframework") {