From f0b3c75779ead7bad94955559865675087eb4f61 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 2 Jul 2014 10:32:32 -0700 Subject: [PATCH] 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 --- src/flatc.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/flatc.cpp b/src/flatc.cpp index e99b1d489..ddd275b9d 100755 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -95,6 +95,17 @@ std::string StripExtension(const std::string &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[]) { program_name = argv[0]; flatbuffers::Parser parser; @@ -149,7 +160,7 @@ int main(int argc, const char *argv[]) { if (!parser.Parse(contents.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) { if (generator_enabled[i]) {