Trim lines when reading from .cquery file.

Otherwise there may be newlines and the like.
This commit is contained in:
Jacob Dufault 2017-12-03 18:17:36 -08:00
parent 95203bffd4
commit 9e6d33689f
3 changed files with 13 additions and 6 deletions

View File

@ -52,10 +52,15 @@ static std::vector<std::string> kBlacklistMulti = {
// Blacklisted flags which are always removed from the command line.
static std::vector<std::string> 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<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) {
std::vector<std::string> 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())

View File

@ -245,7 +245,7 @@ optional<std::string> ReadContent(const std::string& filename) {
}
}
std::vector<std::string> ReadLines(std::string filename) {
std::vector<std::string> ReadLinesWithEnding(std::string filename) {
std::vector<std::string> result;
std::ifstream input(filename);
@ -296,7 +296,7 @@ std::unordered_map<std::string, std::string> 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;

View File

@ -74,7 +74,7 @@ void EnsureEndsInSlash(std::string& path);
std::string EscapeFileName(std::string path);
optional<std::string> ReadContent(const std::string& filename);
std::vector<std::string> ReadLines(std::string filename);
std::vector<std::string> ReadLinesWithEnding(std::string filename);
std::vector<std::string> ToLines(const std::string& content,
bool trim_whitespace);