]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/regex/v5/icu.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / regex / v5 / icu.hpp
1 /*
2 *
3 * Copyright (c) 2004
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 icu.hpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Unicode regular expressions on top of the ICU Library.
17 */
18
19 #ifndef BOOST_REGEX_ICU_V5_HPP
20 #define BOOST_REGEX_ICU_V5_HPP
21
22 #include <unicode/utypes.h>
23 #include <unicode/uchar.h>
24 #include <unicode/coll.h>
25 #include <type_traits>
26 #include <functional>
27 #include <boost/regex.hpp>
28 #include <boost/regex/v5/unicode_iterator.hpp>
29
30 #ifdef BOOST_REGEX_MSVC
31 #pragma warning (push)
32 #pragma warning (disable: 4251)
33 #endif
34
35 namespace boost{
36
37 namespace BOOST_REGEX_DETAIL_NS{
38
39 //
40 // Implementation details:
41 //
42 class icu_regex_traits_implementation
43 {
44 typedef UChar32 char_type;
45 typedef std::size_t size_type;
46 typedef std::vector<char_type> string_type;
47 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
48 typedef std::uint_least32_t char_class_type;
49 public:
50 icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
51 : m_locale(l)
52 {
53 UErrorCode success = U_ZERO_ERROR;
54 m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
55 if(U_SUCCESS(success) == 0)
56 init_error();
57 m_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::IDENTICAL);
58 success = U_ZERO_ERROR;
59 m_primary_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
60 if(U_SUCCESS(success) == 0)
61 init_error();
62 m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
63 }
64 U_NAMESPACE_QUALIFIER Locale getloc()const
65 {
66 return m_locale;
67 }
68 string_type do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const
69 {
70 // TODO make thread safe!!!! :
71 typedef u32_to_u16_iterator<const char_type*, ::UChar> itt;
72 itt i(p1), j(p2);
73 std::vector< ::UChar> t(i, j);
74 std::uint8_t result[100];
75 std::int32_t len;
76 if (!t.empty())
77 len = pcoll->getSortKey(&*t.begin(), static_cast<std::int32_t>(t.size()), result, sizeof(result));
78 else
79 len = pcoll->getSortKey(static_cast<UChar const*>(0), static_cast<std::int32_t>(0), result, sizeof(result));
80 if (std::size_t(len) > sizeof(result))
81 {
82 std::unique_ptr< std::uint8_t[]> presult(new ::uint8_t[len + 1]);
83 if (!t.empty())
84 len = pcoll->getSortKey(&*t.begin(), static_cast<std::int32_t>(t.size()), presult.get(), len + 1);
85 else
86 len = pcoll->getSortKey(static_cast<UChar const*>(0), static_cast<std::int32_t>(0), presult.get(), len + 1);
87 if ((0 == presult[len - 1]) && (len > 1))
88 --len;
89 return string_type(presult.get(), presult.get() + len);
90 }
91 if ((0 == result[len - 1]) && (len > 1))
92 --len;
93 return string_type(result, result + len);
94 }
95 string_type transform(const char_type* p1, const char_type* p2) const
96 {
97 return do_transform(p1, p2, m_collator.get());
98 }
99 string_type transform_primary(const char_type* p1, const char_type* p2) const
100 {
101 return do_transform(p1, p2, m_primary_collator.get());
102 }
103 private:
104 void init_error()
105 {
106 std::runtime_error e("Could not initialize ICU resources");
107 #ifndef BOOST_REGEX_STANDALONE
108 boost::throw_exception(e);
109 #else
110 throw e;
111 #endif
112 }
113 U_NAMESPACE_QUALIFIER Locale m_locale; // The ICU locale that we're using
114 std::unique_ptr< U_NAMESPACE_QUALIFIER Collator> m_collator; // The full collation object
115 std::unique_ptr< U_NAMESPACE_QUALIFIER Collator> m_primary_collator; // The primary collation object
116 };
117 inline std::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
118 {
119 return std::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
120 }
121
122 }
123
124 class icu_regex_traits
125 {
126 public:
127 typedef UChar32 char_type;
128 typedef std::size_t size_type;
129 typedef std::vector<char_type> string_type;
130 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
131 typedef std::uint64_t char_class_type;
132
133 struct boost_extensions_tag{};
134
135 icu_regex_traits()
136 : m_pimpl(BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
137 {
138 }
139 static size_type length(const char_type* p)
140 {
141 size_type result = 0;
142 while (*p)
143 {
144 ++p;
145 ++result;
146 }
147 return result;
148 }
149
150 ::boost::regex_constants::syntax_type syntax_type(char_type c)const
151 {
152 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
153 }
154 ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
155 {
156 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
157 }
158 char_type translate(char_type c) const
159 {
160 return c;
161 }
162 char_type translate_nocase(char_type c) const
163 {
164 return ::u_foldCase(c, U_FOLD_CASE_DEFAULT);
165 }
166 char_type translate(char_type c, bool icase) const
167 {
168 return icase ? translate_nocase(c) : translate(c);
169 }
170 char_type tolower(char_type c) const
171 {
172 return ::u_tolower(c);
173 }
174 char_type toupper(char_type c) const
175 {
176 return ::u_toupper(c);
177 }
178 string_type transform(const char_type* p1, const char_type* p2) const
179 {
180 return m_pimpl->transform(p1, p2);
181 }
182 string_type transform_primary(const char_type* p1, const char_type* p2) const
183 {
184 return m_pimpl->transform_primary(p1, p2);
185 }
186 char_class_type lookup_classname(const char_type* p1, const char_type* p2) const
187 {
188 constexpr char_class_type mask_blank = char_class_type(1) << offset_blank;
189 constexpr char_class_type mask_space = char_class_type(1) << offset_space;
190 constexpr char_class_type mask_xdigit = char_class_type(1) << offset_xdigit;
191 constexpr char_class_type mask_underscore = char_class_type(1) << offset_underscore;
192 constexpr char_class_type mask_unicode = char_class_type(1) << offset_unicode;
193 constexpr char_class_type mask_any = char_class_type(1) << offset_any;
194 constexpr char_class_type mask_ascii = char_class_type(1) << offset_ascii;
195 constexpr char_class_type mask_horizontal = char_class_type(1) << offset_horizontal;
196 constexpr char_class_type mask_vertical = char_class_type(1) << offset_vertical;
197
198 static const char_class_type masks[] =
199 {
200 0,
201 U_GC_L_MASK | U_GC_ND_MASK,
202 U_GC_L_MASK,
203 mask_blank,
204 U_GC_CC_MASK | U_GC_CF_MASK | U_GC_ZL_MASK | U_GC_ZP_MASK,
205 U_GC_ND_MASK,
206 U_GC_ND_MASK,
207 (0x3FFFFFFFu) & ~(U_GC_CC_MASK | U_GC_CF_MASK | U_GC_CS_MASK | U_GC_CN_MASK | U_GC_Z_MASK),
208 mask_horizontal,
209 U_GC_LL_MASK,
210 U_GC_LL_MASK,
211 ~(U_GC_C_MASK),
212 U_GC_P_MASK,
213 char_class_type(U_GC_Z_MASK) | mask_space,
214 char_class_type(U_GC_Z_MASK) | mask_space,
215 U_GC_LU_MASK,
216 mask_unicode,
217 U_GC_LU_MASK,
218 mask_vertical,
219 char_class_type(U_GC_L_MASK | U_GC_ND_MASK | U_GC_MN_MASK) | mask_underscore,
220 char_class_type(U_GC_L_MASK | U_GC_ND_MASK | U_GC_MN_MASK) | mask_underscore,
221 char_class_type(U_GC_ND_MASK) | mask_xdigit,
222 };
223
224 int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2);
225 if (idx >= 0)
226 return masks[idx + 1];
227 char_class_type result = lookup_icu_mask(p1, p2);
228 if (result != 0)
229 return result;
230
231 if (idx < 0)
232 {
233 string_type s(p1, p2);
234 string_type::size_type i = 0;
235 while (i < s.size())
236 {
237 s[i] = static_cast<char>((::u_tolower)(s[i]));
238 if (::u_isspace(s[i]) || (s[i] == '-') || (s[i] == '_'))
239 s.erase(s.begin() + i, s.begin() + i + 1);
240 else
241 {
242 s[i] = static_cast<char>((::u_tolower)(s[i]));
243 ++i;
244 }
245 }
246 if (!s.empty())
247 idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size());
248 if (idx >= 0)
249 return masks[idx + 1];
250 if (!s.empty())
251 result = lookup_icu_mask(&*s.begin(), &*s.begin() + s.size());
252 if (result != 0)
253 return result;
254 }
255 BOOST_REGEX_ASSERT(std::size_t(idx + 1) < sizeof(masks) / sizeof(masks[0]));
256 return masks[idx + 1];
257 }
258 string_type lookup_collatename(const char_type* p1, const char_type* p2) const
259 {
260 string_type result;
261 if (std::find_if(p1, p2, std::bind(std::greater< ::UChar32>(), std::placeholders::_1, 0x7f)) == p2)
262 {
263 std::string s(p1, p2);
264 // Try Unicode name:
265 UErrorCode err = U_ZERO_ERROR;
266 UChar32 c = ::u_charFromName(U_UNICODE_CHAR_NAME, s.c_str(), &err);
267 if (U_SUCCESS(err))
268 {
269 result.push_back(c);
270 return result;
271 }
272 // Try Unicode-extended name:
273 err = U_ZERO_ERROR;
274 c = ::u_charFromName(U_EXTENDED_CHAR_NAME, s.c_str(), &err);
275 if (U_SUCCESS(err))
276 {
277 result.push_back(c);
278 return result;
279 }
280 // try POSIX name:
281 s = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(s);
282 result.assign(s.begin(), s.end());
283 }
284 if (result.empty() && (p2 - p1 == 1))
285 result.push_back(*p1);
286 return result;
287 }
288 bool isctype(char_type c, char_class_type f) const
289 {
290 constexpr char_class_type mask_blank = char_class_type(1) << offset_blank;
291 constexpr char_class_type mask_space = char_class_type(1) << offset_space;
292 constexpr char_class_type mask_xdigit = char_class_type(1) << offset_xdigit;
293 constexpr char_class_type mask_underscore = char_class_type(1) << offset_underscore;
294 constexpr char_class_type mask_unicode = char_class_type(1) << offset_unicode;
295 constexpr char_class_type mask_any = char_class_type(1) << offset_any;
296 constexpr char_class_type mask_ascii = char_class_type(1) << offset_ascii;
297 constexpr char_class_type mask_horizontal = char_class_type(1) << offset_horizontal;
298 constexpr char_class_type mask_vertical = char_class_type(1) << offset_vertical;
299
300 // check for standard catagories first:
301 char_class_type m = char_class_type(static_cast<char_class_type>(1) << u_charType(c));
302 if ((m & f) != 0)
303 return true;
304 // now check for special cases:
305 if (((f & mask_blank) != 0) && u_isblank(c))
306 return true;
307 if (((f & mask_space) != 0) && u_isspace(c))
308 return true;
309 if (((f & mask_xdigit) != 0) && (u_digit(c, 16) >= 0))
310 return true;
311 if (((f & mask_unicode) != 0) && (c >= 0x100))
312 return true;
313 if (((f & mask_underscore) != 0) && (c == '_'))
314 return true;
315 if (((f & mask_any) != 0) && (c <= 0x10FFFF))
316 return true;
317 if (((f & mask_ascii) != 0) && (c <= 0x7F))
318 return true;
319 if (((f & mask_vertical) != 0) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == static_cast<char_type>('\v')) || (m == U_GC_ZL_MASK) || (m == U_GC_ZP_MASK)))
320 return true;
321 if (((f & mask_horizontal) != 0) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && u_isspace(c) && (c != static_cast<char_type>('\v')))
322 return true;
323 return false;
324 }
325 std::intmax_t toi(const char_type*& p1, const char_type* p2, int radix)const
326 {
327 return BOOST_REGEX_DETAIL_NS::global_toi(p1, p2, radix, *this);
328 }
329 int value(char_type c, int radix)const
330 {
331 return u_digit(c, static_cast< std::int8_t>(radix));
332 }
333 locale_type imbue(locale_type l)
334 {
335 locale_type result(m_pimpl->getloc());
336 m_pimpl = BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(l);
337 return result;
338 }
339 locale_type getloc()const
340 {
341 return locale_type();
342 }
343 std::string error_string(::boost::regex_constants::error_type n) const
344 {
345 return BOOST_REGEX_DETAIL_NS::get_default_error_string(n);
346 }
347 private:
348 icu_regex_traits(const icu_regex_traits&);
349 icu_regex_traits& operator=(const icu_regex_traits&);
350
351 //
352 // define the bitmasks offsets we need for additional character properties:
353 //
354 enum{
355 offset_blank = U_CHAR_CATEGORY_COUNT,
356 offset_space = U_CHAR_CATEGORY_COUNT+1,
357 offset_xdigit = U_CHAR_CATEGORY_COUNT+2,
358 offset_underscore = U_CHAR_CATEGORY_COUNT+3,
359 offset_unicode = U_CHAR_CATEGORY_COUNT+4,
360 offset_any = U_CHAR_CATEGORY_COUNT+5,
361 offset_ascii = U_CHAR_CATEGORY_COUNT+6,
362 offset_horizontal = U_CHAR_CATEGORY_COUNT+7,
363 offset_vertical = U_CHAR_CATEGORY_COUNT+8
364 };
365
366 static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2)
367 {
368 constexpr char_class_type mask_blank = char_class_type(1) << offset_blank;
369 constexpr char_class_type mask_space = char_class_type(1) << offset_space;
370 constexpr char_class_type mask_xdigit = char_class_type(1) << offset_xdigit;
371 constexpr char_class_type mask_underscore = char_class_type(1) << offset_underscore;
372 constexpr char_class_type mask_unicode = char_class_type(1) << offset_unicode;
373 constexpr char_class_type mask_any = char_class_type(1) << offset_any;
374 constexpr char_class_type mask_ascii = char_class_type(1) << offset_ascii;
375 constexpr char_class_type mask_horizontal = char_class_type(1) << offset_horizontal;
376 constexpr char_class_type mask_vertical = char_class_type(1) << offset_vertical;
377
378 static const ::UChar32 prop_name_table[] = {
379 /* any */ 'a', 'n', 'y',
380 /* ascii */ 'a', 's', 'c', 'i', 'i',
381 /* assigned */ 'a', 's', 's', 'i', 'g', 'n', 'e', 'd',
382 /* c* */ 'c', '*',
383 /* cc */ 'c', 'c',
384 /* cf */ 'c', 'f',
385 /* closepunctuation */ 'c', 'l', 'o', 's', 'e', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
386 /* cn */ 'c', 'n',
387 /* co */ 'c', 'o',
388 /* connectorpunctuation */ 'c', 'o', 'n', 'n', 'e', 'c', 't', 'o', 'r', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
389 /* control */ 'c', 'o', 'n', 't', 'r', 'o', 'l',
390 /* cs */ 'c', 's',
391 /* currencysymbol */ 'c', 'u', 'r', 'r', 'e', 'n', 'c', 'y', 's', 'y', 'm', 'b', 'o', 'l',
392 /* dashpunctuation */ 'd', 'a', 's', 'h', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
393 /* decimaldigitnumber */ 'd', 'e', 'c', 'i', 'm', 'a', 'l', 'd', 'i', 'g', 'i', 't', 'n', 'u', 'm', 'b', 'e', 'r',
394 /* enclosingmark */ 'e', 'n', 'c', 'l', 'o', 's', 'i', 'n', 'g', 'm', 'a', 'r', 'k',
395 /* finalpunctuation */ 'f', 'i', 'n', 'a', 'l', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
396 /* format */ 'f', 'o', 'r', 'm', 'a', 't',
397 /* initialpunctuation */ 'i', 'n', 'i', 't', 'i', 'a', 'l', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
398 /* l* */ 'l', '*',
399 /* letter */ 'l', 'e', 't', 't', 'e', 'r',
400 /* letternumber */ 'l', 'e', 't', 't', 'e', 'r', 'n', 'u', 'm', 'b', 'e', 'r',
401 /* lineseparator */ 'l', 'i', 'n', 'e', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
402 /* ll */ 'l', 'l',
403 /* lm */ 'l', 'm',
404 /* lo */ 'l', 'o',
405 /* lowercaseletter */ 'l', 'o', 'w', 'e', 'r', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
406 /* lt */ 'l', 't',
407 /* lu */ 'l', 'u',
408 /* m* */ 'm', '*',
409 /* mark */ 'm', 'a', 'r', 'k',
410 /* mathsymbol */ 'm', 'a', 't', 'h', 's', 'y', 'm', 'b', 'o', 'l',
411 /* mc */ 'm', 'c',
412 /* me */ 'm', 'e',
413 /* mn */ 'm', 'n',
414 /* modifierletter */ 'm', 'o', 'd', 'i', 'f', 'i', 'e', 'r', 'l', 'e', 't', 't', 'e', 'r',
415 /* modifiersymbol */ 'm', 'o', 'd', 'i', 'f', 'i', 'e', 'r', 's', 'y', 'm', 'b', 'o', 'l',
416 /* n* */ 'n', '*',
417 /* nd */ 'n', 'd',
418 /* nl */ 'n', 'l',
419 /* no */ 'n', 'o',
420 /* nonspacingmark */ 'n', 'o', 'n', 's', 'p', 'a', 'c', 'i', 'n', 'g', 'm', 'a', 'r', 'k',
421 /* notassigned */ 'n', 'o', 't', 'a', 's', 's', 'i', 'g', 'n', 'e', 'd',
422 /* number */ 'n', 'u', 'm', 'b', 'e', 'r',
423 /* openpunctuation */ 'o', 'p', 'e', 'n', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
424 /* other */ 'o', 't', 'h', 'e', 'r',
425 /* otherletter */ 'o', 't', 'h', 'e', 'r', 'l', 'e', 't', 't', 'e', 'r',
426 /* othernumber */ 'o', 't', 'h', 'e', 'r', 'n', 'u', 'm', 'b', 'e', 'r',
427 /* otherpunctuation */ 'o', 't', 'h', 'e', 'r', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
428 /* othersymbol */ 'o', 't', 'h', 'e', 'r', 's', 'y', 'm', 'b', 'o', 'l',
429 /* p* */ 'p', '*',
430 /* paragraphseparator */ 'p', 'a', 'r', 'a', 'g', 'r', 'a', 'p', 'h', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
431 /* pc */ 'p', 'c',
432 /* pd */ 'p', 'd',
433 /* pe */ 'p', 'e',
434 /* pf */ 'p', 'f',
435 /* pi */ 'p', 'i',
436 /* po */ 'p', 'o',
437 /* privateuse */ 'p', 'r', 'i', 'v', 'a', 't', 'e', 'u', 's', 'e',
438 /* ps */ 'p', 's',
439 /* punctuation */ 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
440 /* s* */ 's', '*',
441 /* sc */ 's', 'c',
442 /* separator */ 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
443 /* sk */ 's', 'k',
444 /* sm */ 's', 'm',
445 /* so */ 's', 'o',
446 /* spaceseparator */ 's', 'p', 'a', 'c', 'e', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
447 /* spacingcombiningmark */ 's', 'p', 'a', 'c', 'i', 'n', 'g', 'c', 'o', 'm', 'b', 'i', 'n', 'i', 'n', 'g', 'm', 'a', 'r', 'k',
448 /* surrogate */ 's', 'u', 'r', 'r', 'o', 'g', 'a', 't', 'e',
449 /* symbol */ 's', 'y', 'm', 'b', 'o', 'l',
450 /* titlecase */ 't', 'i', 't', 'l', 'e', 'c', 'a', 's', 'e',
451 /* titlecaseletter */ 't', 'i', 't', 'l', 'e', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
452 /* uppercaseletter */ 'u', 'p', 'p', 'e', 'r', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
453 /* z* */ 'z', '*',
454 /* zl */ 'z', 'l',
455 /* zp */ 'z', 'p',
456 /* zs */ 'z', 's',
457 };
458
459 static const BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32> range_data[] = {
460 { prop_name_table + 0, prop_name_table + 3, }, // any
461 { prop_name_table + 3, prop_name_table + 8, }, // ascii
462 { prop_name_table + 8, prop_name_table + 16, }, // assigned
463 { prop_name_table + 16, prop_name_table + 18, }, // c*
464 { prop_name_table + 18, prop_name_table + 20, }, // cc
465 { prop_name_table + 20, prop_name_table + 22, }, // cf
466 { prop_name_table + 22, prop_name_table + 38, }, // closepunctuation
467 { prop_name_table + 38, prop_name_table + 40, }, // cn
468 { prop_name_table + 40, prop_name_table + 42, }, // co
469 { prop_name_table + 42, prop_name_table + 62, }, // connectorpunctuation
470 { prop_name_table + 62, prop_name_table + 69, }, // control
471 { prop_name_table + 69, prop_name_table + 71, }, // cs
472 { prop_name_table + 71, prop_name_table + 85, }, // currencysymbol
473 { prop_name_table + 85, prop_name_table + 100, }, // dashpunctuation
474 { prop_name_table + 100, prop_name_table + 118, }, // decimaldigitnumber
475 { prop_name_table + 118, prop_name_table + 131, }, // enclosingmark
476 { prop_name_table + 131, prop_name_table + 147, }, // finalpunctuation
477 { prop_name_table + 147, prop_name_table + 153, }, // format
478 { prop_name_table + 153, prop_name_table + 171, }, // initialpunctuation
479 { prop_name_table + 171, prop_name_table + 173, }, // l*
480 { prop_name_table + 173, prop_name_table + 179, }, // letter
481 { prop_name_table + 179, prop_name_table + 191, }, // letternumber
482 { prop_name_table + 191, prop_name_table + 204, }, // lineseparator
483 { prop_name_table + 204, prop_name_table + 206, }, // ll
484 { prop_name_table + 206, prop_name_table + 208, }, // lm
485 { prop_name_table + 208, prop_name_table + 210, }, // lo
486 { prop_name_table + 210, prop_name_table + 225, }, // lowercaseletter
487 { prop_name_table + 225, prop_name_table + 227, }, // lt
488 { prop_name_table + 227, prop_name_table + 229, }, // lu
489 { prop_name_table + 229, prop_name_table + 231, }, // m*
490 { prop_name_table + 231, prop_name_table + 235, }, // mark
491 { prop_name_table + 235, prop_name_table + 245, }, // mathsymbol
492 { prop_name_table + 245, prop_name_table + 247, }, // mc
493 { prop_name_table + 247, prop_name_table + 249, }, // me
494 { prop_name_table + 249, prop_name_table + 251, }, // mn
495 { prop_name_table + 251, prop_name_table + 265, }, // modifierletter
496 { prop_name_table + 265, prop_name_table + 279, }, // modifiersymbol
497 { prop_name_table + 279, prop_name_table + 281, }, // n*
498 { prop_name_table + 281, prop_name_table + 283, }, // nd
499 { prop_name_table + 283, prop_name_table + 285, }, // nl
500 { prop_name_table + 285, prop_name_table + 287, }, // no
501 { prop_name_table + 287, prop_name_table + 301, }, // nonspacingmark
502 { prop_name_table + 301, prop_name_table + 312, }, // notassigned
503 { prop_name_table + 312, prop_name_table + 318, }, // number
504 { prop_name_table + 318, prop_name_table + 333, }, // openpunctuation
505 { prop_name_table + 333, prop_name_table + 338, }, // other
506 { prop_name_table + 338, prop_name_table + 349, }, // otherletter
507 { prop_name_table + 349, prop_name_table + 360, }, // othernumber
508 { prop_name_table + 360, prop_name_table + 376, }, // otherpunctuation
509 { prop_name_table + 376, prop_name_table + 387, }, // othersymbol
510 { prop_name_table + 387, prop_name_table + 389, }, // p*
511 { prop_name_table + 389, prop_name_table + 407, }, // paragraphseparator
512 { prop_name_table + 407, prop_name_table + 409, }, // pc
513 { prop_name_table + 409, prop_name_table + 411, }, // pd
514 { prop_name_table + 411, prop_name_table + 413, }, // pe
515 { prop_name_table + 413, prop_name_table + 415, }, // pf
516 { prop_name_table + 415, prop_name_table + 417, }, // pi
517 { prop_name_table + 417, prop_name_table + 419, }, // po
518 { prop_name_table + 419, prop_name_table + 429, }, // privateuse
519 { prop_name_table + 429, prop_name_table + 431, }, // ps
520 { prop_name_table + 431, prop_name_table + 442, }, // punctuation
521 { prop_name_table + 442, prop_name_table + 444, }, // s*
522 { prop_name_table + 444, prop_name_table + 446, }, // sc
523 { prop_name_table + 446, prop_name_table + 455, }, // separator
524 { prop_name_table + 455, prop_name_table + 457, }, // sk
525 { prop_name_table + 457, prop_name_table + 459, }, // sm
526 { prop_name_table + 459, prop_name_table + 461, }, // so
527 { prop_name_table + 461, prop_name_table + 475, }, // spaceseparator
528 { prop_name_table + 475, prop_name_table + 495, }, // spacingcombiningmark
529 { prop_name_table + 495, prop_name_table + 504, }, // surrogate
530 { prop_name_table + 504, prop_name_table + 510, }, // symbol
531 { prop_name_table + 510, prop_name_table + 519, }, // titlecase
532 { prop_name_table + 519, prop_name_table + 534, }, // titlecaseletter
533 { prop_name_table + 534, prop_name_table + 549, }, // uppercaseletter
534 { prop_name_table + 549, prop_name_table + 551, }, // z*
535 { prop_name_table + 551, prop_name_table + 553, }, // zl
536 { prop_name_table + 553, prop_name_table + 555, }, // zp
537 { prop_name_table + 555, prop_name_table + 557, }, // zs
538 };
539
540 static const icu_regex_traits::char_class_type icu_class_map[] = {
541 mask_any, // any
542 mask_ascii, // ascii
543 (0x3FFFFFFFu) & ~(U_GC_CN_MASK), // assigned
544 U_GC_C_MASK, // c*
545 U_GC_CC_MASK, // cc
546 U_GC_CF_MASK, // cf
547 U_GC_PE_MASK, // closepunctuation
548 U_GC_CN_MASK, // cn
549 U_GC_CO_MASK, // co
550 U_GC_PC_MASK, // connectorpunctuation
551 U_GC_CC_MASK, // control
552 U_GC_CS_MASK, // cs
553 U_GC_SC_MASK, // currencysymbol
554 U_GC_PD_MASK, // dashpunctuation
555 U_GC_ND_MASK, // decimaldigitnumber
556 U_GC_ME_MASK, // enclosingmark
557 U_GC_PF_MASK, // finalpunctuation
558 U_GC_CF_MASK, // format
559 U_GC_PI_MASK, // initialpunctuation
560 U_GC_L_MASK, // l*
561 U_GC_L_MASK, // letter
562 U_GC_NL_MASK, // letternumber
563 U_GC_ZL_MASK, // lineseparator
564 U_GC_LL_MASK, // ll
565 U_GC_LM_MASK, // lm
566 U_GC_LO_MASK, // lo
567 U_GC_LL_MASK, // lowercaseletter
568 U_GC_LT_MASK, // lt
569 U_GC_LU_MASK, // lu
570 U_GC_M_MASK, // m*
571 U_GC_M_MASK, // mark
572 U_GC_SM_MASK, // mathsymbol
573 U_GC_MC_MASK, // mc
574 U_GC_ME_MASK, // me
575 U_GC_MN_MASK, // mn
576 U_GC_LM_MASK, // modifierletter
577 U_GC_SK_MASK, // modifiersymbol
578 U_GC_N_MASK, // n*
579 U_GC_ND_MASK, // nd
580 U_GC_NL_MASK, // nl
581 U_GC_NO_MASK, // no
582 U_GC_MN_MASK, // nonspacingmark
583 U_GC_CN_MASK, // notassigned
584 U_GC_N_MASK, // number
585 U_GC_PS_MASK, // openpunctuation
586 U_GC_C_MASK, // other
587 U_GC_LO_MASK, // otherletter
588 U_GC_NO_MASK, // othernumber
589 U_GC_PO_MASK, // otherpunctuation
590 U_GC_SO_MASK, // othersymbol
591 U_GC_P_MASK, // p*
592 U_GC_ZP_MASK, // paragraphseparator
593 U_GC_PC_MASK, // pc
594 U_GC_PD_MASK, // pd
595 U_GC_PE_MASK, // pe
596 U_GC_PF_MASK, // pf
597 U_GC_PI_MASK, // pi
598 U_GC_PO_MASK, // po
599 U_GC_CO_MASK, // privateuse
600 U_GC_PS_MASK, // ps
601 U_GC_P_MASK, // punctuation
602 U_GC_S_MASK, // s*
603 U_GC_SC_MASK, // sc
604 U_GC_Z_MASK, // separator
605 U_GC_SK_MASK, // sk
606 U_GC_SM_MASK, // sm
607 U_GC_SO_MASK, // so
608 U_GC_ZS_MASK, // spaceseparator
609 U_GC_MC_MASK, // spacingcombiningmark
610 U_GC_CS_MASK, // surrogate
611 U_GC_S_MASK, // symbol
612 U_GC_LT_MASK, // titlecase
613 U_GC_LT_MASK, // titlecaseletter
614 U_GC_LU_MASK, // uppercaseletter
615 U_GC_Z_MASK, // z*
616 U_GC_ZL_MASK, // zl
617 U_GC_ZP_MASK, // zp
618 U_GC_ZS_MASK, // zs
619 };
620
621
622 const BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32>* ranges_begin = range_data;
623 const BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32>* ranges_end = range_data + (sizeof(range_data) / sizeof(range_data[0]));
624
625 BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32> t = { p1, p2, };
626 const BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32>* p = std::lower_bound(ranges_begin, ranges_end, t);
627 if ((p != ranges_end) && (t == *p))
628 return icu_class_map[p - ranges_begin];
629 return 0;
630 }
631 std::shared_ptr< ::boost::BOOST_REGEX_DETAIL_NS::icu_regex_traits_implementation> m_pimpl;
632 };
633
634 } // namespace boost
635
636 namespace boost{
637
638 // types:
639 typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
640 typedef match_results<const ::UChar32*> u32match;
641 typedef match_results<const ::UChar*> u16match;
642
643 //
644 // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
645 //
646 namespace BOOST_REGEX_DETAIL_NS{
647
648 template <class InputIterator>
649 inline u32regex do_make_u32regex(InputIterator i,
650 InputIterator j,
651 boost::regex_constants::syntax_option_type opt,
652 const std::integral_constant<int, 1>*)
653 {
654 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
655 return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
656 }
657
658 template <class InputIterator>
659 inline u32regex do_make_u32regex(InputIterator i,
660 InputIterator j,
661 boost::regex_constants::syntax_option_type opt,
662 const std::integral_constant<int, 2>*)
663 {
664 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
665 return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
666 }
667
668 template <class InputIterator>
669 inline u32regex do_make_u32regex(InputIterator i,
670 InputIterator j,
671 boost::regex_constants::syntax_option_type opt,
672 const std::integral_constant<int, 4>*)
673 {
674 return u32regex(i, j, opt);
675 }
676 }
677
678 // BOOST_REGEX_UCHAR_IS_WCHAR_T
679 //
680 // Source inspection of unicode/umachine.h in ICU version 59 indicates that:
681 //
682 // On version 59, UChar is always char16_t in C++ mode (and uint16_t in C mode)
683 //
684 // On earlier versions, the logic is
685 //
686 // #if U_SIZEOF_WCHAR_T==2
687 // typedef wchar_t OldUChar;
688 // #elif defined(__CHAR16_TYPE__)
689 // typedef __CHAR16_TYPE__ OldUChar;
690 // #else
691 // typedef uint16_t OldUChar;
692 // #endif
693 //
694 // That is, UChar is wchar_t only on versions below 59, when U_SIZEOF_WCHAR_T==2
695 //
696 // Hence,
697
698 #define BOOST_REGEX_UCHAR_IS_WCHAR_T (U_ICU_VERSION_MAJOR_NUM < 59 && U_SIZEOF_WCHAR_T == 2)
699
700 #if BOOST_REGEX_UCHAR_IS_WCHAR_T
701 static_assert((std::is_same<UChar, wchar_t>::value), "Configuration logic has failed!");
702 #else
703 static_assert(!(std::is_same<UChar, wchar_t>::value), "Configuration logic has failed!");
704 #endif
705
706 //
707 // Construction from an iterator pair:
708 //
709 template <class InputIterator>
710 inline u32regex make_u32regex(InputIterator i,
711 InputIterator j,
712 boost::regex_constants::syntax_option_type opt)
713 {
714 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(i, j, opt, static_cast<std::integral_constant<int, sizeof(*i)> const*>(0));
715 }
716 //
717 // construction from UTF-8 nul-terminated strings:
718 //
719 inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
720 {
721 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<std::integral_constant<int, 1> const*>(0));
722 }
723 inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
724 {
725 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(reinterpret_cast<const char*>(p)), opt, static_cast<std::integral_constant<int, 1> const*>(0));
726 }
727 //
728 // construction from UTF-16 nul-terminated strings:
729 //
730 #ifndef BOOST_NO_WREGEX
731 inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
732 {
733 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
734 }
735 #endif
736 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T
737 inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
738 {
739 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<std::integral_constant<int, 2> const*>(0));
740 }
741 #endif
742 //
743 // construction from basic_string class-template:
744 //
745 template<class C, class T, class A>
746 inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
747 {
748 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.begin(), s.end(), opt, static_cast<std::integral_constant<int, sizeof(C)> const*>(0));
749 }
750 //
751 // Construction from ICU string type:
752 //
753 inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
754 {
755 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<std::integral_constant<int, 2> const*>(0));
756 }
757
758 //
759 // regex_match overloads that widen the character type as appropriate:
760 //
761 namespace BOOST_REGEX_DETAIL_NS{
762 template<class MR1, class MR2, class NSubs>
763 void copy_results(MR1& out, MR2 const& in, NSubs named_subs)
764 {
765 // copy results from an adapted MR2 match_results:
766 out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
767 out.set_base(in.base().base());
768 out.set_named_subs(named_subs);
769 for(int i = 0; i < (int)in.size(); ++i)
770 {
771 if(in[i].matched || !i)
772 {
773 out.set_first(in[i].first.base(), i);
774 out.set_second(in[i].second.base(), i, in[i].matched);
775 }
776 }
777 #ifdef BOOST_REGEX_MATCH_EXTRA
778 // Copy full capture info as well:
779 for(int i = 0; i < (int)in.size(); ++i)
780 {
781 if(in[i].captures().size())
782 {
783 out[i].get_captures().assign(in[i].captures().size(), typename MR1::value_type());
784 for(int j = 0; j < (int)out[i].captures().size(); ++j)
785 {
786 out[i].get_captures()[j].first = in[i].captures()[j].first.base();
787 out[i].get_captures()[j].second = in[i].captures()[j].second.base();
788 out[i].get_captures()[j].matched = in[i].captures()[j].matched;
789 }
790 }
791 }
792 #endif
793 }
794
795 template <class BidiIterator, class Allocator>
796 inline bool do_regex_match(BidiIterator first, BidiIterator last,
797 match_results<BidiIterator, Allocator>& m,
798 const u32regex& e,
799 match_flag_type flags,
800 std::integral_constant<int, 4> const*)
801 {
802 return ::boost::regex_match(first, last, m, e, flags);
803 }
804 template <class BidiIterator, class Allocator>
805 bool do_regex_match(BidiIterator first, BidiIterator last,
806 match_results<BidiIterator, Allocator>& m,
807 const u32regex& e,
808 match_flag_type flags,
809 std::integral_constant<int, 2> const*)
810 {
811 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
812 typedef match_results<conv_type> match_type;
813 //typedef typename match_type::allocator_type alloc_type;
814 match_type what;
815 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
816 // copy results across to m:
817 if(result) copy_results(m, what, e.get_named_subs());
818 return result;
819 }
820 template <class BidiIterator, class Allocator>
821 bool do_regex_match(BidiIterator first, BidiIterator last,
822 match_results<BidiIterator, Allocator>& m,
823 const u32regex& e,
824 match_flag_type flags,
825 std::integral_constant<int, 1> const*)
826 {
827 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
828 typedef match_results<conv_type> match_type;
829 //typedef typename match_type::allocator_type alloc_type;
830 match_type what;
831 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
832 // copy results across to m:
833 if(result) copy_results(m, what, e.get_named_subs());
834 return result;
835 }
836 } // namespace BOOST_REGEX_DETAIL_NS
837
838 template <class BidiIterator, class Allocator>
839 inline bool u32regex_match(BidiIterator first, BidiIterator last,
840 match_results<BidiIterator, Allocator>& m,
841 const u32regex& e,
842 match_flag_type flags = match_default)
843 {
844 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
845 }
846 inline bool u32regex_match(const UChar* p,
847 match_results<const UChar*>& m,
848 const u32regex& e,
849 match_flag_type flags = match_default)
850 {
851 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<std::integral_constant<int, 2> const*>(0));
852 }
853 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
854 inline bool u32regex_match(const wchar_t* p,
855 match_results<const wchar_t*>& m,
856 const u32regex& e,
857 match_flag_type flags = match_default)
858 {
859 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
860 }
861 #endif
862 inline bool u32regex_match(const char* p,
863 match_results<const char*>& m,
864 const u32regex& e,
865 match_flag_type flags = match_default)
866 {
867 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
868 }
869 inline bool u32regex_match(const unsigned char* p,
870 match_results<const unsigned char*>& m,
871 const u32regex& e,
872 match_flag_type flags = match_default)
873 {
874 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
875 }
876 inline bool u32regex_match(const std::string& s,
877 match_results<std::string::const_iterator>& m,
878 const u32regex& e,
879 match_flag_type flags = match_default)
880 {
881 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
882 }
883 #ifndef BOOST_NO_STD_WSTRING
884 inline bool u32regex_match(const std::wstring& s,
885 match_results<std::wstring::const_iterator>& m,
886 const u32regex& e,
887 match_flag_type flags = match_default)
888 {
889 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
890 }
891 #endif
892 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
893 match_results<const UChar*>& m,
894 const u32regex& e,
895 match_flag_type flags = match_default)
896 {
897 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<std::integral_constant<int, 2> const*>(0));
898 }
899 //
900 // regex_match overloads that do not return what matched:
901 //
902 template <class BidiIterator>
903 inline bool u32regex_match(BidiIterator first, BidiIterator last,
904 const u32regex& e,
905 match_flag_type flags = match_default)
906 {
907 match_results<BidiIterator> m;
908 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
909 }
910 inline bool u32regex_match(const UChar* p,
911 const u32regex& e,
912 match_flag_type flags = match_default)
913 {
914 match_results<const UChar*> m;
915 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<std::integral_constant<int, 2> const*>(0));
916 }
917 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
918 inline bool u32regex_match(const wchar_t* p,
919 const u32regex& e,
920 match_flag_type flags = match_default)
921 {
922 match_results<const wchar_t*> m;
923 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
924 }
925 #endif
926 inline bool u32regex_match(const char* p,
927 const u32regex& e,
928 match_flag_type flags = match_default)
929 {
930 match_results<const char*> m;
931 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
932 }
933 inline bool u32regex_match(const unsigned char* p,
934 const u32regex& e,
935 match_flag_type flags = match_default)
936 {
937 match_results<const unsigned char*> m;
938 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
939 }
940 inline bool u32regex_match(const std::string& s,
941 const u32regex& e,
942 match_flag_type flags = match_default)
943 {
944 match_results<std::string::const_iterator> m;
945 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
946 }
947 #ifndef BOOST_NO_STD_WSTRING
948 inline bool u32regex_match(const std::wstring& s,
949 const u32regex& e,
950 match_flag_type flags = match_default)
951 {
952 match_results<std::wstring::const_iterator> m;
953 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
954 }
955 #endif
956 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
957 const u32regex& e,
958 match_flag_type flags = match_default)
959 {
960 match_results<const UChar*> m;
961 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<std::integral_constant<int, 2> const*>(0));
962 }
963
964 //
965 // regex_search overloads that widen the character type as appropriate:
966 //
967 namespace BOOST_REGEX_DETAIL_NS{
968 template <class BidiIterator, class Allocator>
969 inline bool do_regex_search(BidiIterator first, BidiIterator last,
970 match_results<BidiIterator, Allocator>& m,
971 const u32regex& e,
972 match_flag_type flags,
973 BidiIterator base,
974 std::integral_constant<int, 4> const*)
975 {
976 return ::boost::regex_search(first, last, m, e, flags, base);
977 }
978 template <class BidiIterator, class Allocator>
979 bool do_regex_search(BidiIterator first, BidiIterator last,
980 match_results<BidiIterator, Allocator>& m,
981 const u32regex& e,
982 match_flag_type flags,
983 BidiIterator base,
984 std::integral_constant<int, 2> const*)
985 {
986 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
987 typedef match_results<conv_type> match_type;
988 //typedef typename match_type::allocator_type alloc_type;
989 match_type what;
990 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
991 // copy results across to m:
992 if(result) copy_results(m, what, e.get_named_subs());
993 return result;
994 }
995 template <class BidiIterator, class Allocator>
996 bool do_regex_search(BidiIterator first, BidiIterator last,
997 match_results<BidiIterator, Allocator>& m,
998 const u32regex& e,
999 match_flag_type flags,
1000 BidiIterator base,
1001 std::integral_constant<int, 1> const*)
1002 {
1003 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
1004 typedef match_results<conv_type> match_type;
1005 //typedef typename match_type::allocator_type alloc_type;
1006 match_type what;
1007 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
1008 // copy results across to m:
1009 if(result) copy_results(m, what, e.get_named_subs());
1010 return result;
1011 }
1012 }
1013
1014 template <class BidiIterator, class Allocator>
1015 inline bool u32regex_search(BidiIterator first, BidiIterator last,
1016 match_results<BidiIterator, Allocator>& m,
1017 const u32regex& e,
1018 match_flag_type flags = match_default)
1019 {
1020 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
1021 }
1022 template <class BidiIterator, class Allocator>
1023 inline bool u32regex_search(BidiIterator first, BidiIterator last,
1024 match_results<BidiIterator, Allocator>& m,
1025 const u32regex& e,
1026 match_flag_type flags,
1027 BidiIterator base)
1028 {
1029 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, base, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
1030 }
1031 inline bool u32regex_search(const UChar* p,
1032 match_results<const UChar*>& m,
1033 const u32regex& e,
1034 match_flag_type flags = match_default)
1035 {
1036 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<std::integral_constant<int, 2> const*>(0));
1037 }
1038 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
1039 inline bool u32regex_search(const wchar_t* p,
1040 match_results<const wchar_t*>& m,
1041 const u32regex& e,
1042 match_flag_type flags = match_default)
1043 {
1044 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
1045 }
1046 #endif
1047 inline bool u32regex_search(const char* p,
1048 match_results<const char*>& m,
1049 const u32regex& e,
1050 match_flag_type flags = match_default)
1051 {
1052 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<std::integral_constant<int, 1> const*>(0));
1053 }
1054 inline bool u32regex_search(const unsigned char* p,
1055 match_results<const unsigned char*>& m,
1056 const u32regex& e,
1057 match_flag_type flags = match_default)
1058 {
1059 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<std::integral_constant<int, 1> const*>(0));
1060 }
1061 inline bool u32regex_search(const std::string& s,
1062 match_results<std::string::const_iterator>& m,
1063 const u32regex& e,
1064 match_flag_type flags = match_default)
1065 {
1066 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<std::integral_constant<int, 1> const*>(0));
1067 }
1068 #ifndef BOOST_NO_STD_WSTRING
1069 inline bool u32regex_search(const std::wstring& s,
1070 match_results<std::wstring::const_iterator>& m,
1071 const u32regex& e,
1072 match_flag_type flags = match_default)
1073 {
1074 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
1075 }
1076 #endif
1077 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1078 match_results<const UChar*>& m,
1079 const u32regex& e,
1080 match_flag_type flags = match_default)
1081 {
1082 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<std::integral_constant<int, 2> const*>(0));
1083 }
1084 template <class BidiIterator>
1085 inline bool u32regex_search(BidiIterator first, BidiIterator last,
1086 const u32regex& e,
1087 match_flag_type flags = match_default)
1088 {
1089 match_results<BidiIterator> m;
1090 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
1091 }
1092 inline bool u32regex_search(const UChar* p,
1093 const u32regex& e,
1094 match_flag_type flags = match_default)
1095 {
1096 match_results<const UChar*> m;
1097 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<std::integral_constant<int, 2> const*>(0));
1098 }
1099 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
1100 inline bool u32regex_search(const wchar_t* p,
1101 const u32regex& e,
1102 match_flag_type flags = match_default)
1103 {
1104 match_results<const wchar_t*> m;
1105 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
1106 }
1107 #endif
1108 inline bool u32regex_search(const char* p,
1109 const u32regex& e,
1110 match_flag_type flags = match_default)
1111 {
1112 match_results<const char*> m;
1113 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<std::integral_constant<int, 1> const*>(0));
1114 }
1115 inline bool u32regex_search(const unsigned char* p,
1116 const u32regex& e,
1117 match_flag_type flags = match_default)
1118 {
1119 match_results<const unsigned char*> m;
1120 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<std::integral_constant<int, 1> const*>(0));
1121 }
1122 inline bool u32regex_search(const std::string& s,
1123 const u32regex& e,
1124 match_flag_type flags = match_default)
1125 {
1126 match_results<std::string::const_iterator> m;
1127 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<std::integral_constant<int, 1> const*>(0));
1128 }
1129 #ifndef BOOST_NO_STD_WSTRING
1130 inline bool u32regex_search(const std::wstring& s,
1131 const u32regex& e,
1132 match_flag_type flags = match_default)
1133 {
1134 match_results<std::wstring::const_iterator> m;
1135 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
1136 }
1137 #endif
1138 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1139 const u32regex& e,
1140 match_flag_type flags = match_default)
1141 {
1142 match_results<const UChar*> m;
1143 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<std::integral_constant<int, 2> const*>(0));
1144 }
1145
1146 //
1147 // overloads for regex_replace with utf-8 and utf-16 data types:
1148 //
1149 namespace BOOST_REGEX_DETAIL_NS{
1150 template <class I>
1151 inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
1152 make_utf32_seq(I i, I j, std::integral_constant<int, 1> const*)
1153 {
1154 return std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >(boost::u8_to_u32_iterator<I>(i, i, j), boost::u8_to_u32_iterator<I>(j, i, j));
1155 }
1156 template <class I>
1157 inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
1158 make_utf32_seq(I i, I j, std::integral_constant<int, 2> const*)
1159 {
1160 return std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >(boost::u16_to_u32_iterator<I>(i, i, j), boost::u16_to_u32_iterator<I>(j, i, j));
1161 }
1162 template <class I>
1163 inline std::pair< I, I >
1164 make_utf32_seq(I i, I j, std::integral_constant<int, 4> const*)
1165 {
1166 return std::pair< I, I >(i, j);
1167 }
1168 template <class charT>
1169 inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
1170 make_utf32_seq(const charT* p, std::integral_constant<int, 1> const*)
1171 {
1172 std::size_t len = std::strlen((const char*)p);
1173 return std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >(boost::u8_to_u32_iterator<const charT*>(p, p, p+len), boost::u8_to_u32_iterator<const charT*>(p+len, p, p+len));
1174 }
1175 template <class charT>
1176 inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
1177 make_utf32_seq(const charT* p, std::integral_constant<int, 2> const*)
1178 {
1179 std::size_t len = u_strlen((const UChar*)p);
1180 return std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >(boost::u16_to_u32_iterator<const charT*>(p, p, p + len), boost::u16_to_u32_iterator<const charT*>(p+len, p, p + len));
1181 }
1182 template <class charT>
1183 inline std::pair< const charT*, const charT* >
1184 make_utf32_seq(const charT* p, std::integral_constant<int, 4> const*)
1185 {
1186 return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
1187 }
1188 template <class OutputIterator>
1189 inline OutputIterator make_utf32_out(OutputIterator o, std::integral_constant<int, 4> const*)
1190 {
1191 return o;
1192 }
1193 template <class OutputIterator>
1194 inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, std::integral_constant<int, 2> const*)
1195 {
1196 return o;
1197 }
1198 template <class OutputIterator>
1199 inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, std::integral_constant<int, 1> const*)
1200 {
1201 return o;
1202 }
1203
1204 template <class OutputIterator, class I1, class I2>
1205 OutputIterator do_regex_replace(OutputIterator out,
1206 std::pair<I1, I1> const& in,
1207 const u32regex& e,
1208 const std::pair<I2, I2>& fmt,
1209 match_flag_type flags
1210 )
1211 {
1212 // unfortunately we have to copy the format string in order to pass in onward:
1213 std::vector<UChar32> f;
1214 f.assign(fmt.first, fmt.second);
1215
1216 regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
1217 regex_iterator<I1, UChar32, icu_regex_traits> j;
1218 if(i == j)
1219 {
1220 if(!(flags & regex_constants::format_no_copy))
1221 out = std::copy(in.first, in.second, out);
1222 }
1223 else
1224 {
1225 I1 last_m = in.first;
1226 while(i != j)
1227 {
1228 if(!(flags & regex_constants::format_no_copy))
1229 out = std::copy(i->prefix().first, i->prefix().second, out);
1230 if(!f.empty())
1231 out = ::boost::BOOST_REGEX_DETAIL_NS::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
1232 else
1233 out = ::boost::BOOST_REGEX_DETAIL_NS::regex_format_imp(out, *i, static_cast<UChar32 const*>(0), static_cast<UChar32 const*>(0), flags, e.get_traits());
1234 last_m = (*i)[0].second;
1235 if(flags & regex_constants::format_first_only)
1236 break;
1237 ++i;
1238 }
1239 if(!(flags & regex_constants::format_no_copy))
1240 out = std::copy(last_m, in.second, out);
1241 }
1242 return out;
1243 }
1244 template <class BaseIterator>
1245 inline const BaseIterator& extract_output_base(const BaseIterator& b)
1246 {
1247 return b;
1248 }
1249 template <class BaseIterator>
1250 inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
1251 {
1252 return b.base();
1253 }
1254 template <class BaseIterator>
1255 inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
1256 {
1257 return b.base();
1258 }
1259 } // BOOST_REGEX_DETAIL_NS
1260
1261 template <class OutputIterator, class BidirectionalIterator, class charT>
1262 inline OutputIterator u32regex_replace(OutputIterator out,
1263 BidirectionalIterator first,
1264 BidirectionalIterator last,
1265 const u32regex& e,
1266 const charT* fmt,
1267 match_flag_type flags = match_default)
1268 {
1269 return BOOST_REGEX_DETAIL_NS::extract_output_base
1270 (
1271 BOOST_REGEX_DETAIL_NS::do_regex_replace(
1272 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
1273 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
1274 e,
1275 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt, static_cast<std::integral_constant<int, sizeof(*fmt)> const*>(0)),
1276 flags)
1277 );
1278 }
1279
1280 template <class OutputIterator, class Iterator, class charT>
1281 inline OutputIterator u32regex_replace(OutputIterator out,
1282 Iterator first,
1283 Iterator last,
1284 const u32regex& e,
1285 const std::basic_string<charT>& fmt,
1286 match_flag_type flags = match_default)
1287 {
1288 return BOOST_REGEX_DETAIL_NS::extract_output_base
1289 (
1290 BOOST_REGEX_DETAIL_NS::do_regex_replace(
1291 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
1292 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
1293 e,
1294 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<std::integral_constant<int, sizeof(charT)> const*>(0)),
1295 flags)
1296 );
1297 }
1298
1299 template <class OutputIterator, class Iterator>
1300 inline OutputIterator u32regex_replace(OutputIterator out,
1301 Iterator first,
1302 Iterator last,
1303 const u32regex& e,
1304 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1305 match_flag_type flags = match_default)
1306 {
1307 return BOOST_REGEX_DETAIL_NS::extract_output_base
1308 (
1309 BOOST_REGEX_DETAIL_NS::do_regex_replace(
1310 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
1311 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
1312 e,
1313 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<std::integral_constant<int, 2> const*>(0)),
1314 flags)
1315 );
1316 }
1317
1318 template <class charT>
1319 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
1320 const u32regex& e,
1321 const charT* fmt,
1322 match_flag_type flags = match_default)
1323 {
1324 std::basic_string<charT> result;
1325 BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
1326 u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
1327 return result;
1328 }
1329
1330 template <class charT>
1331 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
1332 const u32regex& e,
1333 const std::basic_string<charT>& fmt,
1334 match_flag_type flags = match_default)
1335 {
1336 std::basic_string<charT> result;
1337 BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
1338 u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
1339 return result;
1340 }
1341
1342 namespace BOOST_REGEX_DETAIL_NS{
1343
1344 class unicode_string_out_iterator
1345 {
1346 U_NAMESPACE_QUALIFIER UnicodeString* out;
1347 public:
1348 unicode_string_out_iterator(U_NAMESPACE_QUALIFIER UnicodeString& s) : out(&s) {}
1349 unicode_string_out_iterator& operator++() { return *this; }
1350 unicode_string_out_iterator& operator++(int) { return *this; }
1351 unicode_string_out_iterator& operator*() { return *this; }
1352 unicode_string_out_iterator& operator=(UChar v)
1353 {
1354 *out += v;
1355 return *this;
1356 }
1357 typedef std::ptrdiff_t difference_type;
1358 typedef UChar value_type;
1359 typedef value_type* pointer;
1360 typedef value_type& reference;
1361 typedef std::output_iterator_tag iterator_category;
1362 };
1363
1364 }
1365
1366 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1367 const u32regex& e,
1368 const UChar* fmt,
1369 match_flag_type flags = match_default)
1370 {
1371 U_NAMESPACE_QUALIFIER UnicodeString result;
1372 BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
1373 u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
1374 return result;
1375 }
1376
1377 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1378 const u32regex& e,
1379 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1380 match_flag_type flags = match_default)
1381 {
1382 U_NAMESPACE_QUALIFIER UnicodeString result;
1383 BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
1384 BOOST_REGEX_DETAIL_NS::do_regex_replace(
1385 BOOST_REGEX_DETAIL_NS::make_utf32_out(i, static_cast<std::integral_constant<int, 2> const*>(0)),
1386 BOOST_REGEX_DETAIL_NS::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<std::integral_constant<int, 2> const*>(0)),
1387 e,
1388 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<std::integral_constant<int, 2> const*>(0)),
1389 flags);
1390 return result;
1391 }
1392
1393 } // namespace boost.
1394
1395 #ifdef BOOST_REGEX_MSVC
1396 #pragma warning (pop)
1397 #endif
1398
1399 #include <boost/regex/v5/u32regex_iterator.hpp>
1400 #include <boost/regex/v5/u32regex_token_iterator.hpp>
1401
1402 #endif