📄 perl_matcher_recursive.hpp
字号:
save_pos = position;
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
return false;
++count;
pstate = psingle;
position = save_pos;
if(!match_wild())
return false;
}while(true);
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::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))
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));
if(rep->min > count)
return false; // not enough text left to match
std::advance(position, count);
if((rep->leading) && (count < rep->max) && (rep->greedy))
restart = position;
if(rep->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))
{
++position;
++count;
}
if((rep->leading) && (count == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
return false;
if(position == last)
return false;
position = ++save_pos;
++count;
}while(true);
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
#ifdef __BORLANDC__
#pragma option push -w-8008 -w-8066 -w-8004
#endif
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
assert(1 == static_cast<const re_literal*>(rep->next.p)->length);
const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(rep->next.p) + 1);
unsigned count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->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));
BidiIterator origin(position);
while((position != end) && (traits_inst.translate(*position, icase) == what))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && (traits_inst.translate(*position, icase) == what))
{
++position;
++count;
}
}
if((rep->leading) && (count < rep->max) && (rep->greedy))
restart = position;
if(count < rep->min)
return false;
if(rep->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))
{
if((traits_inst.translate(*position, icase) == what))
{
++position;
++count;
}
else
return false; // counldn't repeat even though it was the only option
}
if((rep->leading) && (rep->max == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
return false;
if(position == last)
return false;
position = ++save_pos;
++count;
}while(true);
#ifdef __BORLANDC__
#pragma option pop
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
#ifdef __BORLANDC__
#pragma option push -w-8008 -w-8066 -w-8004
#endif
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;
unsigned count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->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));
BidiIterator origin(position);
while((position != end) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
{
++position;
++count;
}
}
if((rep->leading) && (count < rep->max) && (rep->greedy))
restart = position;
if(count < rep->min)
return false;
if(rep->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))
{
if(map[(traits_uchar_type)traits_inst.translate(*position, icase)])
{
++position;
++count;
}
else
return false; // counldn't repeat even though it was the only option
}
if((rep->leading) && (rep->max == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
return false;
if(position == last)
return false;
position = ++save_pos;
++count;
}while(true);
#ifdef __BORLANDC__
#pragma option pop
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
#ifdef __BORLANDC__
#pragma option push -w-8008 -w-8066 -w-8004
#endif
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
const re_set_long* set = static_cast<const re_set_long*>(pstate->next.p);
unsigned count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->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));
BidiIterator origin(position);
while((position != end) && (position != re_is_set_member(position, last, set, re)))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re)))
{
++position;
++count;
}
}
if((rep->leading) && (count < rep->max) && (rep->greedy))
restart = position;
if(count < rep->min)
return false;
if(rep->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))
{
if(position != re_is_set_member(position, last, set, re))
{
++position;
++count;
}
else
return false; // counldn't repeat even though it was the only option
}
if((rep->leading) && (rep->max == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
++state_count;
if(match_all_states())
return true;
if(count >= rep->max)
return false;
if(position == last)
return false;
position = ++save_pos;
++count;
}while(true);
#ifdef __BORLANDC__
#pragma option pop
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::backtrack_till_match(unsigned count)
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
if((m_match_flags & match_partial) && (position == last))
m_has_partial_match = true;
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
BidiIterator backtrack = position;
if(position == last)
{
if(rep->can_be_null & mask_skip)
{
pstate = rep->alt.p;
if(match_all_states())
return true;
}
if(count)
{
position = --backtrack;
--count;
}
else
return false;
}
do
{
while(count && !access::can_start(*position, rep->_map, mask_skip))
{
--position;
--count;
++state_count;
}
pstate = rep->alt.p;
backtrack = position;
if(match_all_states())
return true;
if(count == 0)
return false;
position = --backtrack;
++state_count;
--count;
}while(true);
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
} // namespace re_detail
} // namespace boost
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -