Replaced ToDasherCase with ConvertCase (#7131)

This commit is contained in:
Derek Bailey
2022-02-23 20:31:40 -08:00
committed by GitHub
parent 3694b830a2
commit c9571d9897
9 changed files with 494 additions and 47 deletions

View File

@@ -91,7 +91,8 @@ std::string BaseGenerator::NamespaceDir(const Parser &parser,
std::string namespace_dir = path; // Either empty or ends in separator.
auto &namespaces = ns.components;
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
namespace_dir += !dasherize ? *it : ToDasherizedCase(*it);
namespace_dir +=
!dasherize ? *it : ConvertCase(*it, Case::kDasher, Case::kUpperCamel);
namespace_dir += kPathSeparator;
EnsureDirExists(namespace_dir);
}
@@ -103,22 +104,6 @@ std::string BaseGenerator::NamespaceDir(const Namespace &ns,
return BaseGenerator::NamespaceDir(parser_, path_, ns, dasherize);
}
std::string BaseGenerator::ToDasherizedCase(const std::string pascal_case) {
std::string dasherized_case;
char p = 0;
for (size_t i = 0; i < pascal_case.length(); i++) {
char const &c = pascal_case[i];
if (is_alpha_upper(c)) {
if (i > 0 && p != kPathSeparator) dasherized_case += "-";
dasherized_case += CharToLower(c);
} else {
dasherized_case += c;
}
p = c;
}
return dasherized_case;
}
std::string BaseGenerator::FullNamespace(const char *separator,
const Namespace &ns) {
std::string namespace_name;