diff --git a/src/Att.cpp b/src/Att.cpp index 3e90d8bcc..2ea97309a 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -37,6 +37,7 @@ #include #include #include +#include extern Context context; @@ -587,6 +588,7 @@ bool Att::match (const Att& other) const } else { +#ifdef FEATURE_REGEX if (regex) { std::string pattern = "^" + mValue + "$"; @@ -595,12 +597,17 @@ bool Att::match (const Att& other) const } else if (!compare (mValue, other.mValue, (bool) case_sensitive)) return false; +#else + if (!compare (mValue, other.mValue, (bool) case_sensitive)) + return false; +#endif } } // has = contains as a substring. else if (mMod == "has" || mMod == "contains") // TODO i18n { +#ifdef FEATURE_REGEX if (regex) { if (!regexMatch (other.mValue, mValue, case_sensitive)) @@ -608,11 +615,16 @@ bool Att::match (const Att& other) const } else if (find (other.mValue, mValue, (bool) case_sensitive) == std::string::npos) return false; +#else + if (find (other.mValue, mValue, (bool) case_sensitive) == std::string::npos) + return false; +#endif } // is = equal. Nop. else if (mMod == "is" || mMod == "equals") // TODO i18n { +#ifdef FEATURE_REGEX if (regex) { std::string pattern = "^" + mValue + "$"; @@ -621,11 +633,16 @@ bool Att::match (const Att& other) const } else if (!compare (mValue, other.mValue, (bool) case_sensitive)) return false; +#else + if (!compare (mValue, other.mValue, (bool) case_sensitive)) + return false; +#endif } // isnt = not equal. else if (mMod == "isnt" || mMod == "not") // TODO i18n { +#ifdef FEATURE_REGEX if (regex) { std::string pattern = "^" + mValue + "$"; @@ -634,6 +651,10 @@ bool Att::match (const Att& other) const } else if (compare (mValue, other.mValue, (bool) case_sensitive)) return false; +#else + if (compare (mValue, other.mValue, (bool) case_sensitive)) + return false; +#endif } // any = any value, but not empty value. @@ -653,6 +674,7 @@ bool Att::match (const Att& other) const // startswith = first characters must match. else if (mMod == "startswith" || mMod == "left") // TODO i18n { +#ifdef FEATURE_REGEX if (regex) { std::string pattern = "^" + mValue; @@ -661,17 +683,21 @@ bool Att::match (const Att& other) const } else { +#endif if (other.mValue.length () < mValue.length ()) return false; if (!compare (mValue, other.mValue.substr (0, mValue.length ()), (bool) case_sensitive)) return false; +#ifdef FEATURE_REGEX } +#endif } // endswith = last characters must match. else if (mMod == "endswith" || mMod == "right") // TODO i18n { +#ifdef FEATURE_REGEX if (regex) { std::string pattern = mValue + "$"; @@ -680,6 +706,7 @@ bool Att::match (const Att& other) const } else { +#endif if (other.mValue.length () < mValue.length ()) return false; @@ -687,12 +714,15 @@ bool Att::match (const Att& other) const other.mValue.length () - mValue.length (), std::string::npos), (bool) case_sensitive)) return false; +#ifdef FEATURE_REGEX } +#endif } // hasnt = does not contain as a substring. else if (mMod == "hasnt") // TODO i18n { +#ifdef FEATURE_REGEX if (regex) { if (regexMatch (other.mValue, mValue, case_sensitive)) @@ -700,6 +730,10 @@ bool Att::match (const Att& other) const } else if (find (other.mValue, mValue, (bool) case_sensitive) != std::string::npos) return false; +#else + if (find (other.mValue, mValue, (bool) case_sensitive) != std::string::npos) + return false; +#endif } // before = under = below = < @@ -781,6 +815,7 @@ bool Att::match (const Att& other) const // word = contains as a substring, with word boundaries. else if (mMod == "word") // TODO i18n { +#ifdef FEATURE_REGEX if (regex && other.mName != "tags") { std::vector start; @@ -796,6 +831,7 @@ bool Att::match (const Att& other) const } else { +#endif // Fail if the substring is not found. std::string::size_type sub = find (other.mValue, mValue, (bool) case_sensitive); if (sub == std::string::npos) @@ -807,12 +843,15 @@ bool Att::match (const Att& other) const if (!isWordEnd (other.mValue, sub + mValue.length () - 1)) return false; +#ifdef FEATURE_REGEX } +#endif } // noword = does not contain as a substring, with word boundaries. else if (mMod == "noword") // TODO i18n { +#ifdef FEATURE_REGEX if (regex && other.mName != "tags") { std::vector start; @@ -824,6 +863,7 @@ bool Att::match (const Att& other) const } else { +#endif // Fail if the substring is not found. std::string::size_type sub = find (other.mValue, mValue); if (sub != std::string::npos && @@ -832,7 +872,9 @@ bool Att::match (const Att& other) const { return false; } +#ifdef FEATURE_REGEX } +#endif } return true; diff --git a/src/Subst.cpp b/src/Subst.cpp index 68df862c2..d2b79778b 100644 --- a/src/Subst.cpp +++ b/src/Subst.cpp @@ -32,6 +32,7 @@ #include #include #include +#include extern Context context; @@ -132,6 +133,7 @@ void Subst::apply ( if (mFrom != "") { +#ifdef FEATURE_REGEX if (context.config.getBoolean ("regex")) { // Insert capturing parentheses, if necessary. @@ -185,6 +187,7 @@ void Subst::apply ( } else { +#endif if (mGlobal) { // Perform all subs on description. @@ -241,7 +244,9 @@ void Subst::apply ( } } } +#ifdef FEATURE_REGEX } +#endif } } diff --git a/src/main.h b/src/main.h index 2ff0caacd..ac62b9a65 100644 --- a/src/main.h +++ b/src/main.h @@ -33,6 +33,8 @@ #define FEATURE_NCURSES_COLS 1 // Shortcut that avoids WINDOW. #define FEATURE_URL 1 // URL support for import. // (always enabled for merge/push/pull) +//#define FEATURE_REGEX 1 // Enables regexes for attribute modifiers, +// // subst, general search. #include #include diff --git a/test/filter.t b/test/filter.t index 509443626..8801323a4 100755 --- a/test/filter.t +++ b/test/filter.t @@ -28,7 +28,8 @@ use strict; use warnings; -use Test::More tests => 180; +#use Test::More tests => 180; +use Test::More tests => 131; # Create the rc file. if (open my $fh, '>', 'filter.rc') @@ -210,68 +211,68 @@ unlike ($output, qr/six/, 'r6'); unlike ($output, qr/seven/, 'r7'); # Regex filters. -$output = qx{../src/task rc:filter.rc list rc.regex:on project:[A-Z]}; -like ($output, qr/one/, 's1'); -like ($output, qr/two/, 's2'); -like ($output, qr/three/, 's3'); -unlike ($output, qr/four/, 's4'); -unlike ($output, qr/five/, 's5'); -unlike ($output, qr/six/, 's6'); -unlike ($output, qr/seven/, 's7'); +#$output = qx{../src/task rc:filter.rc list rc.regex:on project:[A-Z]}; +#like ($output, qr/one/, 's1'); +#like ($output, qr/two/, 's2'); +#like ($output, qr/three/, 's3'); +#unlike ($output, qr/four/, 's4'); +#unlike ($output, qr/five/, 's5'); +#unlike ($output, qr/six/, 's6'); +#unlike ($output, qr/seven/, 's7'); -$output = qx{../src/task rc:filter.rc list rc.regex:on project:.}; -like ($output, qr/one/, 't1'); -like ($output, qr/two/, 't2'); -like ($output, qr/three/, 't3'); -unlike ($output, qr/four/, 't4'); -unlike ($output, qr/five/, 't5'); -unlike ($output, qr/six/, 't6'); -unlike ($output, qr/seven/, 't7'); +#$output = qx{../src/task rc:filter.rc list rc.regex:on project:.}; +#like ($output, qr/one/, 't1'); +#like ($output, qr/two/, 't2'); +#like ($output, qr/three/, 't3'); +#unlike ($output, qr/four/, 't4'); +#unlike ($output, qr/five/, 't5'); +#unlike ($output, qr/six/, 't6'); +#unlike ($output, qr/seven/, 't7'); -$output = qx{../src/task rc:filter.rc rc.regex:on list fo\{2\}}; -like ($output, qr/one/, 'u1'); -unlike ($output, qr/two/, 'u2'); -unlike ($output, qr/three/, 'u3'); -unlike ($output, qr/four/, 'u4'); -unlike ($output, qr/five/, 'u5'); -like ($output, qr/six/, 'u6'); -like ($output, qr/seven/, 'u7'); +#$output = qx{../src/task rc:filter.rc rc.regex:on list fo\{2\}}; +#like ($output, qr/one/, 'u1'); +#unlike ($output, qr/two/, 'u2'); +#unlike ($output, qr/three/, 'u3'); +#unlike ($output, qr/four/, 'u4'); +#unlike ($output, qr/five/, 'u5'); +#like ($output, qr/six/, 'u6'); +#like ($output, qr/seven/, 'u7'); -$output = qx{../src/task rc:filter.rc rc.regex:on list f.. b..}; -unlike ($output, qr/one/, 'v1'); -unlike ($output, qr/two/, 'v2'); -unlike ($output, qr/three/, 'v3'); -unlike ($output, qr/four/, 'v4'); -unlike ($output, qr/five/, 'v5'); -unlike ($output, qr/six/, 'v6'); -like ($output, qr/seven/, 'v7'); +#$output = qx{../src/task rc:filter.rc rc.regex:on list f.. b..}; +#unlike ($output, qr/one/, 'v1'); +#unlike ($output, qr/two/, 'v2'); +#unlike ($output, qr/three/, 'v3'); +#unlike ($output, qr/four/, 'v4'); +#unlike ($output, qr/five/, 'v5'); +#unlike ($output, qr/six/, 'v6'); +#like ($output, qr/seven/, 'v7'); -$output = qx{../src/task rc:filter.rc rc.regex:on list ^s}; -unlike ($output, qr/one/, 'w1'); -unlike ($output, qr/two/, 'w2'); -unlike ($output, qr/three/, 'w3'); -unlike ($output, qr/four/, 'w4'); -unlike ($output, qr/five/, 'w5'); -like ($output, qr/six/, 'w6'); -like ($output, qr/seven/, 'w7'); +#$output = qx{../src/task rc:filter.rc rc.regex:on list ^s}; +#unlike ($output, qr/one/, 'w1'); +#unlike ($output, qr/two/, 'w2'); +#unlike ($output, qr/three/, 'w3'); +#unlike ($output, qr/four/, 'w4'); +#unlike ($output, qr/five/, 'w5'); +#like ($output, qr/six/, 'w6'); +#like ($output, qr/seven/, 'w7'); -$output = qx{../src/task rc:filter.rc rc.regex:on list ^.i}; -unlike ($output, qr/one/, 'x1'); -unlike ($output, qr/two/, 'x2'); -unlike ($output, qr/three/, 'x3'); -unlike ($output, qr/four/, 'x4'); -like ($output, qr/five/, 'x5'); -like ($output, qr/six/, 'x6'); -unlike ($output, qr/seven/, 'x7'); +#$output = qx{../src/task rc:filter.rc rc.regex:on list ^.i}; +#unlike ($output, qr/one/, 'x1'); +#unlike ($output, qr/two/, 'x2'); +#unlike ($output, qr/three/, 'x3'); +#unlike ($output, qr/four/, 'x4'); +#like ($output, qr/five/, 'x5'); +#like ($output, qr/six/, 'x6'); +#unlike ($output, qr/seven/, 'x7'); -$output = qx{../src/task rc:filter.rc rc.regex:on list "two|five"}; -unlike ($output, qr/one/, 'y1'); -like ($output, qr/two/, 'y2'); -unlike ($output, qr/three/, 'y3'); -unlike ($output, qr/four/, 'y4'); -like ($output, qr/five/, 'y5'); -unlike ($output, qr/six/, 'y6'); -unlike ($output, qr/seven/, 'y7'); +#$output = qx{../src/task rc:filter.rc rc.regex:on list "two|five"}; +#unlike ($output, qr/one/, 'y1'); +#like ($output, qr/two/, 'y2'); +#unlike ($output, qr/three/, 'y3'); +#unlike ($output, qr/four/, 'y4'); +#like ($output, qr/five/, 'y5'); +#unlike ($output, qr/six/, 'y6'); +#unlike ($output, qr/seven/, 'y7'); # Cleanup. unlink 'pending.data';