* Apply Namer to Dart.

- Also refactor idl_gen_dart a bit
  - to use more const and references
  - out parameters should be the last argument

* Add keyword test

* minor fixes

* fix merge

* extra 's'

* move dart keyord into dart dir

* Address comments

* Use $ for escaping keywords
* Outparameters for namespace_map

* Escape dollar in toString

* Escape dollar in toString2

* Use UpperCamelCase for types and variants

* try to fix ToString

* namer Type fixes

* Remove path prefixing in imports

* gen code

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2022-03-28 18:07:09 -04:00
committed by GitHub
parent ae4ce72651
commit a4cb1599d8
12 changed files with 600 additions and 332 deletions

View File

@@ -414,6 +414,27 @@ static std::string ToDasher(const std::string &input) {
} // namespace
// Converts foo_bar_123baz_456 to foo_bar123_baz456
static std::string SnakeToSnake2(const std::string &s) {
if (s.length() <= 1) return s;
std::string result;
result.reserve(s.size());
for (size_t i = 0; i < s.length() - 1; i++) {
if (s[i] == '_' && isdigit(s[i + 1])) {
continue; // Move the `_` until after the digits.
}
result.push_back(s[i]);
if (isdigit(s[i]) && isalpha(s[i + 1]) && islower(s[i + 1])) {
result.push_back('_');
}
}
result.push_back(s.back());
return result;
}
std::string ConvertCase(const std::string &input, Case output_case,
Case input_case) {
if (output_case == Case::kKeep) return input;
@@ -440,6 +461,7 @@ std::string ConvertCase(const std::string &input, Case output_case,
case Case::kAllUpper: return ToAll(input, CharToUpper);
case Case::kAllLower: return ToAll(input, CharToLower);
case Case::kDasher: return ToDasher(input);
case Case::kSnake2: return SnakeToSnake2(input);
default:
case Case::kUnknown: return input;
}