]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/regex/v5/regex_workaround.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / regex / v5 / regex_workaround.hpp
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 #include <boost/regex/config.hpp>
23 #include <algorithm>
24 #include <stdexcept>
25 #include <cstring>
26
27 #ifndef BOOST_REGEX_STANDALONE
28 #include <boost/detail/workaround.hpp>
29 #include <boost/throw_exception.hpp>
30 #endif
31
32 #ifdef BOOST_REGEX_NO_BOOL
33 # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>((x) ? true : false)
34 #else
35 # define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>(x)
36 #endif
37
38 /*****************************************************************************
39 *
40 * helper functions pointer_construct/pointer_destroy:
41 *
42 ****************************************************************************/
43
44 #ifdef __cplusplus
45 namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
46
47 #ifdef BOOST_REGEX_MSVC
48 #pragma warning (push)
49 #pragma warning (disable : 4100)
50 #endif
51
52 template <class T>
53 inline void pointer_destroy(T* p)
54 { p->~T(); (void)p; }
55
56 #ifdef BOOST_REGEX_MSVC
57 #pragma warning (pop)
58 #endif
59
60 template <class T>
61 inline void pointer_construct(T* p, const T& t)
62 { new (p) T(t); }
63
64 }} // namespaces
65 #endif
66
67 /*****************************************************************************
68 *
69 * helper function copy:
70 *
71 ****************************************************************************/
72
73 #if defined(BOOST_WORKAROUND)
74 #if BOOST_WORKAROUND(BOOST_REGEX_MSVC, >= 1400) && defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__
75 #define BOOST_REGEX_HAS_STRCPY_S
76 #endif
77 #endif
78
79 #ifdef __cplusplus
80 namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
81
82 #if defined(BOOST_REGEX_MSVC) && (BOOST_REGEX_MSVC < 1910)
83 //
84 // MSVC 10 will either emit warnings or else refuse to compile
85 // code that makes perfectly legitimate use of std::copy, when
86 // the OutputIterator type is a user-defined class (apparently all user
87 // defined iterators are "unsafe"). What's more Microsoft have removed their
88 // non-standard "unchecked" versions, even though they are still in the MS
89 // documentation!! Work around this as best we can:
90 //
91 template<class InputIterator, class OutputIterator>
92 inline OutputIterator copy(
93 InputIterator first,
94 InputIterator last,
95 OutputIterator dest
96 )
97 {
98 while (first != last)
99 *dest++ = *first++;
100 return dest;
101 }
102 #else
103 using std::copy;
104 #endif
105
106
107 #if defined(BOOST_REGEX_HAS_STRCPY_S)
108
109 // use safe versions of strcpy etc:
110 using ::strcpy_s;
111 using ::strcat_s;
112 #else
113 inline std::size_t strcpy_s(
114 char *strDestination,
115 std::size_t sizeInBytes,
116 const char *strSource
117 )
118 {
119 std::size_t lenSourceWithNull = std::strlen(strSource) + 1;
120 if (lenSourceWithNull > sizeInBytes)
121 return 1;
122 std::memcpy(strDestination, strSource, lenSourceWithNull);
123 return 0;
124 }
125 inline std::size_t strcat_s(
126 char *strDestination,
127 std::size_t sizeInBytes,
128 const char *strSource
129 )
130 {
131 std::size_t lenSourceWithNull = std::strlen(strSource) + 1;
132 std::size_t lenDestination = std::strlen(strDestination);
133 if (lenSourceWithNull + lenDestination > sizeInBytes)
134 return 1;
135 std::memcpy(strDestination + lenDestination, strSource, lenSourceWithNull);
136 return 0;
137 }
138
139 #endif
140
141 inline void overflow_error_if_not_zero(std::size_t i)
142 {
143 if(i)
144 {
145 std::overflow_error e("String buffer too small");
146 #ifndef BOOST_REGEX_STANDALONE
147 boost::throw_exception(e);
148 #else
149 throw e;
150 #endif
151 }
152 }
153
154 }} // namespaces
155
156 #endif // __cplusplus
157
158 #endif // include guard
159