Skip to content

Commit

Permalink
Fix case-sensitivity change behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzmaddock committed Mar 14, 2016
1 parent a976085 commit 9059bfb
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 12 deletions.
1 change: 1 addition & 0 deletions doc/history.qbk
Expand Up @@ -18,6 +18,7 @@ All issues including closed ones can be viewed [@https://svn.boost.org/trac/boos
[h4 Boost.Regex-5.1.1]

* Change to lockfree implementation of memory cache, see [@https://github.com/boostorg/regex/pull/23 PR#23].
* Fix bug in case sensitivity change, see [@https://svn.boost.org/trac/boost/ticket/11940 #11940].

[h4 Boost.Regex-5.1.0 (Boost-1.60.0)]

Expand Down
9 changes: 7 additions & 2 deletions doc/html/boost_regex/background_information/history.html
Expand Up @@ -39,9 +39,14 @@ <h5>
<a name="boost_regex.background_information.history.h0"></a>
<span class="phrase"><a name="boost_regex.background_information.history.boost_regex_5_1_1"></a></span><a class="link" href="history.html#boost_regex.background_information.history.boost_regex_5_1_1">Boost.Regex-5.1.1</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Change to lockfree implementation of memory cache, see <a href="https://github.com/boostorg/regex/pull/23" target="_top">PR#23</a>.
</li></ul></div>
</li>
<li class="listitem">
Fix bug in case sensitivity change, see <a href="https://svn.boost.org/trac/boost/ticket/11940" target="_top">#11940</a>.
</li>
</ul></div>
<h5>
<a name="boost_regex.background_information.history.h1"></a>
<span class="phrase"><a name="boost_regex.background_information.history.boost_regex_5_1_0_boost_1_60_0"></a></span><a class="link" href="history.html#boost_regex.background_information.history.boost_regex_5_1_0_boost_1_60_0">Boost.Regex-5.1.0
Expand Down
2 changes: 1 addition & 1 deletion doc/html/index.html
Expand Up @@ -221,7 +221,7 @@
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: March 12, 2016 at 19:00:00 GMT</small></p></td>
<td align="left"><p><small>Last revised: March 14, 2016 at 19:20:20 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
Expand Down
2 changes: 2 additions & 0 deletions include/boost/regex/v4/perl_matcher.hpp
Expand Up @@ -537,6 +537,7 @@ class perl_matcher
bool unwind_recursion_pop(bool);
bool unwind_commit(bool);
bool unwind_then(bool);
bool unwind_case(bool);
void destroy_single_repeat();
void push_matched_paren(int index, const sub_match<BidiIterator>& sub);
void push_recursion_stopper();
Expand All @@ -547,6 +548,7 @@ class perl_matcher
void push_non_greedy_repeat(const re_syntax_base* ps);
void push_recursion(int idx, const re_syntax_base* p, results_type* presults);
void push_recursion_pop();
void push_case_change(bool);

// pointer to base of stack:
saved_state* m_stack_base;
Expand Down
9 changes: 0 additions & 9 deletions include/boost/regex/v4/perl_matcher_common.hpp
Expand Up @@ -793,15 +793,6 @@ inline bool perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref(
return result;
}

template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_toggle_case()
{
// change our case sensitivity:
this->icase = static_cast<const re_case*>(pstate)->icase;
pstate = pstate->next.p;
return true;
}

template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_fail()
{
Expand Down
43 changes: 43 additions & 0 deletions include/boost/regex/v4/perl_matcher_non_recursive.hpp
Expand Up @@ -138,6 +138,12 @@ struct saved_recursion : public saved_state
Results results;
};

struct saved_change_case : public saved_state
{
bool icase;
saved_change_case(bool c) : saved_state(18), icase(c) {}
};

template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_all_states()
{
Expand Down Expand Up @@ -242,6 +248,22 @@ inline void perl_matcher<BidiIterator, Allocator, traits>::push_matched_paren(in
m_backup_state = pmp;
}

template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_case_change(bool c)
{
//BOOST_ASSERT(index);
saved_change_case* pmp = static_cast<saved_change_case*>(m_backup_state);
--pmp;
if(pmp < m_stack_base)
{
extend_stack();
pmp = static_cast<saved_change_case*>(m_backup_state);
--pmp;
}
(void) new (pmp)saved_change_case(c);
m_backup_state = pmp;
}

template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_recursion_stopper()
{
Expand Down Expand Up @@ -347,6 +369,16 @@ inline void perl_matcher<BidiIterator, Allocator, traits>::push_recursion(int id
m_backup_state = pmp;
}

template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_toggle_case()
{
// change our case sensitivity:
push_case_change(this->icase);
this->icase = static_cast<const re_case*>(pstate)->icase;
pstate = pstate->next.p;
return true;
}

template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
{
Expand Down Expand Up @@ -1142,6 +1174,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::unwind(bool have_match)
&perl_matcher<BidiIterator, Allocator, traits>::unwind_recursion_pop,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_commit,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_then,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_case,
};

m_recursive_result = have_match;
Expand Down Expand Up @@ -1170,6 +1203,16 @@ bool perl_matcher<BidiIterator, Allocator, traits>::unwind_end(bool)
return false; // end of stack nothing more to search
}

template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_case(bool)
{
saved_change_case* pmp = static_cast<saved_change_case*>(m_backup_state);
icase = pmp->icase;
boost::BOOST_REGEX_DETAIL_NS::inplace_destroy(pmp++);
m_backup_state = pmp;
return true;
}

template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_paren(bool have_match)
{
Expand Down
16 changes: 16 additions & 0 deletions include/boost/regex/v4/perl_matcher_recursive.hpp
Expand Up @@ -289,11 +289,13 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_alt()
BidiIterator oldposition(position);
const re_syntax_base* old_pstate = jmp->alt.p;
pstate = pstate->next.p;
bool oldcase = icase;
m_have_then = false;
if(!match_all_states())
{
pstate = old_pstate;
position = oldposition;
icase = oldcase;
if(m_have_then)
{
m_can_backtrack = true;
Expand Down Expand Up @@ -1036,6 +1038,20 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_then()
return false;
}

template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_toggle_case()
{
// change our case sensitivity:
bool oldcase = this->icase;
this->icase = static_cast<const re_case*>(pstate)->icase;
pstate = pstate->next.p;
bool result = match_all_states();
this->icase = oldcase;
return result;
}



template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::skip_until_paren(int index, bool have_match)
{
Expand Down
4 changes: 4 additions & 0 deletions test/regress/test_perl_ex.cpp
Expand Up @@ -245,6 +245,10 @@ void test_options2()
TEST_REGEX_SEARCH("a(?i:b)*c", perl, "aBBc", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("a(?i:b)*c", perl, "aBC", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("a(?i:b)*c", perl, "aBBC", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("(?i:j)|h", perl, "J", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("(?i:j)|h", perl, "j", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("(?i:j)|h", perl, "h", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("(?i:j)|h", perl, "H", match_default, make_array(-2, -2));

TEST_REGEX_SEARCH("a(?=b(?i)c)\\w\\wd", perl, "abcd", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("a(?=b(?i)c)\\w\\wd", perl, "abCd", match_default, make_array(0, 4, -2, -2));
Expand Down

0 comments on commit 9059bfb

Please sign in to comment.