Updates for better partial match support, and to ensure that that the POSIX API functions are able to return the correct error code.

[SVN r9392]
This commit is contained in:
John Maddock
2001-03-03 11:28:50 +00:00
parent efdf9e57a4
commit ee8c9873bc
3 changed files with 23 additions and 11 deletions

View File

@ -103,21 +103,21 @@ template <class charT, class traits, class Allocator>
CONSTRUCTOR_INLINE reg_expression<charT, traits, Allocator>::reg_expression(const charT* p, flag_type f, const Allocator& a) CONSTRUCTOR_INLINE reg_expression<charT, traits, Allocator>::reg_expression(const charT* p, flag_type f, const Allocator& a)
: data(a), pkmp(0), error_code_(REG_EMPTY) : data(a), pkmp(0), error_code_(REG_EMPTY)
{ {
set_expression(p, f); set_expression(p, f | regbase::use_except);
} }
template <class charT, class traits, class Allocator> template <class charT, class traits, class Allocator>
CONSTRUCTOR_INLINE reg_expression<charT, traits, Allocator>::reg_expression(const charT* p1, const charT* p2, flag_type f, const Allocator& a) CONSTRUCTOR_INLINE reg_expression<charT, traits, Allocator>::reg_expression(const charT* p1, const charT* p2, flag_type f, const Allocator& a)
: data(a), pkmp(0), error_code_(REG_EMPTY) : data(a), pkmp(0), error_code_(REG_EMPTY)
{ {
set_expression(p1, p2, f); set_expression(p1, p2, f | regbase::use_except);
} }
template <class charT, class traits, class Allocator> template <class charT, class traits, class Allocator>
CONSTRUCTOR_INLINE reg_expression<charT, traits, Allocator>::reg_expression(const charT* p, size_type len, flag_type f, const Allocator& a) CONSTRUCTOR_INLINE reg_expression<charT, traits, Allocator>::reg_expression(const charT* p, size_type len, flag_type f, const Allocator& a)
: data(a), pkmp(0), error_code_(REG_EMPTY) : data(a), pkmp(0), error_code_(REG_EMPTY)
{ {
set_expression(p, p + len, f); set_expression(p, p + len, f | regbase::use_except);
} }
template <class charT, class traits, class Allocator> template <class charT, class traits, class Allocator>
@ -130,11 +130,14 @@ reg_expression<charT, traits, Allocator>::reg_expression(const reg_expression<ch
if(e.error_code() == 0) if(e.error_code() == 0)
{ {
const charT* pe = e.expression(); const charT* pe = e.expression();
set_expression(pe, pe + e._expression_len, e.flags()); set_expression(pe, pe + e._expression_len, e.flags() | regbase::use_except);
} }
else else
{
_flags = regbase::use_except;
fail(e.error_code()); fail(e.error_code());
} }
}
template <class charT, class traits, class Allocator> template <class charT, class traits, class Allocator>
reg_expression<charT, traits, Allocator>::~reg_expression() reg_expression<charT, traits, Allocator>::~reg_expression()
@ -153,7 +156,7 @@ reg_expression<charT, traits, Allocator>& BOOST_RE_CALL reg_expression<charT, tr
_flags = use_except; _flags = use_except;
fail(e.error_code()); fail(e.error_code());
if(error_code() == 0) if(error_code() == 0)
set_expression(e._expression, e._expression + e._expression_len, e.flags()); set_expression(e._expression, e._expression + e._expression_len, e.flags() | regbase::use_except);
return *this; return *this;
} }
@ -2005,8 +2008,16 @@ void BOOST_RE_CALL reg_expression<charT, traits, Allocator>::fail(unsigned int e
{ {
error_code_ = err; error_code_ = err;
if(err) if(err)
{
_flags |= regbase::failbit;
if(_flags & regbase::use_except)
{
throw bad_expression(traits_inst.error_string(err)); throw bad_expression(traits_inst.error_string(err));
} }
}
else
_flags &= ~regbase::failbit;
}
#if defined(BOOST_RE_NO_TEMPLATE_SWITCH_MERGE) && !defined(BOOST_RE_NO_NAMESPACES) #if defined(BOOST_RE_NO_TEMPLATE_SWITCH_MERGE) && !defined(BOOST_RE_NO_NAMESPACES)

View File

@ -879,6 +879,7 @@ bool query_match_aux(iterator first,
&& (first == last)) // end of input has been reached && (first == last)) // end of input has been reached
{ {
have_partial_match = true; have_partial_match = true;
temp_match.set_second(first, 0, false);
m.maybe_assign(temp_match); m.maybe_assign(temp_match);
} }

View File

@ -521,7 +521,7 @@ public:
template <class ST, class SA> template <class ST, class SA>
explicit reg_expression(const std::basic_string<charT, ST, SA>& p, flag_type f = regbase::normal, const Allocator& a = Allocator()) explicit reg_expression(const std::basic_string<charT, ST, SA>& p, flag_type f = regbase::normal, const Allocator& a = Allocator())
: data(a), pkmp(0) { set_expression(p, f); } : data(a), pkmp(0) { set_expression(p, f | regbase::use_except); }
template <class I> template <class I>
reg_expression(I first, I last, flag_type f = regbase::normal, const Allocator& al = Allocator()) reg_expression(I first, I last, flag_type f = regbase::normal, const Allocator& al = Allocator())
@ -562,10 +562,10 @@ public:
} }
#elif !defined(BOOST_RE_NO_STRING_DEF_ARGS) #elif !defined(BOOST_RE_NO_STRING_DEF_ARGS)
unsigned int BOOST_RE_CALL set_expression(const std::basic_string<charT>& p, flag_type f = regbase::normal) unsigned int BOOST_RE_CALL set_expression(const std::basic_string<charT>& p, flag_type f = regbase::normal)
{ return set_expression(p.data(), p.data() + p.size(), f); } { return set_expression(p.data(), p.data() + p.size(), f | regbase::use_except); }
reg_expression(const std::basic_string<charT>& p, flag_type f = regbase::normal, const Allocator& a = Allocator()) reg_expression(const std::basic_string<charT>& p, flag_type f = regbase::normal, const Allocator& a = Allocator())
: data(a), pkmp(0) { set_expression(p, f); } : data(a), pkmp(0) { set_expression(p, f | regbase::use_except); }
reg_expression& BOOST_RE_CALL operator=(const std::basic_string<charT>& p) reg_expression& BOOST_RE_CALL operator=(const std::basic_string<charT>& p)
{ {
@ -980,11 +980,11 @@ public:
ref->tail.matched = (ref->tail.first == ref->tail.second) ? false : true; ref->tail.matched = (ref->tail.first == ref->tail.second) ? false : true;
} }
void BOOST_RE_CALL set_second(iterator i, size_t pos) void BOOST_RE_CALL set_second(iterator i, size_t pos, bool m = true)
{ {
cow(); cow();
((sub_match<iterator>*)((char*)ref + sizeof(c_reference) + sizeof(sub_match<iterator>) * pos))->second = i; ((sub_match<iterator>*)((char*)ref + sizeof(c_reference) + sizeof(sub_match<iterator>) * pos))->second = i;
((sub_match<iterator>*)((char*)ref + sizeof(c_reference) + sizeof(sub_match<iterator>) * pos))->matched = true; ((sub_match<iterator>*)((char*)ref + sizeof(c_reference) + sizeof(sub_match<iterator>) * pos))->matched = m;
if(pos == 0) if(pos == 0)
{ {
ref->tail.first = i; ref->tail.first = i;