sclang: ServerShmInterface - avoid object duplication in deepCopy
[supercollider.git] / external_libraries / boost / libs / regex / src / wc_regex_traits.cpp
blobb3d2c5a2c7ffcead84a83fac6167894237070e37
1 /*
3 * Copyright (c) 2004
4 * John Maddock
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)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE: wc_regex_traits.cpp
15 * VERSION: see <boost/version.hpp>
16 * DESCRIPTION: Implements out of line members for c_regex_traits<wchar_t>
20 #define BOOST_REGEX_SOURCE
22 #include <boost/detail/workaround.hpp>
23 #include <memory>
24 #include <string>
25 #include "internals.hpp"
27 #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) && defined(_NATIVE_WCHAR_T_DEFINED) \
28 && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) || defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER))\
29 && BOOST_WORKAROUND(BOOST_MSVC, <1600)
31 // This is a horrible workaround, but without declaring these symbols extern we get
32 // duplicate symbol errors when linking if the application is built without
33 // /Zc:wchar_t
35 #ifdef _CRTIMP2_PURE
36 # define BOOST_REGEX_STDLIB_DECL _CRTIMP2_PURE
37 #else
38 # define BOOST_REGEX_STDLIB_DECL _CRTIMP2
39 #endif
41 namespace std{
43 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
44 template class BOOST_REGEX_STDLIB_DECL allocator<unsigned short>;
45 template class BOOST_REGEX_STDLIB_DECL _String_val<unsigned short, allocator<unsigned short> >;
46 template class BOOST_REGEX_STDLIB_DECL basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >;
47 #endif
49 #if BOOST_WORKAROUND(BOOST_MSVC, > 1300) && BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400))
50 template<> BOOST_REGEX_STDLIB_DECL std::size_t __cdecl char_traits<unsigned short>::length(unsigned short const*);
51 #endif
53 template BOOST_REGEX_STDLIB_DECL bool __cdecl operator==(
54 const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
55 const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
56 template BOOST_REGEX_STDLIB_DECL bool __cdecl operator==(
57 const unsigned short *,
58 const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
59 template BOOST_REGEX_STDLIB_DECL bool __cdecl operator==(
60 const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
61 const unsigned short *);
62 template BOOST_REGEX_STDLIB_DECL bool __cdecl operator<(
63 const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
64 const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
65 template BOOST_REGEX_STDLIB_DECL bool __cdecl operator>(
66 const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
67 const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
69 #endif
71 #include <boost/regex/config.hpp>
72 #include <boost/detail/workaround.hpp>
74 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x560)
76 #include <boost/regex/v4/c_regex_traits.hpp>
77 #ifndef BOOST_NO_WREGEX
78 #include <boost/regex/v4/primary_transform.hpp>
79 #include <boost/regex/v4/regex_traits_defaults.hpp>
81 #if defined(BOOST_NO_STDC_NAMESPACE)
82 namespace std{
83 using ::wcstol;
85 #endif
87 namespace boost{
89 c_regex_traits<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::transform(const wchar_t* p1, const wchar_t* p2)
91 std::size_t r;
92 std::size_t s = 10;
93 std::wstring src(p1, p2);
94 std::wstring result(s, L' ');
95 while(s < (r = std::wcsxfrm(&*result.begin(), src.c_str(), s)))
97 result.append(r - s + 3, L' ');
98 s = result.size();
100 result.erase(r);
101 return result;
104 c_regex_traits<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::transform_primary(const wchar_t* p1, const wchar_t* p2)
106 static wchar_t s_delim;
107 static const int s_collate_type = ::boost::re_detail::find_sort_syntax(static_cast<const c_regex_traits<wchar_t>*>(0), &s_delim);
108 std::wstring result;
110 // What we do here depends upon the format of the sort key returned by
111 // sort key returned by this->transform:
113 switch(s_collate_type)
115 case ::boost::re_detail::sort_C:
116 case ::boost::re_detail::sort_unknown:
117 // the best we can do is translate to lower case, then get a regular sort key:
119 result.assign(p1, p2);
120 for(std::wstring::size_type i = 0; i < result.size(); ++i)
121 result[i] = (std::towlower)(result[i]);
122 result = c_regex_traits<wchar_t>::transform(&*result.begin(), &*result.begin() + result.size());
123 break;
125 case ::boost::re_detail::sort_fixed:
127 // get a regular sort key, and then truncate it:
128 result = c_regex_traits<wchar_t>::transform(&*result.begin(), &*result.begin() + result.size());
129 result.erase(s_delim);
130 break;
132 case ::boost::re_detail::sort_delim:
133 // get a regular sort key, and then truncate everything after the delim:
134 result = c_regex_traits<wchar_t>::transform(&*result.begin(), &*result.begin() + result.size());
135 if(result.size() && (result[0] == s_delim))
136 break;
137 std::size_t i;
138 for(i = 0; i < result.size(); ++i)
140 if(result[i] == s_delim)
141 break;
143 result.erase(i);
144 break;
146 if(result.empty())
147 result = std::wstring(1, char(0));
148 return result;
151 c_regex_traits<wchar_t>::char_class_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::lookup_classname(const wchar_t* p1, const wchar_t* p2)
153 static const char_class_type masks[] =
156 char_class_alnum,
157 char_class_alpha,
158 char_class_blank,
159 char_class_cntrl,
160 char_class_digit,
161 char_class_digit,
162 char_class_graph,
163 char_class_horizontal,
164 char_class_lower,
165 char_class_lower,
166 char_class_print,
167 char_class_punct,
168 char_class_space,
169 char_class_space,
170 char_class_upper,
171 char_class_unicode,
172 char_class_upper,
173 char_class_vertical,
174 char_class_alnum | char_class_word,
175 char_class_alnum | char_class_word,
176 char_class_xdigit,
179 int idx = ::boost::re_detail::get_default_class_id(p1, p2);
180 if(idx < 0)
182 std::wstring s(p1, p2);
183 for(std::wstring::size_type i = 0; i < s.size(); ++i)
184 s[i] = (std::towlower)(s[i]);
185 idx = ::boost::re_detail::get_default_class_id(&*s.begin(), &*s.begin() + s.size());
187 BOOST_ASSERT(idx+1 < static_cast<int>(sizeof(masks) / sizeof(masks[0])));
188 return masks[idx+1];
191 bool BOOST_REGEX_CALL c_regex_traits<wchar_t>::isctype(wchar_t c, char_class_type mask)
193 return
194 ((mask & char_class_space) && (std::iswspace)(c))
195 || ((mask & char_class_print) && (std::iswprint)(c))
196 || ((mask & char_class_cntrl) && (std::iswcntrl)(c))
197 || ((mask & char_class_upper) && (std::iswupper)(c))
198 || ((mask & char_class_lower) && (std::iswlower)(c))
199 || ((mask & char_class_alpha) && (std::iswalpha)(c))
200 || ((mask & char_class_digit) && (std::iswdigit)(c))
201 || ((mask & char_class_punct) && (std::iswpunct)(c))
202 || ((mask & char_class_xdigit) && (std::iswxdigit)(c))
203 || ((mask & char_class_blank) && (std::iswspace)(c) && !::boost::re_detail::is_separator(c))
204 || ((mask & char_class_word) && (c == '_'))
205 || ((mask & char_class_unicode) && (c & ~static_cast<wchar_t>(0xff)))
206 || ((mask & char_class_vertical) && (::boost::re_detail::is_separator(c) || (c == L'\v')))
207 || ((mask & char_class_horizontal) && (std::iswspace)(c) && !::boost::re_detail::is_separator(c) && (c != L'\v'));
210 c_regex_traits<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::lookup_collatename(const wchar_t* p1, const wchar_t* p2)
212 #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
213 && !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\
214 && !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)
215 std::string name(p1, p2);
216 #else
217 std::string name;
218 const wchar_t* p0 = p1;
219 while(p0 != p2)
220 name.append(1, char(*p0++));
221 #endif
222 name = ::boost::re_detail::lookup_default_collate_name(name);
223 #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
224 && !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\
225 && !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)
226 if(name.size())
227 return string_type(name.begin(), name.end());
228 #else
229 if(name.size())
231 string_type result;
232 typedef std::string::const_iterator iter;
233 iter b = name.begin();
234 iter e = name.end();
235 while(b != e)
236 result.append(1, wchar_t(*b++));
237 return result;
239 #endif
240 if(p2 - p1 == 1)
241 return string_type(1, *p1);
242 return string_type();
245 int BOOST_REGEX_CALL c_regex_traits<wchar_t>::value(wchar_t c, int radix)
247 #ifdef __BORLANDC__
248 // workaround for broken wcstol:
249 if((std::iswxdigit)(c) == 0)
250 return -1;
251 #endif
252 wchar_t b[2] = { c, '\0', };
253 wchar_t* ep;
254 int result = std::wcstol(b, &ep, radix);
255 if(ep == b)
256 return -1;
257 return result;
260 #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
261 c_regex_traits<unsigned short>::string_type BOOST_REGEX_CALL c_regex_traits<unsigned short>::transform(const unsigned short* p1, const unsigned short* p2)
263 std::wstring result = c_regex_traits<wchar_t>::transform((const wchar_t*)p1, (const wchar_t*)p2);
264 return string_type(result.begin(), result.end());
267 c_regex_traits<unsigned short>::string_type BOOST_REGEX_CALL c_regex_traits<unsigned short>::transform_primary(const unsigned short* p1, const unsigned short* p2)
269 std::wstring result = c_regex_traits<wchar_t>::transform_primary((const wchar_t*)p1, (const wchar_t*)p2);
270 return string_type(result.begin(), result.end());
273 c_regex_traits<unsigned short>::char_class_type BOOST_REGEX_CALL c_regex_traits<unsigned short>::lookup_classname(const unsigned short* p1, const unsigned short* p2)
275 return c_regex_traits<wchar_t>::lookup_classname((const wchar_t*)p1, (const wchar_t*)p2);
278 c_regex_traits<unsigned short>::string_type BOOST_REGEX_CALL c_regex_traits<unsigned short>::lookup_collatename(const unsigned short* p1, const unsigned short* p2)
280 std::wstring result = c_regex_traits<wchar_t>::lookup_collatename((const wchar_t*)p1, (const wchar_t*)p2);
281 return string_type(result.begin(), result.end());
284 bool BOOST_REGEX_CALL c_regex_traits<unsigned short>::isctype(unsigned short c, char_class_type m)
286 return c_regex_traits<wchar_t>::isctype(c, m);
289 int BOOST_REGEX_CALL c_regex_traits<unsigned short>::value(unsigned short c, int radix)
291 return c_regex_traits<wchar_t>::value(c, radix);
294 #endif
298 #endif // BOOST_NO_WREGEX
300 #endif // __BORLANDC__