Non-alpha-numeric characters are filtered out of include guards
Since part of it is based on the filename, which may contain characters that are not legal identifiers. Change-Id: I62b8fe228a434a2040fd4ce47d220fc4d3398b41 Tested: on Linux.
This commit is contained in:
parent
f5e343efba
commit
f57d012a21
|
@ -459,7 +459,7 @@ void CloseNestedNameSpaces(Namespace *ns, std::string *code_ptr) {
|
||||||
// Iterate through all definitions we haven't generate code for (enums, structs,
|
// Iterate through all definitions we haven't generate code for (enums, structs,
|
||||||
// and tables) and output them to a single file.
|
// and tables) and output them to a single file.
|
||||||
std::string GenerateCPP(const Parser &parser,
|
std::string GenerateCPP(const Parser &parser,
|
||||||
const std::string &include_guard_ident,
|
const std::string &file_name,
|
||||||
const GeneratorOptions &opts) {
|
const GeneratorOptions &opts) {
|
||||||
using namespace cpp;
|
using namespace cpp;
|
||||||
|
|
||||||
|
@ -522,8 +522,16 @@ std::string GenerateCPP(const Parser &parser,
|
||||||
" do not modify\n\n";
|
" do not modify\n\n";
|
||||||
|
|
||||||
// Generate include guard.
|
// Generate include guard.
|
||||||
|
std::string include_guard_ident = file_name;
|
||||||
|
// Remove any non-alpha-numeric characters that may appear in a filename.
|
||||||
|
include_guard_ident.erase(
|
||||||
|
std::remove_if(include_guard_ident.begin(),
|
||||||
|
include_guard_ident.end(),
|
||||||
|
[](char c) { return !isalnum(c); }),
|
||||||
|
include_guard_ident.end());
|
||||||
std::string include_guard = "FLATBUFFERS_GENERATED_" + include_guard_ident;
|
std::string include_guard = "FLATBUFFERS_GENERATED_" + include_guard_ident;
|
||||||
include_guard += "_";
|
include_guard += "_";
|
||||||
|
// For further uniqueness, also add the namespace.
|
||||||
auto name_space = parser.namespaces_.back();
|
auto name_space = parser.namespaces_.back();
|
||||||
for (auto it = name_space->components.begin();
|
for (auto it = name_space->components.begin();
|
||||||
it != name_space->components.end(); ++it) {
|
it != name_space->components.end(); ++it) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
#ifndef FLATBUFFERS_GENERATED_MONSTER_TEST_MYGAME_EXAMPLE_H_
|
#ifndef FLATBUFFERS_GENERATED_MONSTERTEST_MYGAME_EXAMPLE_H_
|
||||||
#define FLATBUFFERS_GENERATED_MONSTER_TEST_MYGAME_EXAMPLE_H_
|
#define FLATBUFFERS_GENERATED_MONSTERTEST_MYGAME_EXAMPLE_H_
|
||||||
|
|
||||||
#include "flatbuffers/flatbuffers.h"
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
@ -207,4 +207,4 @@ inline bool MonsterBufferHasIdentifier(const void *buf) { return flatbuffers::Bu
|
||||||
} // namespace Example
|
} // namespace Example
|
||||||
} // namespace MyGame
|
} // namespace MyGame
|
||||||
|
|
||||||
#endif // FLATBUFFERS_GENERATED_MONSTER_TEST_MYGAME_EXAMPLE_H_
|
#endif // FLATBUFFERS_GENERATED_MONSTERTEST_MYGAME_EXAMPLE_H_
|
||||||
|
|
Loading…
Reference in New Issue