From 7b4b9edfe56784de0a5ce44b46d49940235722e6 Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 1 Jun 2021 19:15:00 +0200 Subject: [PATCH] Rename file names in search::matches to make it more clear. --- src/output.cpp | 2 +- src/search.cpp | 4 ++-- src/search.hpp | 12 ++++++------ tests/test_search_epub.cpp | 22 +++++++++++----------- tests/test_search_zip.cpp | 14 ++++++++------ 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index e2c14f6..6e1acbd 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -58,7 +58,7 @@ void print_matches(const std::vector &matches, std::vector metadata; if (!opts.no_fn_epub) { - metadata.emplace_back(match.filepath); + metadata.emplace_back(match.filepath_inside); } if (!match.headline.empty()) { diff --git a/src/search.cpp b/src/search.cpp index 546a12b..af29a5e 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -100,8 +100,8 @@ std::vector search(const fs::path &filepath, boost::match_default)) { match match; // FIXME: Rename variable or struct. - match.epub_filepath = filepath; - match.filepath = entry; + match.filepath_epub = filepath; + match.filepath_inside = entry; match.text = match_result[0]; match.context = context(match_result, opts.context); const auto current_headline{headline(match_result.prefix().str())}; diff --git a/src/search.hpp b/src/search.hpp index 0981729..d0e833e 100644 --- a/src/search.hpp +++ b/src/search.hpp @@ -35,12 +35,12 @@ using match_context = std::pair; struct match { - fs::path epub_filepath; //!< File path of the EPUB. - std::string text; //!< Matched string. - match_context context; //!< The context around the match. - std::string filepath; //!< The file path of the matched line. - std::string headline; //!< The last headline, if available. - std::string page; //!< The page number, if available. + fs::path filepath_epub; //!< File path of the EPUB. + std::string text; //!< Matched string. + match_context context; //!< The context around the match. + std::string filepath_inside; //!< The file path of the matched line. + std::string headline; //!< The last headline, if available. + std::string page; //!< The page number, if available. }; struct settings diff --git a/tests/test_search_epub.cpp b/tests/test_search_epub.cpp index 02e450c..2efa990 100644 --- a/tests/test_search_epub.cpp +++ b/tests/test_search_epub.cpp @@ -42,7 +42,7 @@ SCENARIO("Searching EPUB files works") AND_THEN("It returns the match correctly") { REQUIRE_FALSE(exception); - REQUIRE(matches.at(0).filepath == "start.xhtml"); + REQUIRE(matches.at(0).filepath_inside == "start.xhtml"); REQUIRE(matches.at(0).text == "test-file"); REQUIRE(matches.at(1).text == "test-suite"); REQUIRE(matches.at(1).headline == "Test for epubgrep"); @@ -66,16 +66,16 @@ SCENARIO("Searching EPUB files works") AND_THEN("It returns the match correctly") { REQUIRE_FALSE(exception); - REQUIRE(matches.at(0).filepath == "start.xhtml"); + REQUIRE(matches.at(0).filepath_inside == "start.xhtml"); REQUIRE(matches.at(0).context.first == "epubgrep. Just)"); - REQUIRE(matches.at(1).filepath == "metadata.opf"); + REQUIRE(matches.at(1).filepath_inside == "metadata.opf"); REQUIRE(matches.at(1).context.first == "epubgrep. Just)"); - REQUIRE(matches.at(1).filepath == "nav.xhtml"); + REQUIRE(matches.at(1).filepath_inside == "nav.xhtml"); REQUIRE(matches.at(1).context.first == "
  • Start
  • )") + "\n "); - REQUIRE(matches.at(2).filepath == "metadata.opf"); + REQUIRE(matches.at(2).filepath_inside == "metadata.opf"); REQUIRE(matches.at(2).context.first == "