Update idl_gen_fbs.cpp

This commit is contained in:
Raman 2016-07-04 21:34:42 +02:00 committed by GitHub
parent 68a83eddd4
commit 7d84a4914f
1 changed files with 15 additions and 11 deletions

View File

@ -52,15 +52,18 @@ static void GenNameSpace(const Namespace &name_space, std::string *_schema,
} }
// Generate a flatbuffer schema from the Parser's internal representation. // Generate a flatbuffer schema from the Parser's internal representation.
std::string GenerateFBS(const Parser &parser, const std::string &file_name) { std::string GenerateFBS(const Parser &parser, const std::string &file_name, const bool &escape_proto_identifiers) {
// Proto namespaces may clash with table names, so we have to prefix all: // Proto namespaces may clash with table names, so we have to prefix all:
for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end();
++it) { if (!escape_proto_identifiers) {
for (auto comp = (*it)->components.begin(); comp != (*it)->components.end(); for (auto it = parser.namespaces_.begin(); it != parser.namespaces_.end();
++comp) { ++it) {
(*comp) = "_" + (*comp); for (auto comp = (*it)->components.begin(); comp != (*it)->components.end();
} ++comp) {
} (*comp) = "_" + (*comp);
}
}
}
std::string schema; std::string schema;
schema += "// Generated from " + file_name + ".proto\n\n"; schema += "// Generated from " + file_name + ".proto\n\n";
@ -119,9 +122,10 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name) {
bool GenerateFBS(const Parser &parser, bool GenerateFBS(const Parser &parser,
const std::string &path, const std::string &path,
const std::string &file_name) { const std::string &file_name,
const bool &escape_proto_identifiers) {
return SaveFile((path + file_name + ".fbs").c_str(), return SaveFile((path + file_name + ".fbs").c_str(),
GenerateFBS(parser, file_name), false); GenerateFBS(parser, file_name, escape_proto_identifiers), false);
} }
} // namespace flatbuffers } // namespace flatbuffers