diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f95b82..85c023a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(remwharead - VERSION 0.3.0 + VERSION 0.3.1 LANGUAGES CXX ) diff --git a/remwharead.1.adoc b/remwharead.1.adoc index b01c675..b6b477a 100644 --- a/remwharead.1.adoc +++ b/remwharead.1.adoc @@ -47,10 +47,12 @@ are date and time representations according to ISO 8601 Example: `--span 2019-01-01,2019-02-10T12:30`. *-s* _expression_, *--search-tags* _expression_:: -Search in tags. Format: _tag1 AND tag2 OR tag3_. See _SEARCH EXPRESSIONS_. +Search in tags. Format: _tag1 AND tag2 OR tag3_. See _SEARCH EXPRESSIONS_. Case +insensitive. *-S* _expression_, *--search-all* _expression_:: -Search in tags, title, description and full text. +Search in tags, title, description and full text. See _SEARCH EXPESSIONS_. Case +insensitive. *-N*, *--no-archive*:: Do not archive URI. diff --git a/src/search.cpp b/src/search.cpp index 0311dea..a067427 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -16,12 +16,15 @@ #include #include +#include +#include #include "search.hpp" using std::regex; using std::regex_search; using std::smatch; using std::find; +using std::find_if; const vector> parse_expression(string expression) { @@ -46,10 +49,10 @@ const vector> parse_expression(string expression) vector terms; while (regex_search(sub, match, re_and)) { - terms.push_back(match[1].str()); + terms.push_back(to_lowercase(match[1].str())); sub = match.suffix().str(); } - terms.push_back(sub); + terms.push_back(to_lowercase(sub)); searchlist.push_back(terms); } } @@ -57,6 +60,16 @@ const vector> parse_expression(string expression) return searchlist; } +const string to_lowercase(const string &str) +{ + std::wstring_convert> converter; + std::wstring in = converter.from_bytes(str); + std::wstring out; + + std::transform(in.begin(), in.end(), std::back_inserter(out), ::towlower); + return converter.to_bytes(out); +} + const vector search_tags(const vector &entries, string expression) { @@ -70,7 +83,9 @@ search_tags(const vector &entries, string expression) bool matched = true; for (const string &tag : tags_or) { - const auto it = find(entry.tags.begin(), entry.tags.end(), tag); + const auto it = find_if(entry.tags.begin(), entry.tags.end(), + [&tag](const string &s) + { return to_lowercase(s) == tag; }); if (it == entry.tags.end()) { matched = false; @@ -110,17 +125,17 @@ search_all(const vector &entries, string expression) for (const string &term : terms_or) { - if (entry.title.find(term) == std::string::npos) + if (to_lowercase(entry.title).find(term) == string::npos) { matched_title = false; } - if (entry.description.find(term) == std::string::npos) + if (to_lowercase(entry.description).find(term) == string::npos) { matched_description = false; } - if (entry.fulltext.find(term) == std::string::npos) + if (to_lowercase(entry.fulltext).find(term) == string::npos) { matched_fulltext = false; } diff --git a/src/search.hpp b/src/search.hpp index 49b79f8..c027f3c 100644 --- a/src/search.hpp +++ b/src/search.hpp @@ -25,6 +25,7 @@ using std::vector; using std::string; const vector> parse_expression(string expression); +const string to_lowercase(const string &str); //! Seach database entries for tags. const vector