- Removed regex support (controlled in main.h by #ifdef FEATURE_REGEX),
  because it has proven buggy.
This commit is contained in:
Paul Beckingham 2011-01-25 23:54:44 -05:00
parent 14f06e98b7
commit 06e15b6e25
4 changed files with 107 additions and 57 deletions

View file

@ -37,6 +37,7 @@
#include <Duration.h> #include <Duration.h>
#include <Context.h> #include <Context.h>
#include <Att.h> #include <Att.h>
#include <main.h>
extern Context context; extern Context context;
@ -587,6 +588,7 @@ bool Att::match (const Att& other) const
} }
else else
{ {
#ifdef FEATURE_REGEX
if (regex) if (regex)
{ {
std::string pattern = "^" + mValue + "$"; std::string pattern = "^" + mValue + "$";
@ -595,12 +597,17 @@ bool Att::match (const Att& other) const
} }
else if (!compare (mValue, other.mValue, (bool) case_sensitive)) else if (!compare (mValue, other.mValue, (bool) case_sensitive))
return false; return false;
#else
if (!compare (mValue, other.mValue, (bool) case_sensitive))
return false;
#endif
} }
} }
// has = contains as a substring. // has = contains as a substring.
else if (mMod == "has" || mMod == "contains") // TODO i18n else if (mMod == "has" || mMod == "contains") // TODO i18n
{ {
#ifdef FEATURE_REGEX
if (regex) if (regex)
{ {
if (!regexMatch (other.mValue, mValue, case_sensitive)) 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) else if (find (other.mValue, mValue, (bool) case_sensitive) == std::string::npos)
return false; return false;
#else
if (find (other.mValue, mValue, (bool) case_sensitive) == std::string::npos)
return false;
#endif
} }
// is = equal. Nop. // is = equal. Nop.
else if (mMod == "is" || mMod == "equals") // TODO i18n else if (mMod == "is" || mMod == "equals") // TODO i18n
{ {
#ifdef FEATURE_REGEX
if (regex) if (regex)
{ {
std::string pattern = "^" + mValue + "$"; std::string pattern = "^" + mValue + "$";
@ -621,11 +633,16 @@ bool Att::match (const Att& other) const
} }
else if (!compare (mValue, other.mValue, (bool) case_sensitive)) else if (!compare (mValue, other.mValue, (bool) case_sensitive))
return false; return false;
#else
if (!compare (mValue, other.mValue, (bool) case_sensitive))
return false;
#endif
} }
// isnt = not equal. // isnt = not equal.
else if (mMod == "isnt" || mMod == "not") // TODO i18n else if (mMod == "isnt" || mMod == "not") // TODO i18n
{ {
#ifdef FEATURE_REGEX
if (regex) if (regex)
{ {
std::string pattern = "^" + mValue + "$"; std::string pattern = "^" + mValue + "$";
@ -634,6 +651,10 @@ bool Att::match (const Att& other) const
} }
else if (compare (mValue, other.mValue, (bool) case_sensitive)) else if (compare (mValue, other.mValue, (bool) case_sensitive))
return false; return false;
#else
if (compare (mValue, other.mValue, (bool) case_sensitive))
return false;
#endif
} }
// any = any value, but not empty value. // any = any value, but not empty value.
@ -653,6 +674,7 @@ bool Att::match (const Att& other) const
// startswith = first characters must match. // startswith = first characters must match.
else if (mMod == "startswith" || mMod == "left") // TODO i18n else if (mMod == "startswith" || mMod == "left") // TODO i18n
{ {
#ifdef FEATURE_REGEX
if (regex) if (regex)
{ {
std::string pattern = "^" + mValue; std::string pattern = "^" + mValue;
@ -661,17 +683,21 @@ bool Att::match (const Att& other) const
} }
else else
{ {
#endif
if (other.mValue.length () < mValue.length ()) if (other.mValue.length () < mValue.length ())
return false; return false;
if (!compare (mValue, other.mValue.substr (0, mValue.length ()), (bool) case_sensitive)) if (!compare (mValue, other.mValue.substr (0, mValue.length ()), (bool) case_sensitive))
return false; return false;
#ifdef FEATURE_REGEX
} }
#endif
} }
// endswith = last characters must match. // endswith = last characters must match.
else if (mMod == "endswith" || mMod == "right") // TODO i18n else if (mMod == "endswith" || mMod == "right") // TODO i18n
{ {
#ifdef FEATURE_REGEX
if (regex) if (regex)
{ {
std::string pattern = mValue + "$"; std::string pattern = mValue + "$";
@ -680,6 +706,7 @@ bool Att::match (const Att& other) const
} }
else else
{ {
#endif
if (other.mValue.length () < mValue.length ()) if (other.mValue.length () < mValue.length ())
return false; return false;
@ -687,12 +714,15 @@ bool Att::match (const Att& other) const
other.mValue.length () - mValue.length (), other.mValue.length () - mValue.length (),
std::string::npos), (bool) case_sensitive)) std::string::npos), (bool) case_sensitive))
return false; return false;
#ifdef FEATURE_REGEX
} }
#endif
} }
// hasnt = does not contain as a substring. // hasnt = does not contain as a substring.
else if (mMod == "hasnt") // TODO i18n else if (mMod == "hasnt") // TODO i18n
{ {
#ifdef FEATURE_REGEX
if (regex) if (regex)
{ {
if (regexMatch (other.mValue, mValue, case_sensitive)) 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) else if (find (other.mValue, mValue, (bool) case_sensitive) != std::string::npos)
return false; return false;
#else
if (find (other.mValue, mValue, (bool) case_sensitive) != std::string::npos)
return false;
#endif
} }
// before = under = below = < // before = under = below = <
@ -781,6 +815,7 @@ bool Att::match (const Att& other) const
// word = contains as a substring, with word boundaries. // word = contains as a substring, with word boundaries.
else if (mMod == "word") // TODO i18n else if (mMod == "word") // TODO i18n
{ {
#ifdef FEATURE_REGEX
if (regex && other.mName != "tags") if (regex && other.mName != "tags")
{ {
std::vector <int> start; std::vector <int> start;
@ -796,6 +831,7 @@ bool Att::match (const Att& other) const
} }
else else
{ {
#endif
// Fail if the substring is not found. // Fail if the substring is not found.
std::string::size_type sub = find (other.mValue, mValue, (bool) case_sensitive); std::string::size_type sub = find (other.mValue, mValue, (bool) case_sensitive);
if (sub == std::string::npos) if (sub == std::string::npos)
@ -807,12 +843,15 @@ bool Att::match (const Att& other) const
if (!isWordEnd (other.mValue, sub + mValue.length () - 1)) if (!isWordEnd (other.mValue, sub + mValue.length () - 1))
return false; return false;
#ifdef FEATURE_REGEX
} }
#endif
} }
// noword = does not contain as a substring, with word boundaries. // noword = does not contain as a substring, with word boundaries.
else if (mMod == "noword") // TODO i18n else if (mMod == "noword") // TODO i18n
{ {
#ifdef FEATURE_REGEX
if (regex && other.mName != "tags") if (regex && other.mName != "tags")
{ {
std::vector <int> start; std::vector <int> start;
@ -824,6 +863,7 @@ bool Att::match (const Att& other) const
} }
else else
{ {
#endif
// Fail if the substring is not found. // Fail if the substring is not found.
std::string::size_type sub = find (other.mValue, mValue); std::string::size_type sub = find (other.mValue, mValue);
if (sub != std::string::npos && if (sub != std::string::npos &&
@ -832,7 +872,9 @@ bool Att::match (const Att& other) const
{ {
return false; return false;
} }
#ifdef FEATURE_REGEX
} }
#endif
} }
return true; return true;

View file

@ -32,6 +32,7 @@
#include <text.h> #include <text.h>
#include <rx.h> #include <rx.h>
#include <i18n.h> #include <i18n.h>
#include <main.h>
extern Context context; extern Context context;
@ -132,6 +133,7 @@ void Subst::apply (
if (mFrom != "") if (mFrom != "")
{ {
#ifdef FEATURE_REGEX
if (context.config.getBoolean ("regex")) if (context.config.getBoolean ("regex"))
{ {
// Insert capturing parentheses, if necessary. // Insert capturing parentheses, if necessary.
@ -185,6 +187,7 @@ void Subst::apply (
} }
else else
{ {
#endif
if (mGlobal) if (mGlobal)
{ {
// Perform all subs on description. // Perform all subs on description.
@ -241,7 +244,9 @@ void Subst::apply (
} }
} }
} }
#ifdef FEATURE_REGEX
} }
#endif
} }
} }

