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.
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Unicode regular expressions on top of the ICU Library.
19 #ifndef BOOST_REGEX_ICU_V5_HPP
20 #define BOOST_REGEX_ICU_V5_HPP
22 #include <unicode/utypes.h>
23 #include <unicode/uchar.h>
24 #include <unicode/coll.h>
25 #include <type_traits>
27 #include <boost/regex.hpp>
28 #include <boost/regex/v5/unicode_iterator.hpp>
30 #ifdef BOOST_REGEX_MSVC
31 #pragma warning (push)
32 #pragma warning (disable: 4251)
37 namespace BOOST_REGEX_DETAIL_NS{
40 // Implementation details:
42 class icu_regex_traits_implementation
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;
50 icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
53 UErrorCode success = U_ZERO_ERROR;
54 m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
55 if(U_SUCCESS(success) == 0)
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)
62 m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
64 U_NAMESPACE_QUALIFIER Locale getloc()const
68 string_type do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const
70 // TODO make thread safe!!!! :
71 typedef u32_to_u16_iterator<const char_type*, ::UChar> itt;
73 std::vector< ::UChar> t(i, j);
74 std::uint8_t result[100];
77 len = pcoll->getSortKey(&*t.begin(), static_cast<std::int32_t>(t.size()), result, sizeof(result));
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))
82 std::unique_ptr< std::uint8_t[]> presult(new ::uint8_t[len + 1]);
84 len = pcoll->getSortKey(&*t.begin(), static_cast<std::int32_t>(t.size()), presult.get(), len + 1);
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))
89 return string_type(presult.get(), presult.get() + len);
91 if ((0 == result[len - 1]) && (len > 1))
93 return string_type(result, result + len);
95 string_type transform(const char_type* p1, const char_type* p2) const
97 return do_transform(p1, p2, m_collator.get());
99 string_type transform_primary(const char_type* p1, const char_type* p2) const
101 return do_transform(p1, p2, m_primary_collator.get());
106 std::runtime_error e("Could not initialize ICU resources");
107 #ifndef BOOST_REGEX_STANDALONE
108 boost::throw_exception(e);
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
117 inline std::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
119 return std::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
124 class icu_regex_traits
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;
133 struct boost_extensions_tag{};
136 : m_pimpl(BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
139 static size_type length(const char_type* p)
141 size_type result = 0;
150 ::boost::regex_constants::syntax_type syntax_type(char_type c)const
152 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
154 ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
156 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
158 char_type translate(char_type c) const
162 char_type translate_nocase(char_type c) const
164 return ::u_foldCase(c, U_FOLD_CASE_DEFAULT);
166 char_type translate(char_type c, bool icase) const
168 return icase ? translate_nocase(c) : translate(c);
170 char_type tolower(char_type c) const
172 return ::u_tolower(c);
174 char_type toupper(char_type c) const
176 return ::u_toupper(c);
178 string_type transform(const char_type* p1, const char_type* p2) const
180 return m_pimpl->transform(p1, p2);
182 string_type transform_primary(const char_type* p1, const char_type* p2) const
184 return m_pimpl->transform_primary(p1, p2);
186 char_class_type lookup_classname(const char_type* p1, const char_type* p2) const
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;
198 static const char_class_type masks[] =
201 U_GC_L_MASK | U_GC_ND_MASK,
204 U_GC_CC_MASK | U_GC_CF_MASK | U_GC_ZL_MASK | U_GC_ZP_MASK,
207 (0x3FFFFFFFu) & ~(U_GC_CC_MASK | U_GC_CF_MASK | U_GC_CS_MASK | U_GC_CN_MASK | U_GC_Z_MASK),
213 char_class_type(U_GC_Z_MASK) | mask_space,
214 char_class_type(U_GC_Z_MASK) | mask_space,
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,
224 int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2);
226 return masks[idx + 1];
227 char_class_type result = lookup_icu_mask(p1, p2);
233 string_type s(p1, p2);
234 string_type::size_type i = 0;
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);
242 s[i] = static_cast<char>((::u_tolower)(s[i]));
247 idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size());
249 return masks[idx + 1];
251 result = lookup_icu_mask(&*s.begin(), &*s.begin() + s.size());
255 BOOST_REGEX_ASSERT(std::size_t(idx + 1) < sizeof(masks) / sizeof(masks[0]));
256 return masks[idx + 1];
258 string_type lookup_collatename(const char_type* p1, const char_type* p2) const
261 if (std::find_if(p1, p2, std::bind(std::greater< ::UChar32>(), std::placeholders::_1, 0x7f)) == p2)
263 std::string s(p1, p2);
265 UErrorCode err = U_ZERO_ERROR;
266 UChar32 c = ::u_charFromName(U_UNICODE_CHAR_NAME, s.c_str(), &err);
272 // Try Unicode-extended name:
274 c = ::u_charFromName(U_EXTENDED_CHAR_NAME, s.c_str(), &err);
281 s = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(s);
282 result.assign(s.begin(), s.end());
284 if (result.empty() && (p2 - p1 == 1))
285 result.push_back(*p1);
288 bool isctype(char_type c, char_class_type f) const
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;
300 // check for standard catagories first:
301 char_class_type m = char_class_type(static_cast<char_class_type>(1) << u_charType(c));
304 // now check for special cases:
305 if (((f & mask_blank) != 0) && u_isblank(c))
307 if (((f & mask_space) != 0) && u_isspace(c))
309 if (((f & mask_xdigit) != 0) && (u_digit(c, 16) >= 0))
311 if (((f & mask_unicode) != 0) && (c >= 0x100))
313 if (((f & mask_underscore) != 0) && (c == '_'))
315 if (((f & mask_any) != 0) && (c <= 0x10FFFF))
317 if (((f & mask_ascii) != 0) && (c <= 0x7F))
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)))
321 if (((f & mask_horizontal) != 0) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && u_isspace(c) && (c != static_cast<char_type>('\v')))
325 std::intmax_t toi(const char_type*& p1, const char_type* p2, int radix)const
327 return BOOST_REGEX_DETAIL_NS::global_toi(p1, p2, radix, *this);
329 int value(char_type c, int radix)const
331 return u_digit(c, static_cast< std::int8_t>(radix));
333 locale_type imbue(locale_type l)
335 locale_type result(m_pimpl->getloc());
336 m_pimpl = BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(l);
339 locale_type getloc()const
341 return locale_type();
343 std::string error_string(::boost::regex_constants::error_type n) const
345 return BOOST_REGEX_DETAIL_NS::get_default_error_string(n);
348 icu_regex_traits(const icu_regex_traits&);
349 icu_regex_traits& operator=(const icu_regex_traits&);
352 // define the bitmasks offsets we need for additional character properties:
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
366 static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2)
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;
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',
385 /* closepunctuation */ 'c', 'l', 'o', 's', 'e', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
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',
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',
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',
405 /* lowercaseletter */ 'l', 'o', 'w', 'e', 'r', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
409 /* mark */ 'm', 'a', 'r', 'k',
410 /* mathsymbol */ 'm', 'a', 't', 'h', 's', 'y', 'm', 'b', 'o', 'l',
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',
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',
430 /* paragraphseparator */ 'p', 'a', 'r', 'a', 'g', 'r', 'a', 'p', 'h', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
437 /* privateuse */ 'p', 'r', 'i', 'v', 'a', 't', 'e', 'u', 's', 'e',
439 /* punctuation */ 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
442 /* separator */ 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
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',
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
540 static const icu_regex_traits::char_class_type icu_class_map[] = {
543 (0x3FFFFFFFu) & ~(U_GC_CN_MASK), // assigned
547 U_GC_PE_MASK, // closepunctuation
550 U_GC_PC_MASK, // connectorpunctuation
551 U_GC_CC_MASK, // control
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
561 U_GC_L_MASK, // letter
562 U_GC_NL_MASK, // letternumber
563 U_GC_ZL_MASK, // lineseparator
567 U_GC_LL_MASK, // lowercaseletter
572 U_GC_SM_MASK, // mathsymbol
576 U_GC_LM_MASK, // modifierletter
577 U_GC_SK_MASK, // modifiersymbol
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
592 U_GC_ZP_MASK, // paragraphseparator
599 U_GC_CO_MASK, // privateuse
601 U_GC_P_MASK, // punctuation
604 U_GC_Z_MASK, // separator
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
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]));
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];
631 std::shared_ptr< ::boost::BOOST_REGEX_DETAIL_NS::icu_regex_traits_implementation> m_pimpl;
639 typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
640 typedef match_results<const ::UChar32*> u32match;
641 typedef match_results<const ::UChar*> u16match;
644 // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
646 namespace BOOST_REGEX_DETAIL_NS{
648 template <class InputIterator>
649 inline u32regex do_make_u32regex(InputIterator i,
651 boost::regex_constants::syntax_option_type opt,
652 const std::integral_constant<int, 1>*)
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);
658 template <class InputIterator>
659 inline u32regex do_make_u32regex(InputIterator i,
661 boost::regex_constants::syntax_option_type opt,
662 const std::integral_constant<int, 2>*)
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);
668 template <class InputIterator>
669 inline u32regex do_make_u32regex(InputIterator i,
671 boost::regex_constants::syntax_option_type opt,
672 const std::integral_constant<int, 4>*)
674 return u32regex(i, j, opt);
678 // BOOST_REGEX_UCHAR_IS_WCHAR_T
680 // Source inspection of unicode/umachine.h in ICU version 59 indicates that:
682 // On version 59, UChar is always char16_t in C++ mode (and uint16_t in C mode)
684 // On earlier versions, the logic is
686 // #if U_SIZEOF_WCHAR_T==2
687 // typedef wchar_t OldUChar;
688 // #elif defined(__CHAR16_TYPE__)
689 // typedef __CHAR16_TYPE__ OldUChar;
691 // typedef uint16_t OldUChar;
694 // That is, UChar is wchar_t only on versions below 59, when U_SIZEOF_WCHAR_T==2
698 #define BOOST_REGEX_UCHAR_IS_WCHAR_T (U_ICU_VERSION_MAJOR_NUM < 59 && U_SIZEOF_WCHAR_T == 2)
700 #if BOOST_REGEX_UCHAR_IS_WCHAR_T
701 static_assert((std::is_same<UChar, wchar_t>::value), "Configuration logic has failed!");
703 static_assert(!(std::is_same<UChar, wchar_t>::value), "Configuration logic has failed!");
707 // Construction from an iterator pair:
709 template <class InputIterator>
710 inline u32regex make_u32regex(InputIterator i,
712 boost::regex_constants::syntax_option_type opt)
714 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(i, j, opt, static_cast<std::integral_constant<int, sizeof(*i)> const*>(0));
717 // construction from UTF-8 nul-terminated strings:
719 inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
721 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<std::integral_constant<int, 1> const*>(0));
723 inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
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));
728 // construction from UTF-16 nul-terminated strings:
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)
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));
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)
739 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<std::integral_constant<int, 2> const*>(0));
743 // construction from basic_string class-template:
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)
748 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.begin(), s.end(), opt, static_cast<std::integral_constant<int, sizeof(C)> const*>(0));
751 // Construction from ICU string type:
753 inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
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));
759 // regex_match overloads that widen the character type as appropriate:
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)
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)
771 if(in[i].matched || !i)
773 out.set_first(in[i].first.base(), i);
774 out.set_second(in[i].second.base(), i, in[i].matched);
777 #ifdef BOOST_REGEX_MATCH_EXTRA
778 // Copy full capture info as well:
779 for(int i = 0; i < (int)in.size(); ++i)
781 if(in[i].captures().size())
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)
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;
795 template <class BidiIterator, class Allocator>
796 inline bool do_regex_match(BidiIterator first, BidiIterator last,
797 match_results<BidiIterator, Allocator>& m,
799 match_flag_type flags,
800 std::integral_constant<int, 4> const*)
802 return ::boost::regex_match(first, last, m, e, flags);
804 template <class BidiIterator, class Allocator>
805 bool do_regex_match(BidiIterator first, BidiIterator last,
806 match_results<BidiIterator, Allocator>& m,
808 match_flag_type flags,
809 std::integral_constant<int, 2> const*)
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;
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());
820 template <class BidiIterator, class Allocator>
821 bool do_regex_match(BidiIterator first, BidiIterator last,
822 match_results<BidiIterator, Allocator>& m,
824 match_flag_type flags,
825 std::integral_constant<int, 1> const*)
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;
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());
836 } // namespace BOOST_REGEX_DETAIL_NS
838 template <class BidiIterator, class Allocator>
839 inline bool u32regex_match(BidiIterator first, BidiIterator last,
840 match_results<BidiIterator, Allocator>& m,
842 match_flag_type flags = match_default)
844 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
846 inline bool u32regex_match(const UChar* p,
847 match_results<const UChar*>& m,
849 match_flag_type flags = match_default)
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));
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,
857 match_flag_type flags = match_default)
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));
862 inline bool u32regex_match(const char* p,
863 match_results<const char*>& m,
865 match_flag_type flags = match_default)
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));
869 inline bool u32regex_match(const unsigned char* p,
870 match_results<const unsigned char*>& m,
872 match_flag_type flags = match_default)
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));
876 inline bool u32regex_match(const std::string& s,
877 match_results<std::string::const_iterator>& m,
879 match_flag_type flags = match_default)
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));
883 #ifndef BOOST_NO_STD_WSTRING
884 inline bool u32regex_match(const std::wstring& s,
885 match_results<std::wstring::const_iterator>& m,
887 match_flag_type flags = match_default)
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));
892 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
893 match_results<const UChar*>& m,
895 match_flag_type flags = match_default)
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));
900 // regex_match overloads that do not return what matched:
902 template <class BidiIterator>
903 inline bool u32regex_match(BidiIterator first, BidiIterator last,
905 match_flag_type flags = match_default)
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));
910 inline bool u32regex_match(const UChar* p,
912 match_flag_type flags = match_default)
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));
917 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
918 inline bool u32regex_match(const wchar_t* p,
920 match_flag_type flags = match_default)
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));
926 inline bool u32regex_match(const char* p,
928 match_flag_type flags = match_default)
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));
933 inline bool u32regex_match(const unsigned char* p,
935 match_flag_type flags = match_default)
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));
940 inline bool u32regex_match(const std::string& s,
942 match_flag_type flags = match_default)
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));
947 #ifndef BOOST_NO_STD_WSTRING
948 inline bool u32regex_match(const std::wstring& s,
950 match_flag_type flags = match_default)
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));
956 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
958 match_flag_type flags = match_default)
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));
965 // regex_search overloads that widen the character type as appropriate:
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,
972 match_flag_type flags,
974 std::integral_constant<int, 4> const*)
976 return ::boost::regex_search(first, last, m, e, flags, base);
978 template <class BidiIterator, class Allocator>
979 bool do_regex_search(BidiIterator first, BidiIterator last,
980 match_results<BidiIterator, Allocator>& m,
982 match_flag_type flags,
984 std::integral_constant<int, 2> const*)
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;
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());
995 template <class BidiIterator, class Allocator>
996 bool do_regex_search(BidiIterator first, BidiIterator last,
997 match_results<BidiIterator, Allocator>& m,
999 match_flag_type flags,
1001 std::integral_constant<int, 1> const*)
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;
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());
1014 template <class BidiIterator, class Allocator>
1015 inline bool u32regex_search(BidiIterator first, BidiIterator last,
1016 match_results<BidiIterator, Allocator>& m,
1018 match_flag_type flags = match_default)
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));
1022 template <class BidiIterator, class Allocator>
1023 inline bool u32regex_search(BidiIterator first, BidiIterator last,
1024 match_results<BidiIterator, Allocator>& m,
1026 match_flag_type flags,
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));
1031 inline bool u32regex_search(const UChar* p,
1032 match_results<const UChar*>& m,
1034 match_flag_type flags = match_default)
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));
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,
1042 match_flag_type flags = match_default)
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));
1047 inline bool u32regex_search(const char* p,
1048 match_results<const char*>& m,
1050 match_flag_type flags = match_default)
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));
1054 inline bool u32regex_search(const unsigned char* p,
1055 match_results<const unsigned char*>& m,
1057 match_flag_type flags = match_default)
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));
1061 inline bool u32regex_search(const std::string& s,
1062 match_results<std::string::const_iterator>& m,
1064 match_flag_type flags = match_default)
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));
1068 #ifndef BOOST_NO_STD_WSTRING
1069 inline bool u32regex_search(const std::wstring& s,
1070 match_results<std::wstring::const_iterator>& m,
1072 match_flag_type flags = match_default)
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));
1077 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1078 match_results<const UChar*>& m,
1080 match_flag_type flags = match_default)
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));
1084 template <class BidiIterator>
1085 inline bool u32regex_search(BidiIterator first, BidiIterator last,
1087 match_flag_type flags = match_default)
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));
1092 inline bool u32regex_search(const UChar* p,
1094 match_flag_type flags = match_default)
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));
1099 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
1100 inline bool u32regex_search(const wchar_t* p,
1102 match_flag_type flags = match_default)
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));
1108 inline bool u32regex_search(const char* p,
1110 match_flag_type flags = match_default)
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));
1115 inline bool u32regex_search(const unsigned char* p,
1117 match_flag_type flags = match_default)
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));
1122 inline bool u32regex_search(const std::string& s,
1124 match_flag_type flags = match_default)
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));
1129 #ifndef BOOST_NO_STD_WSTRING
1130 inline bool u32regex_search(const std::wstring& s,
1132 match_flag_type flags = match_default)
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));
1138 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1140 match_flag_type flags = match_default)
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));
1147 // overloads for regex_replace with utf-8 and utf-16 data types:
1149 namespace BOOST_REGEX_DETAIL_NS{
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*)
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));
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*)
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));
1163 inline std::pair< I, I >
1164 make_utf32_seq(I i, I j, std::integral_constant<int, 4> const*)
1166 return std::pair< I, I >(i, j);
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*)
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));
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*)
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));
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*)
1186 return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
1188 template <class OutputIterator>
1189 inline OutputIterator make_utf32_out(OutputIterator o, std::integral_constant<int, 4> const*)
1193 template <class OutputIterator>
1194 inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, std::integral_constant<int, 2> const*)
1198 template <class OutputIterator>
1199 inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, std::integral_constant<int, 1> const*)
1204 template <class OutputIterator, class I1, class I2>
1205 OutputIterator do_regex_replace(OutputIterator out,
1206 std::pair<I1, I1> const& in,
1208 const std::pair<I2, I2>& fmt,
1209 match_flag_type flags
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);
1216 regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
1217 regex_iterator<I1, UChar32, icu_regex_traits> j;
1220 if(!(flags & regex_constants::format_no_copy))
1221 out = std::copy(in.first, in.second, out);
1225 I1 last_m = in.first;
1228 if(!(flags & regex_constants::format_no_copy))
1229 out = std::copy(i->prefix().first, i->prefix().second, out);
1231 out = ::boost::BOOST_REGEX_DETAIL_NS::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
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)
1239 if(!(flags & regex_constants::format_no_copy))
1240 out = std::copy(last_m, in.second, out);
1244 template <class BaseIterator>
1245 inline const BaseIterator& extract_output_base(const BaseIterator& b)
1249 template <class BaseIterator>
1250 inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
1254 template <class BaseIterator>
1255 inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
1259 } // BOOST_REGEX_DETAIL_NS
1261 template <class OutputIterator, class BidirectionalIterator, class charT>
1262 inline OutputIterator u32regex_replace(OutputIterator out,
1263 BidirectionalIterator first,
1264 BidirectionalIterator last,
1267 match_flag_type flags = match_default)
1269 return BOOST_REGEX_DETAIL_NS::extract_output_base
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)),
1275 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt, static_cast<std::integral_constant<int, sizeof(*fmt)> const*>(0)),
1280 template <class OutputIterator, class Iterator, class charT>
1281 inline OutputIterator u32regex_replace(OutputIterator out,
1285 const std::basic_string<charT>& fmt,
1286 match_flag_type flags = match_default)
1288 return BOOST_REGEX_DETAIL_NS::extract_output_base
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)),
1294 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<std::integral_constant<int, sizeof(charT)> const*>(0)),
1299 template <class OutputIterator, class Iterator>
1300 inline OutputIterator u32regex_replace(OutputIterator out,
1304 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1305 match_flag_type flags = match_default)
1307 return BOOST_REGEX_DETAIL_NS::extract_output_base
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)),
1313 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<std::integral_constant<int, 2> const*>(0)),
1318 template <class charT>
1319 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
1322 match_flag_type flags = match_default)
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);
1330 template <class charT>
1331 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
1333 const std::basic_string<charT>& fmt,
1334 match_flag_type flags = match_default)
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);
1342 namespace BOOST_REGEX_DETAIL_NS{
1344 class unicode_string_out_iterator
1346 U_NAMESPACE_QUALIFIER UnicodeString* out;
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)
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;
1366 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1369 match_flag_type flags = match_default)
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);
1377 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1379 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1380 match_flag_type flags = match_default)
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)),
1388 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<std::integral_constant<int, 2> const*>(0)),
1393 } // namespace boost.
1395 #ifdef BOOST_REGEX_MSVC
1396 #pragma warning (pop)
1399 #include <boost/regex/v5/u32regex_iterator.hpp>
1400 #include <boost/regex/v5/u32regex_token_iterator.hpp>