From 8b21f4a8b9d023812873c1c91d78d3524365ddd8 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 24 May 2021 16:37:43 +0200 Subject: [PATCH] Don't output empty fields. --- src/main.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f937f76..4e252ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -111,9 +111,18 @@ int main(int argc, char *argv[]) for (const auto &match : search::search(filepath, regex, opts)) { - cout << match.filepath << ", " << match.headline << ", " - << match.page << ": " << match.context.first - << match.text << match.context.second << '\n'; + cout << match.filepath; + if (!match.headline.empty()) + { + + cout << ", " << match.headline; + } + if (!match.page.empty()) + { + cout << ", " << match.page; + } + cout << ": " << match.context.first << match.text + << match.context.second << '\n'; } } }