From dcc5dbf16ad2f2ac949196fd72d9abdff022e6d7 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 28 Sep 2014 13:39:50 -0400 Subject: [PATCH] Variant - The ::operator_match (and by extension operator_nomatch) now obey the rc.regex setting. --- src/Context.cpp | 9 +++++++++ src/Variant.cpp | 48 +++++++++++++++++++++++++++++++++++------------- src/Variant.h | 1 + 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index 95b3034f2..a18bbec15 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -126,6 +126,7 @@ int Context::initialize (int argc, const char** argv) Lexer::dateFormat = config.get ("dateformat"); Variant::dateFormat = config.get ("dateformat"); Variant::searchCaseSensitive = config.getBoolean ("search.case.sensitive"); + Variant::searchUsingRegex = config.getBoolean ("regex"); parser.initialize (argc, argv); // task arg0 arg1 ... @@ -148,6 +149,14 @@ int Context::initialize (int argc, const char** argv) // Create missing config file and data directory, if necessary. parser.applyOverrides (); + + // These may have changed. + // TODO Uh oh. + Lexer::dateFormat = config.get ("dateformat"); + Variant::dateFormat = config.get ("dateformat"); + Variant::searchCaseSensitive = config.getBoolean ("search.case.sensitive"); + Variant::searchUsingRegex = config.getBoolean ("regex"); + createDefaultConfig (); // Initialize the color rules, if necessary. diff --git a/src/Variant.cpp b/src/Variant.cpp index e33193874..35e2dc649 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -39,6 +39,7 @@ std::string Variant::dateFormat = ""; bool Variant::searchCaseSensitive = true; +bool Variant::searchUsingRegex = true; //////////////////////////////////////////////////////////////////////////////// Variant::Variant () @@ -913,21 +914,42 @@ bool Variant::operator_match (const Variant& other, const Task& task) const left.cast (type_string); right.cast (type_string); - RX r (right._string, searchCaseSensitive); - if (r.match (left._string)) - return true; - - // If the above did not match, and the left source is "description", then - // in the annotations. - if (left.source () == "description") + if (searchUsingRegex) { - std::map annotations; - task.getAnnotations (annotations); + RX r (right._string, searchCaseSensitive); + if (r.match (left._string)) + return true; - std::map ::iterator a; - for (a = annotations.begin (); a != annotations.end (); ++a) - if (r.match (a->second)) - return true; + // If the above did not match, and the left source is "description", then + // in the annotations. + if (left.source () == "description") + { + std::map annotations; + task.getAnnotations (annotations); + + std::map ::iterator a; + for (a = annotations.begin (); a != annotations.end (); ++a) + if (r.match (a->second)) + return true; + } + } + else + { + if (find (left._string, right._string, searchCaseSensitive) != std::string::npos) + return true; + + // If the above did not match, and the left source is "description", then + // in the annotations. + if (left.source () == "description") + { + std::map annotations; + task.getAnnotations (annotations); + + std::map ::iterator a; + for (a = annotations.begin (); a != annotations.end (); ++a) + if (find (a->second, right._string, searchCaseSensitive) != std::string::npos) + return true; + } } return false; diff --git a/src/Variant.h b/src/Variant.h index 8073fdaf9..b121d21e1 100644 --- a/src/Variant.h +++ b/src/Variant.h @@ -36,6 +36,7 @@ class Variant public: static std::string dateFormat; static bool searchCaseSensitive; + static bool searchUsingRegex; enum type {type_unknown, type_boolean, type_integer, type_real, type_string, type_date, type_duration};