mirror of
https://github.com/boostorg/regex.git
synced 2025-07-16 05:42:15 +02:00
Added support for compilers with no exception handling support.
[SVN r12758]
This commit is contained in:
@ -242,6 +242,7 @@ public:
|
||||
unsigned int SetExpression(const char* p, bool icase = false);
|
||||
unsigned int SetExpression(const std::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); }
|
||||
std::string Expression()const;
|
||||
unsigned int error_code()const;
|
||||
//
|
||||
// now matching operators:
|
||||
//
|
||||
|
@ -794,7 +794,10 @@ int do_toi(iterator i, iterator j, char c, int radix)
|
||||
std::string s(i, j);
|
||||
char* p;
|
||||
int result = std::strtol(s.c_str(), &p, radix);
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
if(*p)throw bad_pattern("Bad sub-expression");
|
||||
#endif
|
||||
BOOST_REGEX_NOEH_ASSERT(0 == *p)
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -819,7 +822,10 @@ sub_match<iterator>::operator int()const
|
||||
{
|
||||
iterator i = first;
|
||||
iterator j = second;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
if(i == j)throw bad_pattern("Bad sub-expression");
|
||||
#endif
|
||||
BOOST_REGEX_NOEH_ASSERT(i != j)
|
||||
int neg = 1;
|
||||
if((i != j) && (*i == '-'))
|
||||
{
|
||||
@ -827,7 +833,10 @@ sub_match<iterator>::operator int()const
|
||||
++i;
|
||||
}
|
||||
neg *= re_detail::do_toi(i, j, *i);
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
if(i != j)throw bad_pattern("Bad sub-expression");
|
||||
#endif
|
||||
BOOST_REGEX_NOEH_ASSERT(i == j)
|
||||
return neg;
|
||||
}
|
||||
template <class iterator>
|
||||
@ -835,8 +844,11 @@ sub_match<iterator>::operator unsigned int()const
|
||||
{
|
||||
iterator i = first;
|
||||
iterator j = second;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
if(i == j)
|
||||
throw bad_pattern("Bad sub-expression");
|
||||
#endif
|
||||
BOOST_REGEX_NOEH_ASSERT(i != j)
|
||||
return re_detail::do_toi(i, j, *first);
|
||||
}
|
||||
#endif
|
||||
@ -1063,27 +1075,33 @@ template <class iterator, class Allocator>
|
||||
match_results_base<iterator, Allocator>::match_results_base(const Allocator& a)
|
||||
{
|
||||
ref = (c_reference*)c_alloc(a).allocate(sizeof(sub_match<iterator>) + sizeof(c_reference));
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
new (ref) c_reference(a);
|
||||
ref->cmatches = 1;
|
||||
ref->count = 1;
|
||||
// construct the sub_match<iterator>:
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
new ((sub_match<iterator>*)(ref+1)) sub_match<iterator>();
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
::boost::re_detail::pointer_destroy(ref);
|
||||
throw;
|
||||
{
|
||||
::boost::re_detail::pointer_destroy(ref);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
c_alloc(a).deallocate((char*)(void*)ref, sizeof(sub_match<iterator>) + sizeof(c_reference));
|
||||
throw;
|
||||
{
|
||||
c_alloc(a).deallocate((char*)(void*)ref, sizeof(sub_match<iterator>) + sizeof(c_reference));
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class iterator, class Allocator>
|
||||
@ -1148,25 +1166,30 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_typ
|
||||
if(ref->cmatches != n)
|
||||
{
|
||||
c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match<iterator>) * n + sizeof(c_reference));
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
new (newref) c_reference(*ref);
|
||||
newref->count = 1;
|
||||
newref->cmatches = n;
|
||||
sub_match<iterator>* p1, *p2;
|
||||
p1 = (sub_match<iterator>*)(newref+1);
|
||||
p2 = p1 + newref->cmatches;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
while(p1 != p2)
|
||||
{
|
||||
new (p1) sub_match<iterator>();
|
||||
++p1;
|
||||
}
|
||||
m_free();
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
{
|
||||
p2 = (sub_match<iterator>*)(newref+1);
|
||||
while(p2 != p1)
|
||||
{
|
||||
@ -1174,15 +1197,18 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_typ
|
||||
++p2;
|
||||
}
|
||||
::boost::re_detail::pointer_destroy(ref);
|
||||
throw;
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
ref = newref;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * n + sizeof(c_reference));
|
||||
throw;
|
||||
{
|
||||
ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * n + sizeof(c_reference));
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -1192,20 +1218,25 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_typ
|
||||
if(ref->cmatches != n)
|
||||
{
|
||||
c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match<iterator>) * n + sizeof(c_reference));;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try{
|
||||
#endif
|
||||
new (newref) c_reference(*ref);
|
||||
newref->count = 1;
|
||||
newref->cmatches = n;
|
||||
sub_match<iterator>* p1 = (sub_match<iterator>*)(newref+1);
|
||||
sub_match<iterator>* p2 = p1 + newref->cmatches;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
while(p1 != p2)
|
||||
{
|
||||
new (p1) sub_match<iterator>(j);
|
||||
++p1;
|
||||
}
|
||||
m_free();
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@ -1218,13 +1249,16 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_typ
|
||||
::boost::re_detail::pointer_destroy(ref);
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
ref = newref;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * n + sizeof(c_reference));
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1298,19 +1332,24 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::cow()
|
||||
if(ref->count > 1)
|
||||
{
|
||||
c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match<iterator>) * ref->cmatches + sizeof(c_reference));
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try{
|
||||
#endif
|
||||
new (newref) c_reference(*ref);
|
||||
newref->count = 1;
|
||||
sub_match<iterator>* p1 = (sub_match<iterator>*)(newref+1);
|
||||
sub_match<iterator>* p2 = p1 + newref->cmatches;
|
||||
sub_match<iterator>* p3 = (sub_match<iterator>*)(ref+1);
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try{
|
||||
#endif
|
||||
while(p1 != p2)
|
||||
{
|
||||
new (p1) sub_match<iterator>(*p3);
|
||||
++p1;
|
||||
++p3;
|
||||
}
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@ -1323,14 +1362,17 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::cow()
|
||||
::boost::re_detail::pointer_destroy(ref);
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
--(ref->count);
|
||||
ref = newref;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * ref->cmatches + sizeof(c_reference));
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -1418,19 +1460,24 @@ match_results<iterator, Allocator>::match_results(const match_results<iterator,
|
||||
reinterpret_cast<typename re_detail::match_results_base<iterator, Allocator>::c_reference *>
|
||||
(m.ref->allocate(sizeof(sub_match<iterator>) * m.ref->cmatches +
|
||||
sizeof(typename re_detail::match_results_base<iterator, Allocator>::c_reference)));
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try{
|
||||
#endif
|
||||
new (this->ref) typename re_detail::match_results_base<iterator, Allocator>::c_reference(*m.ref);
|
||||
this->ref->count = 1;
|
||||
sub_match<iterator>* p1 = (sub_match<iterator>*)(this->ref+1);
|
||||
sub_match<iterator>* p2 = p1 + this->ref->cmatches;
|
||||
sub_match<iterator>* p3 = (sub_match<iterator>*)(m.ref+1);
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try{
|
||||
#endif
|
||||
while(p1 != p2)
|
||||
{
|
||||
new (p1) sub_match<iterator>(*p3);
|
||||
++p1;
|
||||
++p3;
|
||||
}
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@ -1449,6 +1496,7 @@ match_results<iterator, Allocator>::match_results(const match_results<iterator,
|
||||
m.ref->deallocate((char*)(void*)this->ref, sizeof(sub_match<iterator>) * m.ref->cmatches + sizeof(typename re_detail::match_results_base<iterator, Allocator>::c_reference));
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class iterator, class Allocator>
|
||||
|
@ -273,6 +273,35 @@ using std::distance;
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Error Handling for exception free compilers:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef BOOST_NO_EXCEPTIONS
|
||||
//
|
||||
// If there are no exceptions then we must report critical-errors
|
||||
// the only way we know how; by terminating.
|
||||
//
|
||||
#ifdef __BORLANDC__
|
||||
// <cstdio> seems not to make stderr usable with Borland:
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
# define BOOST_REGEX_NOEH_ASSERT(x)\
|
||||
if(0 == (x))\
|
||||
{\
|
||||
std::fprintf(stderr, "Error: critical regex++ failure in \"%s\"", #x);\
|
||||
std::abort();\
|
||||
}
|
||||
#else
|
||||
//
|
||||
// With exceptions then error handling is taken care of and
|
||||
// there is no need for these checks:
|
||||
//
|
||||
# define BOOST_REGEX_NOEH_ASSERT(x)
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Debugging / tracing support:
|
||||
@ -516,6 +545,10 @@ namespace std{
|
||||
using ::fopen;
|
||||
using ::fclose;
|
||||
using ::FILE;
|
||||
#ifdef BOOST_NO_EXCEPTIONS
|
||||
using ::fprintf;
|
||||
using ::abort;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1167,8 +1167,10 @@ void BOOST_REGEX_CALL reg_expression<charT, traits, Allocator>::fixup_apply(re_d
|
||||
register re_detail::re_syntax_base* ptr = b;
|
||||
bool* pb = 0;
|
||||
b_alloc a(data.allocator());
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
pb = a.allocate(cbraces);
|
||||
for(unsigned i = 0; i < cbraces; ++i)
|
||||
pb[i] = false;
|
||||
@ -1232,6 +1234,7 @@ void BOOST_REGEX_CALL reg_expression<charT, traits, Allocator>::fixup_apply(re_d
|
||||
}
|
||||
a.deallocate(pb, cbraces);
|
||||
pb = 0;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@ -1239,6 +1242,7 @@ void BOOST_REGEX_CALL reg_expression<charT, traits, Allocator>::fixup_apply(re_d
|
||||
a.deallocate(pb, cbraces);
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -2053,10 +2057,12 @@ void BOOST_REGEX_CALL reg_expression<charT, traits, Allocator>::fail(unsigned in
|
||||
if(err)
|
||||
{
|
||||
_flags |= regbase::failbit;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
if(_flags & regbase::use_except)
|
||||
{
|
||||
throw bad_expression(traits_inst.error_string(err));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
_flags &= ~regbase::failbit;
|
||||
|
Reference in New Issue
Block a user