forked from boostorg/regex
1) Disabled recursive implementation for VC8: stack overflows can't be reliably detected unless the whole program is compiled with asynchronous exceptions.
2) Changed std::copy calls on VC8 to avoid "dangerous code" warnings. 3) Moved backreference and octal escape code into line with POSIX-extended requirements. 4) Changed match_results leftmost-longest rules to stop unnecessary std::distance computations (an optimisation for non-random access iterators). 5) Changed C lib calls to use "safe" versions of string API's where available. 6) Added many new POSIX-extended leftmost-longest tests, to verify the above. [SVN r27880]
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2004
|
||||
* Copyright (c) 1998-2005
|
||||
* John Maddock
|
||||
*
|
||||
* Use, modification and distribution are subject to the
|
||||
@ -43,6 +43,12 @@
|
||||
# include <locale>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std{
|
||||
using ::sprintf; using ::strcpy; using ::strcat; using ::strlen;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace re_detail{
|
||||
#ifdef BOOST_NO_STD_DISTANCE
|
||||
template <class T>
|
||||
@ -112,4 +118,73 @@ inline void pointer_construct(T* p, const T& t)
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* helper function copy:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace boost{ namespace re_detail{
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC,>=1400)
|
||||
//
|
||||
// MSVC 8 will either emit warnings or else refuse to compile
|
||||
// code that makes perfectly legitimate use of std::copy, when
|
||||
// the OutputIterator type is a user-defined class (apparently all user
|
||||
// defined iterators are "unsafe"). This code works around that:
|
||||
//
|
||||
template<class InputIterator, class OutputIterator>
|
||||
inline OutputIterator copy(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
OutputIterator dest
|
||||
)
|
||||
{
|
||||
return stdext::unchecked_copy(first, last, dest);
|
||||
}
|
||||
|
||||
// use safe versions of strcpy etc:
|
||||
using ::strcpy_s;
|
||||
using ::strcat_s;
|
||||
#else
|
||||
using std::copy;
|
||||
|
||||
inline std::size_t strcpy_s(
|
||||
char *strDestination,
|
||||
std::size_t sizeInBytes,
|
||||
const char *strSource
|
||||
)
|
||||
{
|
||||
if(std::strlen(strSource)+1 > sizeInBytes)
|
||||
return 1;
|
||||
std::strcpy(strDestination, strSource);
|
||||
return 0;
|
||||
}
|
||||
inline std::size_t strcat_s(
|
||||
char *strDestination,
|
||||
std::size_t sizeInBytes,
|
||||
const char *strSource
|
||||
)
|
||||
{
|
||||
if(std::strlen(strSource) + std::strlen(strDestination) + 1 > sizeInBytes)
|
||||
return 1;
|
||||
std::strcat(strDestination, strSource);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline void overflow_error_if_not_zero(std::size_t i)
|
||||
{
|
||||
if(i)
|
||||
{
|
||||
std::overflow_error e("String buffer too small");
|
||||
boost::throw_exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
||||
|
||||
#endif // include guard
|
||||
|
||||
|
Reference in New Issue
Block a user