Update contrib.
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_HPP
20 #define BOOST_REGEX_ICU_HPP
22 #include <unicode/utypes.h>
23 #include <unicode/uchar.h>
24 #include <unicode/coll.h>
25 #include <boost/regex.hpp>
26 #include <boost/regex/pending/unicode_iterator.hpp>
27 #include <boost/mpl/int_fwd.hpp>
36 // Implementation details:
38 class BOOST_REGEX_DECL icu_regex_traits_implementation
40 typedef UChar32 char_type;
41 typedef std::size_t size_type;
42 typedef std::vector<char_type> string_type;
43 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
44 typedef boost::uint_least32_t char_class_type;
46 icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
49 UErrorCode success = U_ZERO_ERROR;
50 m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
51 if(U_SUCCESS(success) == 0)
53 m_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::IDENTICAL);
54 success = U_ZERO_ERROR;
55 m_primary_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
56 if(U_SUCCESS(success) == 0)
58 m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
60 U_NAMESPACE_QUALIFIER Locale getloc()const
64 string_type do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const;
65 string_type transform(const char_type* p1, const char_type* p2) const
67 return do_transform(p1, p2, m_collator.get());
69 string_type transform_primary(const char_type* p1, const char_type* p2) const
71 return do_transform(p1, p2, m_primary_collator.get());
76 std::runtime_error e("Could not initialize ICU resources");
77 boost::throw_exception(e);
79 U_NAMESPACE_QUALIFIER Locale m_locale; // The ICU locale that we're using
80 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_collator; // The full collation object
81 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_primary_collator; // The primary collation object
84 inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
86 return boost::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
91 class BOOST_REGEX_DECL icu_regex_traits
94 typedef UChar32 char_type;
95 typedef std::size_t size_type;
96 typedef std::vector<char_type> string_type;
97 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
98 #ifdef BOOST_NO_INT64_T
99 typedef std::bitset<64> char_class_type;
101 typedef boost::uint64_t char_class_type;
104 struct boost_extensions_tag{};
107 : m_pimpl(re_detail::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
110 static size_type length(const char_type* p);
112 ::boost::regex_constants::syntax_type syntax_type(char_type c)const
114 return ((c < 0x7f) && (c > 0)) ? re_detail::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
116 ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
118 return ((c < 0x7f) && (c > 0)) ? re_detail::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
120 char_type translate(char_type c) const
124 char_type translate_nocase(char_type c) const
126 return ::u_tolower(c);
128 char_type translate(char_type c, bool icase) const
130 return icase ? translate_nocase(c) : translate(c);
132 char_type tolower(char_type c) const
134 return ::u_tolower(c);
136 char_type toupper(char_type c) const
138 return ::u_toupper(c);
140 string_type transform(const char_type* p1, const char_type* p2) const
142 return m_pimpl->transform(p1, p2);
144 string_type transform_primary(const char_type* p1, const char_type* p2) const
146 return m_pimpl->transform_primary(p1, p2);
148 char_class_type lookup_classname(const char_type* p1, const char_type* p2) const;
149 string_type lookup_collatename(const char_type* p1, const char_type* p2) const;
150 bool isctype(char_type c, char_class_type f) const;
151 int toi(const char_type*& p1, const char_type* p2, int radix)const
153 return re_detail::global_toi(p1, p2, radix, *this);
155 int value(char_type c, int radix)const
157 return u_digit(c, static_cast< ::int8_t>(radix));
159 locale_type imbue(locale_type l)
161 locale_type result(m_pimpl->getloc());
162 m_pimpl = re_detail::get_icu_regex_traits_implementation(l);
165 locale_type getloc()const
167 return locale_type();
169 std::string error_string(::boost::regex_constants::error_type n) const
171 return re_detail::get_default_error_string(n);
174 icu_regex_traits(const icu_regex_traits&);
175 icu_regex_traits& operator=(const icu_regex_traits&);
178 // define the bitmasks offsets we need for additional character properties:
181 offset_blank = U_CHAR_CATEGORY_COUNT,
182 offset_space = U_CHAR_CATEGORY_COUNT+1,
183 offset_xdigit = U_CHAR_CATEGORY_COUNT+2,
184 offset_underscore = U_CHAR_CATEGORY_COUNT+3,
185 offset_unicode = U_CHAR_CATEGORY_COUNT+4,
186 offset_any = U_CHAR_CATEGORY_COUNT+5,
187 offset_ascii = U_CHAR_CATEGORY_COUNT+6
191 // and now the masks:
193 static const char_class_type mask_blank;
194 static const char_class_type mask_space;
195 static const char_class_type mask_xdigit;
196 static const char_class_type mask_underscore;
197 static const char_class_type mask_unicode;
198 static const char_class_type mask_any;
199 static const char_class_type mask_ascii;
201 static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
203 boost::shared_ptr< ::boost::re_detail::icu_regex_traits_implementation> m_pimpl;
209 // template instances:
211 #define BOOST_REGEX_CHAR_T UChar32
212 #undef BOOST_REGEX_TRAITS_T
213 #define BOOST_REGEX_TRAITS_T , icu_regex_traits
214 #define BOOST_REGEX_ICU_INSTANCES
215 #ifdef BOOST_REGEX_ICU_INSTANTIATE
216 # define BOOST_REGEX_INSTANTIATE
218 #include <boost/regex/v4/instances.hpp>
219 #undef BOOST_REGEX_CHAR_T
220 #undef BOOST_REGEX_TRAITS_T
221 #undef BOOST_REGEX_ICU_INSTANCES
222 #ifdef BOOST_REGEX_INSTANTIATE
223 # undef BOOST_REGEX_INSTANTIATE
229 typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
230 typedef match_results<const ::UChar32*> u32match;
231 typedef match_results<const ::UChar*> u16match;
234 // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
238 #if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
239 template <class InputIterator>
240 inline u32regex do_make_u32regex(InputIterator i,
242 boost::regex_constants::syntax_option_type opt,
243 const boost::mpl::int_<1>*)
245 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
246 return u32regex(conv_type(i), conv_type(j), opt);
249 template <class InputIterator>
250 inline u32regex do_make_u32regex(InputIterator i,
252 boost::regex_constants::syntax_option_type opt,
253 const boost::mpl::int_<2>*)
255 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
256 return u32regex(conv_type(i), conv_type(j), opt);
259 template <class InputIterator>
260 inline u32regex do_make_u32regex(InputIterator i,
262 boost::regex_constants::syntax_option_type opt,
263 const boost::mpl::int_<4>*)
265 return u32regex(i, j, opt);
268 template <class InputIterator>
269 inline u32regex do_make_u32regex(InputIterator i,
271 boost::regex_constants::syntax_option_type opt,
272 const boost::mpl::int_<1>*)
274 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
275 typedef std::vector<UChar32> vector_type;
277 conv_type a(i), b(j);
284 return u32regex(&*v.begin(), v.size(), opt);
285 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
288 template <class InputIterator>
289 inline u32regex do_make_u32regex(InputIterator i,
291 boost::regex_constants::syntax_option_type opt,
292 const boost::mpl::int_<2>*)
294 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
295 typedef std::vector<UChar32> vector_type;
297 conv_type a(i), b(j);
304 return u32regex(&*v.begin(), v.size(), opt);
305 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
308 template <class InputIterator>
309 inline u32regex do_make_u32regex(InputIterator i,
311 boost::regex_constants::syntax_option_type opt,
312 const boost::mpl::int_<4>*)
314 typedef std::vector<UCHAR32> vector_type;
318 v.push_back((UCHAR32)(*i));
322 return u32regex(&*v.begin(), v.size(), opt);
323 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
329 // Construction from an iterator pair:
331 template <class InputIterator>
332 inline u32regex make_u32regex(InputIterator i,
334 boost::regex_constants::syntax_option_type opt)
336 return re_detail::do_make_u32regex(i, j, opt, static_cast<boost::mpl::int_<sizeof(*i)> const*>(0));
339 // construction from UTF-8 nul-terminated strings:
341 inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
343 return re_detail::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<boost::mpl::int_<1> const*>(0));
345 inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
347 return re_detail::do_make_u32regex(p, p + std::strlen(reinterpret_cast<const char*>(p)), opt, static_cast<boost::mpl::int_<1> const*>(0));
350 // construction from UTF-16 nul-terminated strings:
352 #ifndef BOOST_NO_WREGEX
353 inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
355 return re_detail::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<boost::mpl::int_<sizeof(wchar_t)> const*>(0));
358 #ifndef U_WCHAR_IS_UTF16
359 inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
361 return re_detail::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
365 // construction from basic_string class-template:
367 template<class C, class T, class A>
368 inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
370 return re_detail::do_make_u32regex(s.begin(), s.end(), opt, static_cast<boost::mpl::int_<sizeof(C)> const*>(0));
373 // Construction from ICU string type:
375 inline u32regex make_u32regex(const UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
377 return re_detail::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
381 // regex_match overloads that widen the character type as appropriate:
384 template<class MR1, class MR2>
385 void copy_results(MR1& out, MR2 const& in)
387 // copy results from an adapted MR2 match_results:
388 out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
389 out.set_base(in.base().base());
390 for(int i = 0; i < (int)in.size(); ++i)
394 out.set_first(in[i].first.base(), i);
395 out.set_second(in[i].second.base(), i);
400 template <class BidiIterator, class Allocator>
401 inline bool do_regex_match(BidiIterator first, BidiIterator last,
402 match_results<BidiIterator, Allocator>& m,
404 match_flag_type flags,
405 boost::mpl::int_<4> const*)
407 return ::boost::regex_match(first, last, m, e, flags);
409 template <class BidiIterator, class Allocator>
410 bool do_regex_match(BidiIterator first, BidiIterator last,
411 match_results<BidiIterator, Allocator>& m,
413 match_flag_type flags,
414 boost::mpl::int_<2> const*)
416 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
417 typedef match_results<conv_type> match_type;
418 typedef typename match_type::allocator_type alloc_type;
420 bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
421 // copy results across to m:
422 if(result) copy_results(m, what);
425 template <class BidiIterator, class Allocator>
426 bool do_regex_match(BidiIterator first, BidiIterator last,
427 match_results<BidiIterator, Allocator>& m,
429 match_flag_type flags,
430 boost::mpl::int_<1> const*)
432 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
433 typedef match_results<conv_type> match_type;
434 typedef typename match_type::allocator_type alloc_type;
436 bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
437 // copy results across to m:
438 if(result) copy_results(m, what);
441 } // namespace re_detail
443 template <class BidiIterator, class Allocator>
444 inline bool u32regex_match(BidiIterator first, BidiIterator last,
445 match_results<BidiIterator, Allocator>& m,
447 match_flag_type flags = match_default)
449 return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
451 inline bool u32regex_match(const UChar* p,
452 match_results<const UChar*>& m,
454 match_flag_type flags = match_default)
456 return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
458 #if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
459 inline bool u32regex_match(const wchar_t* p,
460 match_results<const wchar_t*>& m,
462 match_flag_type flags = match_default)
464 return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
467 inline bool u32regex_match(const char* p,
468 match_results<const char*>& m,
470 match_flag_type flags = match_default)
472 return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
474 inline bool u32regex_match(const unsigned char* p,
475 match_results<const unsigned char*>& m,
477 match_flag_type flags = match_default)
479 return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
481 inline bool u32regex_match(const std::string& s,
482 match_results<std::string::const_iterator>& m,
484 match_flag_type flags = match_default)
486 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
488 #ifndef BOOST_NO_STD_WSTRING
489 inline bool u32regex_match(const std::wstring& s,
490 match_results<std::wstring::const_iterator>& m,
492 match_flag_type flags = match_default)
494 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
497 inline bool u32regex_match(const UnicodeString& s,
498 match_results<const UChar*>& m,
500 match_flag_type flags = match_default)
502 return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
505 // regex_match overloads that do not return what matched:
507 template <class BidiIterator>
508 inline bool u32regex_match(BidiIterator first, BidiIterator last,
510 match_flag_type flags = match_default)
512 match_results<BidiIterator> m;
513 return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
515 inline bool u32regex_match(const UChar* p,
517 match_flag_type flags = match_default)
519 match_results<const UChar*> m;
520 return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
522 #if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
523 inline bool u32regex_match(const wchar_t* p,
525 match_flag_type flags = match_default)
527 match_results<const wchar_t*> m;
528 return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
531 inline bool u32regex_match(const char* p,
533 match_flag_type flags = match_default)
535 match_results<const char*> m;
536 return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
538 inline bool u32regex_match(const unsigned char* p,
540 match_flag_type flags = match_default)
542 match_results<const unsigned char*> m;
543 return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
545 inline bool u32regex_match(const std::string& s,
547 match_flag_type flags = match_default)
549 match_results<std::string::const_iterator> m;
550 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
552 #ifndef BOOST_NO_STD_WSTRING
553 inline bool u32regex_match(const std::wstring& s,
555 match_flag_type flags = match_default)
557 match_results<std::wstring::const_iterator> m;
558 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
561 inline bool u32regex_match(const UnicodeString& s,
563 match_flag_type flags = match_default)
565 match_results<const UChar*> m;
566 return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
570 // regex_search overloads that widen the character type as appropriate:
573 template <class BidiIterator, class Allocator>
574 inline bool do_regex_search(BidiIterator first, BidiIterator last,
575 match_results<BidiIterator, Allocator>& m,
577 match_flag_type flags,
579 boost::mpl::int_<4> const*)
581 return ::boost::regex_search(first, last, m, e, flags, base);
583 template <class BidiIterator, class Allocator>
584 bool do_regex_search(BidiIterator first, BidiIterator last,
585 match_results<BidiIterator, Allocator>& m,
587 match_flag_type flags,
589 boost::mpl::int_<2> const*)
591 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
592 typedef match_results<conv_type> match_type;
593 typedef typename match_type::allocator_type alloc_type;
595 bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags, conv_type(base));
596 // copy results across to m:
597 if(result) copy_results(m, what);
600 template <class BidiIterator, class Allocator>
601 bool do_regex_search(BidiIterator first, BidiIterator last,
602 match_results<BidiIterator, Allocator>& m,
604 match_flag_type flags,
606 boost::mpl::int_<1> const*)
608 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
609 typedef match_results<conv_type> match_type;
610 typedef typename match_type::allocator_type alloc_type;
612 bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags, conv_type(base));
613 // copy results across to m:
614 if(result) copy_results(m, what);
619 template <class BidiIterator, class Allocator>
620 inline bool u32regex_search(BidiIterator first, BidiIterator last,
621 match_results<BidiIterator, Allocator>& m,
623 match_flag_type flags = match_default)
625 return re_detail::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
627 template <class BidiIterator, class Allocator>
628 inline bool u32regex_search(BidiIterator first, BidiIterator last,
629 match_results<BidiIterator, Allocator>& m,
631 match_flag_type flags,
634 return re_detail::do_regex_search(first, last, m, e, flags, base, static_cast<mpl::int_<sizeof(*first)> const*>(0));
636 inline bool u32regex_search(const UChar* p,
637 match_results<const UChar*>& m,
639 match_flag_type flags = match_default)
641 return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
643 #if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
644 inline bool u32regex_search(const wchar_t* p,
645 match_results<const wchar_t*>& m,
647 match_flag_type flags = match_default)
649 return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
652 inline bool u32regex_search(const char* p,
653 match_results<const char*>& m,
655 match_flag_type flags = match_default)
657 return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
659 inline bool u32regex_search(const unsigned char* p,
660 match_results<const unsigned char*>& m,
662 match_flag_type flags = match_default)
664 return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
666 inline bool u32regex_search(const std::string& s,
667 match_results<std::string::const_iterator>& m,
669 match_flag_type flags = match_default)
671 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
673 #ifndef BOOST_NO_STD_WSTRING
674 inline bool u32regex_search(const std::wstring& s,
675 match_results<std::wstring::const_iterator>& m,
677 match_flag_type flags = match_default)
679 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
682 inline bool u32regex_search(const UnicodeString& s,
683 match_results<const UChar*>& m,
685 match_flag_type flags = match_default)
687 return re_detail::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
689 template <class BidiIterator>
690 inline bool u32regex_search(BidiIterator first, BidiIterator last,
692 match_flag_type flags = match_default)
694 match_results<BidiIterator> m;
695 return re_detail::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
697 inline bool u32regex_search(const UChar* p,
699 match_flag_type flags = match_default)
701 match_results<const UChar*> m;
702 return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
704 #if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
705 inline bool u32regex_search(const wchar_t* p,
707 match_flag_type flags = match_default)
709 match_results<const wchar_t*> m;
710 return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
713 inline bool u32regex_search(const char* p,
715 match_flag_type flags = match_default)
717 match_results<const char*> m;
718 return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
720 inline bool u32regex_search(const unsigned char* p,
722 match_flag_type flags = match_default)
724 match_results<const unsigned char*> m;
725 return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
727 inline bool u32regex_search(const std::string& s,
729 match_flag_type flags = match_default)
731 match_results<std::string::const_iterator> m;
732 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
734 #ifndef BOOST_NO_STD_WSTRING
735 inline bool u32regex_search(const std::wstring& s,
737 match_flag_type flags = match_default)
739 match_results<std::wstring::const_iterator> m;
740 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
743 inline bool u32regex_search(const UnicodeString& s,
745 match_flag_type flags = match_default)
747 match_results<const UChar*> m;
748 return re_detail::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
752 // overloads for regex_replace with utf-8 and utf-16 data types:
756 inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
757 make_utf32_seq(I i, I j, mpl::int_<1> const*)
759 return std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >(boost::u8_to_u32_iterator<I>(i), boost::u8_to_u32_iterator<I>(j));
762 inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
763 make_utf32_seq(I i, I j, mpl::int_<2> const*)
765 return std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >(boost::u16_to_u32_iterator<I>(i), boost::u16_to_u32_iterator<I>(j));
768 inline std::pair< I, I >
769 make_utf32_seq(I i, I j, mpl::int_<4> const*)
771 return std::pair< I, I >(i, j);
773 template <class charT>
774 inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
775 make_utf32_seq(const charT* p, mpl::int_<1> const*)
777 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), boost::u8_to_u32_iterator<const charT*>(p+std::strlen((const char*)p)));
779 template <class charT>
780 inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
781 make_utf32_seq(const charT* p, mpl::int_<2> const*)
783 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), boost::u16_to_u32_iterator<const charT*>(p+u_strlen((const UChar*)p)));
785 template <class charT>
786 inline std::pair< const charT*, const charT* >
787 make_utf32_seq(const charT* p, mpl::int_<4> const*)
789 return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
791 template <class OutputIterator>
792 inline OutputIterator make_utf32_out(OutputIterator o, mpl::int_<4> const*)
796 template <class OutputIterator>
797 inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<2> const*)
801 template <class OutputIterator>
802 inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<1> const*)
807 template <class OutputIterator, class I1, class I2>
808 OutputIterator do_regex_replace(OutputIterator out,
809 std::pair<I1, I1> const& in,
811 const std::pair<I2, I2>& fmt,
812 match_flag_type flags
815 // unfortunately we have to copy the format string in order to pass in onward:
816 std::vector<UChar32> f;
817 #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
818 f.assign(fmt.first, fmt.second);
822 while(pos != fmt.second)
826 regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
827 regex_iterator<I1, UChar32, icu_regex_traits> j;
830 if(!(flags & regex_constants::format_no_copy))
831 out = re_detail::copy(in.first, in.second, out);
835 I1 last_m = in.first;
838 if(!(flags & regex_constants::format_no_copy))
839 out = re_detail::copy(i->prefix().first, i->prefix().second, out);
841 out = ::boost::re_detail::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
843 out = ::boost::re_detail::regex_format_imp(out, *i, static_cast<UChar32 const*>(0), static_cast<UChar32 const*>(0), flags, e.get_traits());
844 last_m = (*i)[0].second;
845 if(flags & regex_constants::format_first_only)
849 if(!(flags & regex_constants::format_no_copy))
850 out = re_detail::copy(last_m, in.second, out);
854 template <class BaseIterator>
855 inline const BaseIterator& extract_output_base(const BaseIterator& b)
859 template <class BaseIterator>
860 inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
864 template <class BaseIterator>
865 inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
871 template <class OutputIterator, class BidirectionalIterator, class charT>
872 inline OutputIterator u32regex_replace(OutputIterator out,
873 BidirectionalIterator first,
874 BidirectionalIterator last,
877 match_flag_type flags = match_default)
879 return re_detail::extract_output_base
880 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
884 re_detail::do_regex_replace(
885 re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
886 re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
888 re_detail::make_utf32_seq(fmt, static_cast<mpl::int_<sizeof(*fmt)> const*>(0)),
893 template <class OutputIterator, class Iterator, class charT>
894 inline OutputIterator u32regex_replace(OutputIterator out,
898 const std::basic_string<charT>& fmt,
899 match_flag_type flags = match_default)
901 return re_detail::extract_output_base
902 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
906 re_detail::do_regex_replace(
907 re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
908 re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
910 re_detail::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<mpl::int_<sizeof(charT)> const*>(0)),
915 template <class OutputIterator, class Iterator>
916 inline OutputIterator u32regex_replace(OutputIterator out,
920 const UnicodeString& fmt,
921 match_flag_type flags = match_default)
923 return re_detail::extract_output_base
924 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
928 re_detail::do_regex_replace(
929 re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
930 re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
932 re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
937 template <class charT>
938 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
941 match_flag_type flags = match_default)
943 std::basic_string<charT> result;
944 re_detail::string_out_iterator<std::basic_string<charT> > i(result);
945 u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
949 template <class charT>
950 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
952 const std::basic_string<charT>& fmt,
953 match_flag_type flags = match_default)
955 std::basic_string<charT> result;
956 re_detail::string_out_iterator<std::basic_string<charT> > i(result);
957 u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
963 class unicode_string_out_iterator
967 unicode_string_out_iterator(UnicodeString& s) : out(&s) {}
968 unicode_string_out_iterator& operator++() { return *this; }
969 unicode_string_out_iterator& operator++(int) { return *this; }
970 unicode_string_out_iterator& operator*() { return *this; }
971 unicode_string_out_iterator& operator=(UChar v)
976 typedef std::ptrdiff_t difference_type;
977 typedef UChar value_type;
978 typedef value_type* pointer;
979 typedef value_type& reference;
980 typedef std::output_iterator_tag iterator_category;
985 inline UnicodeString u32regex_replace(const UnicodeString& s,
988 match_flag_type flags = match_default)
990 UnicodeString result;
991 re_detail::unicode_string_out_iterator i(result);
992 u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
996 inline UnicodeString u32regex_replace(const UnicodeString& s,
998 const UnicodeString& fmt,
999 match_flag_type flags = match_default)
1001 UnicodeString result;
1002 re_detail::unicode_string_out_iterator i(result);
1003 re_detail::do_regex_replace(
1004 re_detail::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)),
1005 re_detail::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<mpl::int_<2> const*>(0)),
1007 re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
1012 } // namespace boost.
1014 #include <boost/regex/v4/u32regex_iterator.hpp>
1015 #include <boost/regex/v4/u32regex_token_iterator.hpp>