From 9e6d33689f7cf682f80a1147ceb7afd9bdcaf2e0 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 3 Dec 2017 18:17:36 -0800 Subject: [PATCH] Trim lines when reading from .cquery file. Otherwise there may be newlines and the like. --- src/project.cc | 13 ++++++++++--- src/utils.cc | 4 ++-- src/utils.h | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/project.cc b/src/project.cc index 2bf8c4f7..00518ddf 100644 --- a/src/project.cc +++ b/src/project.cc @@ -52,10 +52,15 @@ static std::vector kBlacklistMulti = { // Blacklisted flags which are always removed from the command line. static std::vector kBlacklist = { - "-c", "-MP", "-MD", "-MMD", "--fcolor-diagnostics", + "-c", + "-MP", + "-MD", + "-MMD", + "--fcolor-diagnostics", // This strips path-like args but is a bit hacky. - "/", "..", + "/", + "..", }; // Arguments which are followed by a potentially relative path. We need to make @@ -207,7 +212,9 @@ std::vector LoadFromDirectoryListing(ProjectConfig* config) { std::vector args; std::cerr << "Using arguments: "; - for (const std::string& line : ReadLines(config->project_dir + "/.cquery")) { + for (std::string line : + ReadLinesWithEnding(config->project_dir + "/.cquery")) { + Trim(line); if (line.empty() || StartsWith(line, "#")) continue; if (!args.empty()) diff --git a/src/utils.cc b/src/utils.cc index 0c8d2d2e..c568d8a0 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -245,7 +245,7 @@ optional ReadContent(const std::string& filename) { } } -std::vector ReadLines(std::string filename) { +std::vector ReadLinesWithEnding(std::string filename) { std::vector result; std::ifstream input(filename); @@ -296,7 +296,7 @@ std::unordered_map ParseTestExpectation( std::string active_output_filename; std::string active_output_contents; - for (std::string line_with_ending : ReadLines(filename)) { + for (std::string line_with_ending : ReadLinesWithEnding(filename)) { if (StartsWith(line_with_ending, "*/")) break; diff --git a/src/utils.h b/src/utils.h index a15575d9..0a4a8198 100644 --- a/src/utils.h +++ b/src/utils.h @@ -74,7 +74,7 @@ void EnsureEndsInSlash(std::string& path); std::string EscapeFileName(std::string path); optional ReadContent(const std::string& filename); -std::vector ReadLines(std::string filename); +std::vector ReadLinesWithEnding(std::string filename); std::vector ToLines(const std::string& content, bool trim_whitespace);