mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-04 16:01:09 +00:00
Fixed flatc not stripping the path from the base filename.
This caused two bugs when used with a path: not being able to save the generated files, and preprocessor defines with / characters in them. Bug: 15676771 Tested: on Windows Change-Id: I62a3c45d22e2545fdaad83728d83a42a6efa37f9
This commit is contained in:
@@ -95,6 +95,17 @@ std::string StripExtension(const std::string &filename) {
|
|||||||
return i != std::string::npos ? filename.substr(0, i) : filename;
|
return i != std::string::npos ? filename.substr(0, i) : filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string StripPath(const std::string &filename) {
|
||||||
|
size_t i = filename.find_last_of(
|
||||||
|
#ifdef WIN32
|
||||||
|
"\\:"
|
||||||
|
#else
|
||||||
|
"/"
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
return i != std::string::npos ? filename.substr(i + 1) : filename;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
program_name = argv[0];
|
program_name = argv[0];
|
||||||
flatbuffers::Parser parser;
|
flatbuffers::Parser parser;
|
||||||
@@ -149,7 +160,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
if (!parser.Parse(contents.c_str()))
|
if (!parser.Parse(contents.c_str()))
|
||||||
Error(parser.error_.c_str());
|
Error(parser.error_.c_str());
|
||||||
|
|
||||||
std::string filebase = StripExtension(*file_it);
|
std::string filebase = StripPath(StripExtension(*file_it));
|
||||||
|
|
||||||
for (size_t i = 0; i < num_generators; ++i) {
|
for (size_t i = 0; i < num_generators; ++i) {
|
||||||
if (generator_enabled[i]) {
|
if (generator_enabled[i]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user