From f209c24cf673639190f6434e1d328cb48e31632f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 29 Aug 2016 13:00:28 -0700 Subject: [PATCH] Trim trailing newlines from corpus texts --- spec/helpers/read_test_entries.cc | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/spec/helpers/read_test_entries.cc b/spec/helpers/read_test_entries.cc index 6f829ef4..5b14c9c2 100644 --- a/spec/helpers/read_test_entries.cc +++ b/spec/helpers/read_test_entries.cc @@ -40,58 +40,58 @@ static string trim_output(const string &input) { static vector parse_test_entries(string content) { regex header_pattern("===+\n" "([^=]+)\n" "===+\n", extended); - regex separator_pattern("---+", extended); + regex separator_pattern("---+\n", extended); vector descriptions; vector bodies; for (;;) { smatch matches; if (!regex_search(content, matches, header_pattern) || matches.empty()) - break; + break; string description = matches[1].str(); descriptions.push_back(description); if (!bodies.empty()) - bodies.back().erase(matches.position()); + bodies.back().erase(matches.position()); content.erase(0, matches.position() + matches[0].length()); bodies.push_back(content); } - vector result; + vector result; for (size_t i = 0; i < descriptions.size(); i++) { string body = bodies[i]; smatch matches; if (regex_search(body, matches, separator_pattern)) { result.push_back({ - descriptions[i], - body.substr(0, matches.position()), - trim_output(body.substr(matches.position() + matches[0].length())) + descriptions[i], + body.substr(0, matches.position() - 1), + trim_output(body.substr(matches.position() + matches[0].length())) }); } } - return result; + return result; } static vector list_directory(string dir_name) { - vector result; + vector result; - DIR *dir = opendir(dir_name.c_str()); - if (!dir) { + DIR *dir = opendir(dir_name.c_str()); + if (!dir) { printf("\nTest error - no such directory '%s'", dir_name.c_str()); return result; } - struct dirent *dir_entry; - while ((dir_entry = readdir(dir))) { - string name(dir_entry->d_name); - if (name != "." && name != "..") - result.push_back(dir_name + "/" + name); - } + struct dirent *dir_entry; + while ((dir_entry = readdir(dir))) { + string name(dir_entry->d_name); + if (name != "." && name != "..") + result.push_back(dir_name + "/" + name); + } closedir(dir); - return result; + return result; } static string read_file(string filename) {