Skip to content

Commit

Permalink
Fixed errors in second order quantifiers: ?? == .{0, 2} and `## == …
Browse files Browse the repository at this point in the history
….{2}`

For example:

* False positive matching `[1####_of` for `TV_[11_of_24]`
* Crashed `number = '????';` for `number = '123';`
* and related.

Added new tests. Use this for details!
  • Loading branch information
3F committed Aug 8, 2020
1 parent fe35401 commit 3f89cc8
Show file tree
Hide file tree
Showing 5 changed files with 580 additions and 4 deletions.
13 changes: 9 additions & 4 deletions regXwild/core/ESS/AlgorithmEss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ bool AlgorithmEss::search(const tstring& text, const tstring& filter, bool ignor
udiff_t AlgorithmEss::interval()
{
// "#"
if(item.mask.prev & SINGLE && (words.found - words.left) != 1)
if(item.mask.prev & SINGLE)
{
udiff_t len = item.prev.length();
diff_t lPos = words.found - len - item.overlay - 1;
Expand All @@ -265,10 +265,15 @@ udiff_t AlgorithmEss::interval()
if(item.mask.prev & ONE && (words.found - words.left) > 1)
{
udiff_t len = item.prev.length();
udiff_t lPosMax = words.found - len;
udiff_t lPos = lPosMax - item.overlay - 1;
diff_t lPosMax = words.found - len;
diff_t lPos = lPosMax - item.overlay - 1;

do{ // ????? - min<->max:
if(lPos < 0) { // When filter ???? (0-4) is more than origin data.
lPos = 0; //TOOD: currently no info about mixed ms like ??#?
}

do // ????? - min<->max:
{
if(_text.substr(lPos, len).compare(item.prev) == 0){
return words.found;
}
Expand Down
41 changes: 41 additions & 0 deletions regXwildTest/AlgorithmEssTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,47 @@ namespace regXwildTest
Assert::AreEqual(true, regXwild::searchEss(_T("system"), _T("sy*stem"), false));
}

TEST_METHOD(underscoreTest1)
{
tstring data = _T("TV_[11_of_24]");

Assert::IsTrue(searchEss(data, _T("1#_of")));
Assert::IsTrue(searchEss(data, _T("#1_of")));
Assert::IsTrue(searchEss(data, _T("1_of")));
Assert::IsTrue(searchEss(data, _T("[1#_o*24")));
Assert::IsFalse(searchEss(data, _T("[1##_o*24")));
Assert::IsFalse(searchEss(data, _T("[1###_o*24")));
Assert::IsFalse(searchEss(data, _T("[1###_o")));
Assert::IsFalse(searchEss(data, _T("[1###_of")));
Assert::IsTrue(searchEss(data, _T("[1#_of")));
Assert::IsFalse(searchEss(data, _T("[1__of")));
Assert::IsTrue(searchEss(data, _T("1_of")));
Assert::IsTrue(searchEss(data, _T("[1??_of")));
Assert::IsTrue(searchEss(data, _T("[1???_of")));
}

TEST_METHOD(underscoreTest2)
{
tstring data = _T("TV_[11_of_24]");

Assert::IsFalse(searchEss(data, _T("1####4")));
Assert::IsTrue(searchEss(data, _T("1#####4")));
Assert::IsTrue(searchEss(data, _T("1######4")));
Assert::IsFalse(searchEss(data, _T("f####4")));
Assert::IsFalse(searchEss(data, _T("f###4")));
Assert::IsTrue(searchEss(data, _T("f##4")));
Assert::IsFalse(searchEss(data, _T("1#######_of")));
Assert::IsFalse(searchEss(data, _T("1###############_of")));
Assert::IsFalse(searchEss(data, _T("1###############f")));
Assert::IsFalse(searchEss(data, _T("1###############_f")));
Assert::IsFalse(searchEss(data, _T("1###############_o")));
Assert::IsFalse(searchEss(data, _T("[1####_of")));
Assert::IsFalse(searchEss(data, _T("[1####of")));
Assert::IsFalse(searchEss(data, _T("[1###of")));
Assert::IsTrue(searchEss(data, _T("[1##of")));
}


private:

bool searchEss(const tstring& data, const tstring& filter)
Expand Down
Loading

0 comments on commit 3f89cc8

Please sign in to comment.