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

@@ -21,32 +21,16 @@
* be maintained according to the Swift-grpc repository
*/
#include "src/compiler/ts_generator.h"
#include <map>
#include <sstream>
#include "flatbuffers/util.h"
#include "src/compiler/schema_interface.h"
#include "src/compiler/ts_generator.h"
namespace grpc_ts_generator {
grpc::string ToDasherizedCase(const grpc::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 (flatbuffers::is_alpha_upper(c)) {
if (i > 0 && p != flatbuffers::kPathSeparator) dasherized_case += "-";
dasherized_case += flatbuffers::CharToLower(c);
} else {
dasherized_case += c;
}
p = c;
}
return dasherized_case;
}
grpc::string GenerateNamespace(const std::vector<std::string> ns,
const std::string filename,
const bool include_separator) {
@@ -55,11 +39,17 @@ grpc::string GenerateNamespace(const std::vector<std::string> ns,
for (auto it = ns.begin(); it < ns.end(); it++) {
if (include_separator) path += "/";
path += include_separator ? ToDasherizedCase(*it) : *it + "_";
path += include_separator
? flatbuffers::ConvertCase(*it, flatbuffers::Case::kDasher,
flatbuffers::Case::kUpperCamel)
: *it + "_";
}
if (include_separator) path += "/";
path += include_separator ? ToDasherizedCase(filename) : filename;
path += include_separator
? flatbuffers::ConvertCase(filename, flatbuffers::Case::kDasher,
flatbuffers::Case::kUpperCamel)
: filename;
return path;
}