View file

@ -33,6 +33,8 @@
#define FEATURE_NCURSES_COLS 1 // Shortcut that avoids WINDOW. #define FEATURE_NCURSES_COLS 1 // Shortcut that avoids WINDOW.
#define FEATURE_URL 1 // URL support for import. #define FEATURE_URL 1 // URL support for import.
// (always enabled for merge/push/pull) // (always enabled for merge/push/pull)
//#define FEATURE_REGEX 1 // Enables regexes for attribute modifiers,
// // subst, general search.
#include <string> #include <string>
#include <vector> #include <vector>

View file

@ -28,7 +28,8 @@
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 180; #use Test::More tests => 180;
use Test::More tests => 131;
# Create the rc file. # Create the rc file.
if (open my $fh, '>', 'filter.rc') if (open my $fh, '>', 'filter.rc')
@ -210,68 +211,68 @@ unlike ($output, qr/six/, 'r6');
unlike ($output, qr/seven/, 'r7'); unlike ($output, qr/seven/, 'r7');
# Regex filters. # Regex filters.
$output = qx{../src/task rc:filter.rc list rc.regex:on project:[A-Z]}; #$output = qx{../src/task rc:filter.rc list rc.regex:on project:[A-Z]};
like ($output, qr/one/, 's1'); #like ($output, qr/one/, 's1');
like ($output, qr/two/, 's2'); #like ($output, qr/two/, 's2');
like ($output, qr/three/, 's3'); #like ($output, qr/three/, 's3');
unlike ($output, qr/four/, 's4'); #unlike ($output, qr/four/, 's4');
unlike ($output, qr/five/, 's5'); #unlike ($output, qr/five/, 's5');
unlike ($output, qr/six/, 's6'); #unlike ($output, qr/six/, 's6');
unlike ($output, qr/seven/, 's7'); #unlike ($output, qr/seven/, 's7');
$output = qx{../src/task rc:filter.rc list rc.regex:on project:.}; #$output = qx{../src/task rc:filter.rc list rc.regex:on project:.};
like ($output, qr/one/, 't1'); #like ($output, qr/one/, 't1');
like ($output, qr/two/, 't2'); #like ($output, qr/two/, 't2');
like ($output, qr/three/, 't3'); #like ($output, qr/three/, 't3');
unlike ($output, qr/four/, 't4'); #unlike ($output, qr/four/, 't4');
unlike ($output, qr/five/, 't5'); #unlike ($output, qr/five/, 't5');
unlike ($output, qr/six/, 't6'); #unlike ($output, qr/six/, 't6');
unlike ($output, qr/seven/, 't7'); #unlike ($output, qr/seven/, 't7');
$output = qx{../src/task rc:filter.rc rc.regex:on list fo\{2\}}; #$output = qx{../src/task rc:filter.rc rc.regex:on list fo\{2\}};
like ($output, qr/one/, 'u1'); #like ($output, qr/one/, 'u1');
unlike ($output, qr/two/, 'u2'); #unlike ($output, qr/two/, 'u2');
unlike ($output, qr/three/, 'u3'); #unlike ($output, qr/three/, 'u3');
unlike ($output, qr/four/, 'u4'); #unlike ($output, qr/four/, 'u4');
unlike ($output, qr/five/, 'u5'); #unlike ($output, qr/five/, 'u5');
like ($output, qr/six/, 'u6'); #like ($output, qr/six/, 'u6');
like ($output, qr/seven/, 'u7'); #like ($output, qr/seven/, 'u7');
$output = qx{../src/task rc:filter.rc rc.regex:on list f.. b..}; #$output = qx{../src/task rc:filter.rc rc.regex:on list f.. b..};
unlike ($output, qr/one/, 'v1'); #unlike ($output, qr/one/, 'v1');
unlike ($output, qr/two/, 'v2'); #unlike ($output, qr/two/, 'v2');
unlike ($output, qr/three/, 'v3'); #unlike ($output, qr/three/, 'v3');
unlike ($output, qr/four/, 'v4'); #unlike ($output, qr/four/, 'v4');
unlike ($output, qr/five/, 'v5'); #unlike ($output, qr/five/, 'v5');
unlike ($output, qr/six/, 'v6'); #unlike ($output, qr/six/, 'v6');
like ($output, qr/seven/, 'v7'); #like ($output, qr/seven/, 'v7');
$output = qx{../src/task rc:filter.rc rc.regex:on list ^s}; #$output = qx{../src/task rc:filter.rc rc.regex:on list ^s};
unlike ($output, qr/one/, 'w1'); #unlike ($output, qr/one/, 'w1');
unlike ($output, qr/two/, 'w2'); #unlike ($output, qr/two/, 'w2');
unlike ($output, qr/three/, 'w3'); #unlike ($output, qr/three/, 'w3');
unlike ($output, qr/four/, 'w4'); #unlike ($output, qr/four/, 'w4');
unlike ($output, qr/five/, 'w5'); #unlike ($output, qr/five/, 'w5');
like ($output, qr/six/, 'w6'); #like ($output, qr/six/, 'w6');
like ($output, qr/seven/, 'w7'); #like ($output, qr/seven/, 'w7');
$output = qx{../src/task rc:filter.rc rc.regex:on list ^.i}; #$output = qx{../src/task rc:filter.rc rc.regex:on list ^.i};
unlike ($output, qr/one/, 'x1'); #unlike ($output, qr/one/, 'x1');
unlike ($output, qr/two/, 'x2'); #unlike ($output, qr/two/, 'x2');
unlike ($output, qr/three/, 'x3'); #unlike ($output, qr/three/, 'x3');
unlike ($output, qr/four/, 'x4'); #unlike ($output, qr/four/, 'x4');
like ($output, qr/five/, 'x5'); #like ($output, qr/five/, 'x5');
like ($output, qr/six/, 'x6'); #like ($output, qr/six/, 'x6');
unlike ($output, qr/seven/, 'x7'); #unlike ($output, qr/seven/, 'x7');
$output = qx{../src/task rc:filter.rc rc.regex:on list "two|five"}; #$output = qx{../src/task rc:filter.rc rc.regex:on list "two|five"};
unlike ($output, qr/one/, 'y1'); #unlike ($output, qr/one/, 'y1');
like ($output, qr/two/, 'y2'); #like ($output, qr/two/, 'y2');
unlike ($output, qr/three/, 'y3'); #unlike ($output, qr/three/, 'y3');
unlike ($output, qr/four/, 'y4'); #unlike ($output, qr/four/, 'y4');
like ($output, qr/five/, 'y5'); #like ($output, qr/five/, 'y5');
unlike ($output, qr/six/, 'y6'); #unlike ($output, qr/six/, 'y6');
unlike ($output, qr/seven/, 'y7'); #unlike ($output, qr/seven/, 'y7');
# Cleanup. # Cleanup.
unlink 'pending.data'; unlink 'pending.data';