merged changes in regex5 branch

[SVN r26692]
This commit is contained in:
John Maddock
2005-01-13 17:06:21 +00:00
parent de0ab9092a
commit 71a0e020e2
275 changed files with 37305 additions and 27154 deletions

View File

@ -45,48 +45,51 @@ public:
const sub_match<BidiIterator>& get() { return sub; }
};
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_all_states()
{
static matcher_proc_type const s_match_vtable[26] =
static matcher_proc_type const s_match_vtable[29] =
{
(&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark),
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_endmark,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_literal,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_start_line,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_end_line,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_wild,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_match,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_boundary,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_within_word,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_start,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_start,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_backref,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_jump,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_combining,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_soft_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_restart_continue,
(::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow),
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat,
(&perl_matcher<BidiIterator, Allocator, traits>::match_startmark),
&perl_matcher<BidiIterator, Allocator, traits>::match_endmark,
&perl_matcher<BidiIterator, Allocator, traits>::match_literal,
&perl_matcher<BidiIterator, Allocator, traits>::match_start_line,
&perl_matcher<BidiIterator, Allocator, traits>::match_end_line,
&perl_matcher<BidiIterator, Allocator, traits>::match_wild,
&perl_matcher<BidiIterator, Allocator, traits>::match_match,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_boundary,
&perl_matcher<BidiIterator, Allocator, traits>::match_within_word,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_start,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_buffer_start,
&perl_matcher<BidiIterator, Allocator, traits>::match_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_backref,
&perl_matcher<BidiIterator, Allocator, traits>::match_long_set,
&perl_matcher<BidiIterator, Allocator, traits>::match_set,
&perl_matcher<BidiIterator, Allocator, traits>::match_jump,
&perl_matcher<BidiIterator, Allocator, traits>::match_alt,
&perl_matcher<BidiIterator, Allocator, traits>::match_rep,
&perl_matcher<BidiIterator, Allocator, traits>::match_combining,
&perl_matcher<BidiIterator, Allocator, traits>::match_soft_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_restart_continue,
(::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow),
&perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_backstep,
&perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref,
&perl_matcher<BidiIterator, Allocator, traits>::match_toggle_case,
};
if(state_count > max_state_count)
raise_error(traits_inst, REG_ESPACE);
raise_error(traits_inst, regex_constants::error_space);
while(pstate)
{
matcher_proc_type proc = s_match_vtable[pstate->type];
++state_count;
if(!(this->*proc)())
{
if((m_match_flags & match_partial) && (position == last))
if((m_match_flags & match_partial) && (position == last) && (position != search_base))
m_has_partial_match = true;
return 0;
}
@ -94,8 +97,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
{
int index = static_cast<const re_brace*>(pstate)->index;
bool r = true;
@ -123,10 +126,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
case -3:
{
// independent sub-expression:
bool old_independent = m_independent;
m_independent = true;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p;
r = match_all_states();
pstate = next_pstate;
m_independent = old_independent;
#ifdef BOOST_REGEX_MATCH_EXTRA
if(r && (m_match_flags & match_extra))
{
@ -156,6 +162,37 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
#endif
break;
}
case -4:
{
// conditional expression:
const re_alt* alt = static_cast<const re_alt*>(pstate->next.p);
BOOST_ASSERT(alt->type == syntax_element_alt);
pstate = alt->next.p;
if(pstate->type == syntax_element_assert_backref)
{
if(!match_assert_backref())
pstate = alt->alt.p;
break;
}
else
{
// zero width assertion, have to match this recursively:
BOOST_ASSERT(pstate->type == syntax_element_startmark);
bool negated = static_cast<const re_brace*>(pstate)->index == -2;
BidiIterator saved_position = position;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p;
bool r = match_all_states();
position = saved_position;
if(negated)
r = !r;
if(r)
pstate = next_pstate;
else
pstate = alt->alt.p;
break;
}
}
default:
{
assert(index > 0);
@ -185,11 +222,11 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
return r;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_alt()
{
bool take_first, take_second;
const re_jump* jmp = static_cast<const re_jump*>(pstate);
const re_alt* jmp = static_cast<const re_alt*>(pstate);
// find out which of these two alternatives we need to take:
if(position == last)
@ -199,8 +236,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
}
else
{
take_first = access::can_start(*position, jmp->_map, (unsigned char)mask_take);
take_second = access::can_start(*position, jmp->_map, (unsigned char)mask_skip);
take_first = can_start(*position, jmp->_map, (unsigned char)mask_take);
take_second = can_start(*position, jmp->_map, (unsigned char)mask_skip);
}
if(take_first)
@ -230,8 +267,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
return false; // neither option is possible
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_rep()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -261,8 +298,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
}
else
{
take_first = access::can_start(*position, rep->_map, (unsigned char)mask_take);
take_second = access::can_start(*position, rep->_map, (unsigned char)mask_skip);
take_first = can_start(*position, rep->_map, (unsigned char)mask_take);
take_second = can_start(*position, rep->_map, (unsigned char)mask_skip);
}
if(next_count->get_count() < rep->min)
@ -277,8 +314,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
}
return false;
}
if(rep->greedy)
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
if(greedy)
{
// try and take the repeat if we can:
if((next_count->get_count() < rep->max) && take_first)
@ -327,8 +364,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -345,7 +382,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
return false;
++count;
}
if(rep->greedy)
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
if(greedy)
{
// normal repeat:
while(count < rep->max)
@ -387,41 +425,51 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast()
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
if(m_match_flags & (match_not_dot_newline | match_not_dot_null))
if(m_match_flags & match_not_dot_null)
return match_dot_repeat_slow();
if((static_cast<const re_dot*>(pstate->next.p)->mask & match_any_mask) == 0)
return match_dot_repeat_slow();
//
// start by working out how much we can skip:
//
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
unsigned count = (std::min)(static_cast<unsigned>(re_detail::distance(position, last)), (rep->greedy ? rep->max : rep->min));
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4267)
#endif
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t count = (std::min)(static_cast<std::size_t>(::boost::re_detail::distance(position, last)), static_cast<std::size_t>(greedy ? rep->max : rep->min));
if(rep->min > count)
{
position = last;
return false; // not enough text left to match
}
std::advance(position, count);
if((rep->leading) && (count < rep->max) && (rep->greedy))
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
if((rep->leading) && (count < rep->max) && greedy)
restart = position;
if(rep->greedy)
if(greedy)
return backtrack_till_match(count - rep->min);
// non-greedy, keep trying till we get a match:
BidiIterator save_pos;
do
{
while((position != last) && (count < rep->max) && !access::can_start(*position, rep->_map, mask_skip))
while((position != last) && (count < rep->max) && !can_start(*position, rep->_map, mask_skip))
{
++position;
++count;
}
if((rep->leading) && (count == UINT_MAX))
if((rep->leading) && (rep->max == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
@ -440,8 +488,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -457,17 +505,18 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((unsigned)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && (traits_inst.translate(*position, icase) == what))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
@ -477,19 +526,19 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
++count;
}
}
if((rep->leading) && (count < rep->max) && (rep->greedy))
if((rep->leading) && (count < rep->max) && greedy)
restart = position;
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
return backtrack_till_match(count - rep->min);
// non-greedy, keep trying till we get a match:
BidiIterator save_pos;
do
{
while((position != last) && (count < rep->max) && !access::can_start(*position, rep->_map, mask_skip))
while((position != last) && (count < rep->max) && !can_start(*position, rep->_map, mask_skip))
{
if((traits_inst.translate(*position, icase) == what))
{
@ -529,8 +578,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -545,41 +594,42 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((unsigned)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
while((position != end) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
while((count < desired) && (position != last) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
++count;
}
}
if((rep->leading) && (count < rep->max) && (rep->greedy))
if((rep->leading) && (count < rep->max) && greedy)
restart = position;
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
return backtrack_till_match(count - rep->min);
// non-greedy, keep trying till we get a match:
BidiIterator save_pos;
do
{
while((position != last) && (count < rep->max) && !access::can_start(*position, rep->_map, mask_skip))
while((position != last) && (count < rep->max) && !can_start(*position, rep->_map, mask_skip))
{
if(map[(traits_uchar_type)traits_inst.translate(*position, icase)])
if(map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
++count;
@ -599,7 +649,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
if(position == last)
return false;
position = save_pos;
if(map[(traits_uchar_type)traits_inst.translate(*position, icase)])
if(map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
++count;
@ -617,8 +667,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -627,47 +677,49 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
#ifdef __BORLANDC__
#pragma option push -w-8008 -w-8066 -w-8004
#endif
typedef typename traits::char_class_type char_class_type;
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
const re_set_long* set = static_cast<const re_set_long*>(pstate->next.p);
const re_set_long<char_class_type>* set = static_cast<const re_set_long<char_class_type>*>(pstate->next.p);
unsigned count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((unsigned)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && (position != re_is_set_member(position, last, set, re)))
while((position != end) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re)))
while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
++position;
++count;
}
}
if((rep->leading) && (count < rep->max) && (rep->greedy))
if((rep->leading) && (count < rep->max) && greedy)
restart = position;
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
return backtrack_till_match(count - rep->min);
// non-greedy, keep trying till we get a match:
BidiIterator save_pos;
do
{
while((position != last) && (count < rep->max) && !access::can_start(*position, rep->_map, mask_skip))
while((position != last) && (count < rep->max) && !can_start(*position, rep->_map, mask_skip))
{
if(position != re_is_set_member(position, last, set, re))
if(position != re_is_set_member(position, last, set, re.get_data(), icase))
{
++position;
++count;
@ -687,7 +739,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
if(position == last)
return false;
position = save_pos;
if(position != re_is_set_member(position, last, set, re))
if(position != re_is_set_member(position, last, set, re.get_data(), icase))
{
++position;
++count;
@ -705,8 +757,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::backtrack_till_match(unsigned count)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::backtrack_till_match(std::size_t count)
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -735,7 +787,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::backtrack_till_m
}
do
{
while(count && !access::can_start(*position, rep->_map, mask_skip))
while(count && !can_start(*position, rep->_map, mask_skip))
{
--position;
--count;