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