| 1 | /* |
|---|
| 2 | * |
|---|
| 3 | * Copyright (c) 1998-2005 |
|---|
| 4 | * John Maddock |
|---|
| 5 | * |
|---|
| 6 | * Use, modification and distribution are subject to the |
|---|
| 7 | * Boost Software License, Version 1.0. (See accompanying file |
|---|
| 8 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 9 | * |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | /* |
|---|
| 13 | * LOCATION: see http://www.boost.org for most recent version. |
|---|
| 14 | * FILE regex_workarounds.cpp |
|---|
| 15 | * VERSION see <boost/version.hpp> |
|---|
| 16 | * DESCRIPTION: Declares Misc workarounds. |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | #ifndef BOOST_REGEX_WORKAROUND_HPP |
|---|
| 20 | #define BOOST_REGEX_WORKAROUND_HPP |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #include <new> |
|---|
| 24 | #include <cstring> |
|---|
| 25 | #include <cstdlib> |
|---|
| 26 | #include <cstddef> |
|---|
| 27 | #include <cassert> |
|---|
| 28 | #include <cstdio> |
|---|
| 29 | #include <string> |
|---|
| 30 | #include <stdexcept> |
|---|
| 31 | #include <iterator> |
|---|
| 32 | #include <algorithm> |
|---|
| 33 | #include <iosfwd> |
|---|
| 34 | #include <vector> |
|---|
| 35 | #include <map> |
|---|
| 36 | #include <boost/limits.hpp> |
|---|
| 37 | #include <boost/assert.hpp> |
|---|
| 38 | #include <boost/cstdint.hpp> |
|---|
| 39 | #include <boost/throw_exception.hpp> |
|---|
| 40 | #include <boost/scoped_ptr.hpp> |
|---|
| 41 | #include <boost/scoped_array.hpp> |
|---|
| 42 | #include <boost/shared_ptr.hpp> |
|---|
| 43 | #include <boost/mpl/bool_fwd.hpp> |
|---|
| 44 | #ifndef BOOST_NO_STD_LOCALE |
|---|
| 45 | # include <locale> |
|---|
| 46 | #endif |
|---|
| 47 | |
|---|
| 48 | #if defined(BOOST_NO_STDC_NAMESPACE) |
|---|
| 49 | namespace std{ |
|---|
| 50 | using ::sprintf; using ::strcpy; using ::strcat; using ::strlen; |
|---|
| 51 | } |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | namespace boost{ namespace re_detail{ |
|---|
| 55 | #ifdef BOOST_NO_STD_DISTANCE |
|---|
| 56 | template <class T> |
|---|
| 57 | std::ptrdiff_t distance(const T& x, const T& y) |
|---|
| 58 | { return y - x; } |
|---|
| 59 | #else |
|---|
| 60 | using std::distance; |
|---|
| 61 | #endif |
|---|
| 62 | }} |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | #ifdef BOOST_REGEX_NO_BOOL |
|---|
| 66 | # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>((x) ? true : false) |
|---|
| 67 | #else |
|---|
| 68 | # ifdef BOOST_MSVC |
|---|
| 69 | // warning suppression with VC6: |
|---|
| 70 | # pragma warning(disable: 4800) |
|---|
| 71 | # pragma warning(disable: 4786) |
|---|
| 72 | # endif |
|---|
| 73 | # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>(x) |
|---|
| 74 | #endif |
|---|
| 75 | |
|---|
| 76 | /***************************************************************************** |
|---|
| 77 | * |
|---|
| 78 | * Fix broken broken namespace support: |
|---|
| 79 | * |
|---|
| 80 | ****************************************************************************/ |
|---|
| 81 | |
|---|
| 82 | #if defined(BOOST_NO_STDC_NAMESPACE) && defined(__cplusplus) |
|---|
| 83 | |
|---|
| 84 | namespace std{ |
|---|
| 85 | using ::ptrdiff_t; |
|---|
| 86 | using ::size_t; |
|---|
| 87 | using ::abs; |
|---|
| 88 | using ::memset; |
|---|
| 89 | using ::memcpy; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | #endif |
|---|
| 93 | |
|---|
| 94 | /***************************************************************************** |
|---|
| 95 | * |
|---|
| 96 | * helper functions pointer_construct/pointer_destroy: |
|---|
| 97 | * |
|---|
| 98 | ****************************************************************************/ |
|---|
| 99 | |
|---|
| 100 | #ifdef __cplusplus |
|---|
| 101 | namespace boost{ namespace re_detail{ |
|---|
| 102 | |
|---|
| 103 | #ifdef BOOST_MSVC |
|---|
| 104 | #pragma warning (push) |
|---|
| 105 | #pragma warning (disable : 4100) |
|---|
| 106 | #endif |
|---|
| 107 | |
|---|
| 108 | template <class T> |
|---|
| 109 | inline void pointer_destroy(T* p) |
|---|
| 110 | { p->~T(); (void)p; } |
|---|
| 111 | |
|---|
| 112 | #ifdef BOOST_MSVC |
|---|
| 113 | #pragma warning (pop) |
|---|
| 114 | #endif |
|---|
| 115 | |
|---|
| 116 | template <class T> |
|---|
| 117 | inline void pointer_construct(T* p, const T& t) |
|---|
| 118 | { new (p) T(t); } |
|---|
| 119 | |
|---|
| 120 | }} // namespaces |
|---|
| 121 | #endif |
|---|
| 122 | |
|---|
| 123 | /***************************************************************************** |
|---|
| 124 | * |
|---|
| 125 | * helper function copy: |
|---|
| 126 | * |
|---|
| 127 | ****************************************************************************/ |
|---|
| 128 | |
|---|
| 129 | #ifdef __cplusplus |
|---|
| 130 | namespace boost{ namespace re_detail{ |
|---|
| 131 | #if BOOST_WORKAROUND(BOOST_MSVC,>=1400) && defined(_CPPLIB_VER) && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) |
|---|
| 132 | // |
|---|
| 133 | // MSVC 8 will either emit warnings or else refuse to compile |
|---|
| 134 | // code that makes perfectly legitimate use of std::copy, when |
|---|
| 135 | // the OutputIterator type is a user-defined class (apparently all user |
|---|
| 136 | // defined iterators are "unsafe"). This code works around that: |
|---|
| 137 | // |
|---|
| 138 | template<class InputIterator, class OutputIterator> |
|---|
| 139 | inline OutputIterator copy( |
|---|
| 140 | InputIterator first, |
|---|
| 141 | InputIterator last, |
|---|
| 142 | OutputIterator dest |
|---|
| 143 | ) |
|---|
| 144 | { |
|---|
| 145 | return stdext::unchecked_copy(first, last, dest); |
|---|
| 146 | } |
|---|
| 147 | template<class InputIterator1, class InputIterator2> |
|---|
| 148 | inline bool equal( |
|---|
| 149 | InputIterator1 first, |
|---|
| 150 | InputIterator1 last, |
|---|
| 151 | InputIterator2 with |
|---|
| 152 | ) |
|---|
| 153 | { |
|---|
| 154 | return stdext::unchecked_equal(first, last, with); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | // use safe versions of strcpy etc: |
|---|
| 158 | using ::strcpy_s; |
|---|
| 159 | using ::strcat_s; |
|---|
| 160 | #else |
|---|
| 161 | using std::copy; |
|---|
| 162 | using std::equal; |
|---|
| 163 | |
|---|
| 164 | inline std::size_t strcpy_s( |
|---|
| 165 | char *strDestination, |
|---|
| 166 | std::size_t sizeInBytes, |
|---|
| 167 | const char *strSource |
|---|
| 168 | ) |
|---|
| 169 | { |
|---|
| 170 | if(std::strlen(strSource)+1 > sizeInBytes) |
|---|
| 171 | return 1; |
|---|
| 172 | std::strcpy(strDestination, strSource); |
|---|
| 173 | return 0; |
|---|
| 174 | } |
|---|
| 175 | inline std::size_t strcat_s( |
|---|
| 176 | char *strDestination, |
|---|
| 177 | std::size_t sizeInBytes, |
|---|
| 178 | const char *strSource |
|---|
| 179 | ) |
|---|
| 180 | { |
|---|
| 181 | if(std::strlen(strSource) + std::strlen(strDestination) + 1 > sizeInBytes) |
|---|
| 182 | return 1; |
|---|
| 183 | std::strcat(strDestination, strSource); |
|---|
| 184 | return 0; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | #endif |
|---|
| 188 | |
|---|
| 189 | inline void overflow_error_if_not_zero(std::size_t i) |
|---|
| 190 | { |
|---|
| 191 | if(i) |
|---|
| 192 | { |
|---|
| 193 | std::overflow_error e("String buffer too small"); |
|---|
| 194 | boost::throw_exception(e); |
|---|
| 195 | } |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | }} // namespaces |
|---|
| 199 | #endif |
|---|
| 200 | |
|---|
| 201 | #endif // include guard |
|---|
| 202 | |
|---|