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>
31 #pragma warning (push)
32 #pragma warning (disable: 4251)
40 // Implementation details:
42 class BOOST_REGEX_DECL 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 boost::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;
69 string_type transform(const char_type* p1, const char_type* p2) const
71 return do_transform(p1, p2, m_collator.get());
73 string_type transform_primary(const char_type* p1, const char_type* p2) const
75 return do_transform(p1, p2, m_primary_collator.get());
80 std::runtime_error e("Could not initialize ICU resources");
81 boost::throw_exception(e);
83 U_NAMESPACE_QUALIFIER Locale m_locale; // The ICU locale that we're using
84 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_collator; // The full collation object
85 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_primary_collator; // The primary collation object
88 inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
90 return boost::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
95 class BOOST_REGEX_DECL icu_regex_traits
98 typedef UChar32 char_type;
99 typedef std::size_t size_type;
100 typedef std::vector<char_type> string_type;
101 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
102 #ifdef BOOST_NO_INT64_T
103 typedef std::bitset<64> char_class_type;
105 typedef boost::uint64_t char_class_type;
108 struct boost_extensions_tag{};
111 : m_pimpl(re_detail::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
114 static size_type length(const char_type* p);
116 ::boost::regex_constants::syntax_type syntax_type(char_type c)const
118 return ((c < 0x7f) && (c > 0)) ? re_detail::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
120 ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
122 return ((c < 0x7f) && (c > 0)) ? re_detail::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
124 char_type translate(char_type c) const
128 char_type translate_nocase(char_type c) const
130 return ::u_tolower(c);
132 char_type translate(char_type c, bool icase) const
134 return icase ? translate_nocase(c) : translate(c);
136 char_type tolower(char_type c) const
138 return ::u_tolower(c);
140 char_type toupper(char_type c) const
142 return ::u_toupper(c);
144 string_type transform(const char_type* p1, const char_type* p2) const
146 return m_pimpl->transform(p1, p2);
148 string_type transform_primary(const char_type* p1, const char_type* p2) const
150 return m_pimpl->transform_primary(p1, p2);
152 char_class_type lookup_classname(const char_type* p1, const char_type* p2) const;
153 string_type lookup_collatename(const char_type* p1, const char_type* p2) const;
154 bool isctype(char_type c, char_class_type f) const;
155 int toi(const char_type*& p1, const char_type* p2, int radix)const
157 return re_detail::global_toi(p1, p2, radix, *this);
159 int value(char_type c, int radix)const
161 return u_digit(c, static_cast< ::int8_t>(radix));
163 locale_type imbue(locale_type l)
165 locale_type result(m_pimpl->getloc());
166 m_pimpl = re_detail::get_icu_regex_traits_implementation(l);
169 locale_type getloc()const
171 return locale_type();
173 std::string error_string(::boost::regex_constants::error_type n) const
175 return re_detail::get_default_error_string(n);
178 icu_regex_traits(const icu_regex_traits&);
179 icu_regex_traits& operator=(const icu_regex_traits&);
182 // define the bitmasks offsets we need for additional character properties:
185 offset_blank = U_CHAR_CATEGORY_COUNT,
186 offset_space = U_CHAR_CATEGORY_COUNT+1,
187 offset_xdigit = U_CHAR_CATEGORY_COUNT+2,
188 offset_underscore = U_CHAR_CATEGORY_COUNT+3,
189 offset_unicode = U_CHAR_CATEGORY_COUNT+4,
190 offset_any = U_CHAR_CATEGORY_COUNT+5,
191 offset_ascii = U_CHAR_CATEGORY_COUNT+6,
192 offset_horizontal = U_CHAR_CATEGORY_COUNT+7,
193 offset_vertical = U_CHAR_CATEGORY_COUNT+8
197 // and now the masks:
199 static const char_class_type mask_blank;
200 static const char_class_type mask_space;
201 static const char_class_type mask_xdigit;
202 static const char_class_type mask_underscore;
203 static const char_class_type mask_unicode;
204 static const char_class_type mask_any;
205 static const char_class_type mask_ascii;
206 static const char_class_type mask_horizontal;
207 static const char_class_type mask_vertical;
209 static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
211 boost::shared_ptr< ::boost::re_detail::icu_regex_traits_implementation> m_pimpl;
217 // template instances:
219 #define BOOST_REGEX_CHAR_T UChar32
220 #undef BOOST_REGEX_TRAITS_T
221 #define BOOST_REGEX_TRAITS_T , icu_regex_traits
222 #define BOOST_REGEX_ICU_INSTANCES
223 #ifdef BOOST_REGEX_ICU_INSTANTIATE
224 # define BOOST_REGEX_INSTANTIATE
226 #include <boost/regex/v4/instances.hpp>
227 #undef BOOST_REGEX_CHAR_T
228 #undef BOOST_REGEX_TRAITS_T
229 #undef BOOST_REGEX_ICU_INSTANCES
230 #ifdef BOOST_REGEX_INSTANTIATE
231 # undef BOOST_REGEX_INSTANTIATE
237 typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
238 typedef match_results<const ::UChar32*> u32match;
239 typedef match_results<const ::UChar*> u16match;
242 // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
246 #if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
247 template <class InputIterator>
248 inline u32regex do_make_u32regex(InputIterator i,
250 boost::regex_constants::syntax_option_type opt,
251 const boost::mpl::int_<1>*)
253 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
254 return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
257 template <class InputIterator>
258 inline u32regex do_make_u32regex(InputIterator i,
260 boost::regex_constants::syntax_option_type opt,
261 const boost::mpl::int_<2>*)
263 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
264 return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
267 template <class InputIterator>
268 inline u32regex do_make_u32regex(InputIterator i,
270 boost::regex_constants::syntax_option_type opt,
271 const boost::mpl::int_<4>*)
273 return u32regex(i, j, opt);
276 template <class InputIterator>
277 inline u32regex do_make_u32regex(InputIterator i,
279 boost::regex_constants::syntax_option_type opt,
280 const boost::mpl::int_<1>*)
282 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
283 typedef std::vector<UChar32> vector_type;
285 conv_type a(i, i, j), b(j, i, j);
292 return u32regex(&*v.begin(), v.size(), opt);
293 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
296 template <class InputIterator>
297 inline u32regex do_make_u32regex(InputIterator i,
299 boost::regex_constants::syntax_option_type opt,
300 const boost::mpl::int_<2>*)
302 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
303 typedef std::vector<UChar32> vector_type;
305 conv_type a(i, i, j), b(j, i, j);
312 return u32regex(&*v.begin(), v.size(), opt);
313 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
316 template <class InputIterator>
317 inline u32regex do_make_u32regex(InputIterator i,
319 boost::regex_constants::syntax_option_type opt,
320 const boost::mpl::int_<4>*)
322 typedef std::vector<UChar32> vector_type;
326 v.push_back((UChar32)(*i));
330 return u32regex(&*v.begin(), v.size(), opt);
331 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
337 // Construction from an iterator pair:
339 template <class InputIterator>
340 inline u32regex make_u32regex(InputIterator i,
342 boost::regex_constants::syntax_option_type opt)
344 return re_detail::do_make_u32regex(i, j, opt, static_cast<boost::mpl::int_<sizeof(*i)> const*>(0));
347 // construction from UTF-8 nul-terminated strings:
349 inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
351 return re_detail::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<boost::mpl::int_<1> const*>(0));
353 inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
355 return re_detail::do_make_u32regex(p, p + std::strlen(reinterpret_cast<const char*>(p)), opt, static_cast<boost::mpl::int_<1> const*>(0));
358 // construction from UTF-16 nul-terminated strings:
360 #ifndef BOOST_NO_WREGEX
361 inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
363 return re_detail::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<boost::mpl::int_<sizeof(wchar_t)> const*>(0));
366 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
367 inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
369 return re_detail::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
373 // construction from basic_string class-template:
375 template<class C, class T, class A>
376 inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
378 return re_detail::do_make_u32regex(s.begin(), s.end(), opt, static_cast<boost::mpl::int_<sizeof(C)> const*>(0));
381 // Construction from ICU string type:
383 inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
385 return re_detail::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
389 // regex_match overloads that widen the character type as appropriate:
392 template<class MR1, class MR2>
393 void copy_results(MR1& out, MR2 const& in)
395 // copy results from an adapted MR2 match_results:
396 out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
397 out.set_base(in.base().base());
398 for(int i = 0; i < (int)in.size(); ++i)
402 out.set_first(in[i].first.base(), i);
403 out.set_second(in[i].second.base(), i);
408 template <class BidiIterator, class Allocator>
409 inline bool do_regex_match(BidiIterator first, BidiIterator last,
410 match_results<BidiIterator, Allocator>& m,
412 match_flag_type flags,
413 boost::mpl::int_<4> const*)
415 return ::boost::regex_match(first, last, m, e, flags);
417 template <class BidiIterator, class Allocator>
418 bool do_regex_match(BidiIterator first, BidiIterator last,
419 match_results<BidiIterator, Allocator>& m,
421 match_flag_type flags,
422 boost::mpl::int_<2> const*)
424 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
425 typedef match_results<conv_type> match_type;
426 typedef typename match_type::allocator_type alloc_type;
428 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
429 // copy results across to m:
430 if(result) copy_results(m, what);
433 template <class BidiIterator, class Allocator>
434 bool do_regex_match(BidiIterator first, BidiIterator last,
435 match_results<BidiIterator, Allocator>& m,
437 match_flag_type flags,
438 boost::mpl::int_<1> const*)
440 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
441 typedef match_results<conv_type> match_type;
442 typedef typename match_type::allocator_type alloc_type;
444 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
445 // copy results across to m:
446 if(result) copy_results(m, what);
449 } // namespace re_detail
451 template <class BidiIterator, class Allocator>
452 inline bool u32regex_match(BidiIterator first, BidiIterator last,
453 match_results<BidiIterator, Allocator>& m,
455 match_flag_type flags = match_default)
457 return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
459 inline bool u32regex_match(const UChar* p,
460 match_results<const UChar*>& m,
462 match_flag_type flags = match_default)
464 return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
466 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
467 inline bool u32regex_match(const wchar_t* p,
468 match_results<const wchar_t*>& m,
470 match_flag_type flags = match_default)
472 return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
475 inline bool u32regex_match(const char* p,
476 match_results<const char*>& m,
478 match_flag_type flags = match_default)
480 return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
482 inline bool u32regex_match(const unsigned char* p,
483 match_results<const unsigned char*>& m,
485 match_flag_type flags = match_default)
487 return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
489 inline bool u32regex_match(const std::string& s,
490 match_results<std::string::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_<1> const*>(0));
496 #ifndef BOOST_NO_STD_WSTRING
497 inline bool u32regex_match(const std::wstring& s,
498 match_results<std::wstring::const_iterator>& m,
500 match_flag_type flags = match_default)
502 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
505 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
506 match_results<const UChar*>& m,
508 match_flag_type flags = match_default)
510 return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
513 // regex_match overloads that do not return what matched:
515 template <class BidiIterator>
516 inline bool u32regex_match(BidiIterator first, BidiIterator last,
518 match_flag_type flags = match_default)
520 match_results<BidiIterator> m;
521 return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
523 inline bool u32regex_match(const UChar* p,
525 match_flag_type flags = match_default)
527 match_results<const UChar*> m;
528 return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
530 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
531 inline bool u32regex_match(const wchar_t* p,
533 match_flag_type flags = match_default)
535 match_results<const wchar_t*> m;
536 return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
539 inline bool u32regex_match(const char* p,
541 match_flag_type flags = match_default)
543 match_results<const char*> m;
544 return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
546 inline bool u32regex_match(const unsigned char* p,
548 match_flag_type flags = match_default)
550 match_results<const unsigned char*> m;
551 return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
553 inline bool u32regex_match(const std::string& s,
555 match_flag_type flags = match_default)
557 match_results<std::string::const_iterator> m;
558 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
560 #ifndef BOOST_NO_STD_WSTRING
561 inline bool u32regex_match(const std::wstring& s,
563 match_flag_type flags = match_default)
565 match_results<std::wstring::const_iterator> m;
566 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
569 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
571 match_flag_type flags = match_default)
573 match_results<const UChar*> m;
574 return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
578 // regex_search overloads that widen the character type as appropriate:
581 template <class BidiIterator, class Allocator>
582 inline bool do_regex_search(BidiIterator first, BidiIterator last,
583 match_results<BidiIterator, Allocator>& m,
585 match_flag_type flags,
587 boost::mpl::int_<4> const*)
589 return ::boost::regex_search(first, last, m, e, flags, base);
591 template <class BidiIterator, class Allocator>
592 bool do_regex_search(BidiIterator first, BidiIterator last,
593 match_results<BidiIterator, Allocator>& m,
595 match_flag_type flags,
597 boost::mpl::int_<2> const*)
599 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
600 typedef match_results<conv_type> match_type;
601 typedef typename match_type::allocator_type alloc_type;
603 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
604 // copy results across to m:
605 if(result) copy_results(m, what);
608 template <class BidiIterator, class Allocator>
609 bool do_regex_search(BidiIterator first, BidiIterator last,
610 match_results<BidiIterator, Allocator>& m,
612 match_flag_type flags,
614 boost::mpl::int_<1> const*)
616 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
617 typedef match_results<conv_type> match_type;
618 typedef typename match_type::allocator_type alloc_type;
620 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
621 // copy results across to m:
622 if(result) copy_results(m, what);
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 = match_default)
633 return re_detail::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
635 template <class BidiIterator, class Allocator>
636 inline bool u32regex_search(BidiIterator first, BidiIterator last,
637 match_results<BidiIterator, Allocator>& m,
639 match_flag_type flags,
642 return re_detail::do_regex_search(first, last, m, e, flags, base, static_cast<mpl::int_<sizeof(*first)> const*>(0));
644 inline bool u32regex_search(const UChar* p,
645 match_results<const UChar*>& m,
647 match_flag_type flags = match_default)
649 return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
651 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
652 inline bool u32regex_search(const wchar_t* p,
653 match_results<const wchar_t*>& m,
655 match_flag_type flags = match_default)
657 return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
660 inline bool u32regex_search(const char* p,
661 match_results<const char*>& m,
663 match_flag_type flags = match_default)
665 return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
667 inline bool u32regex_search(const unsigned char* p,
668 match_results<const unsigned char*>& m,
670 match_flag_type flags = match_default)
672 return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
674 inline bool u32regex_search(const std::string& s,
675 match_results<std::string::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_<1> const*>(0));
681 #ifndef BOOST_NO_STD_WSTRING
682 inline bool u32regex_search(const std::wstring& s,
683 match_results<std::wstring::const_iterator>& m,
685 match_flag_type flags = match_default)
687 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
690 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
691 match_results<const UChar*>& m,
693 match_flag_type flags = match_default)
695 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));
697 template <class BidiIterator>
698 inline bool u32regex_search(BidiIterator first, BidiIterator last,
700 match_flag_type flags = match_default)
702 match_results<BidiIterator> m;
703 return re_detail::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
705 inline bool u32regex_search(const UChar* p,
707 match_flag_type flags = match_default)
709 match_results<const UChar*> m;
710 return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
712 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
713 inline bool u32regex_search(const wchar_t* p,
715 match_flag_type flags = match_default)
717 match_results<const wchar_t*> m;
718 return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
721 inline bool u32regex_search(const char* p,
723 match_flag_type flags = match_default)
725 match_results<const char*> m;
726 return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
728 inline bool u32regex_search(const unsigned char* p,
730 match_flag_type flags = match_default)
732 match_results<const unsigned char*> m;
733 return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
735 inline bool u32regex_search(const std::string& s,
737 match_flag_type flags = match_default)
739 match_results<std::string::const_iterator> m;
740 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
742 #ifndef BOOST_NO_STD_WSTRING
743 inline bool u32regex_search(const std::wstring& s,
745 match_flag_type flags = match_default)
747 match_results<std::wstring::const_iterator> m;
748 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
751 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
753 match_flag_type flags = match_default)
755 match_results<const UChar*> m;
756 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));
760 // overloads for regex_replace with utf-8 and utf-16 data types:
764 inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
765 make_utf32_seq(I i, I j, mpl::int_<1> const*)
767 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));
770 inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
771 make_utf32_seq(I i, I j, mpl::int_<2> const*)
773 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));
776 inline std::pair< I, I >
777 make_utf32_seq(I i, I j, mpl::int_<4> const*)
779 return std::pair< I, I >(i, j);
781 template <class charT>
782 inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
783 make_utf32_seq(const charT* p, mpl::int_<1> const*)
785 std::size_t len = std::strlen((const char*)p);
786 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));
788 template <class charT>
789 inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
790 make_utf32_seq(const charT* p, mpl::int_<2> const*)
792 std::size_t len = u_strlen((const UChar*)p);
793 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));
795 template <class charT>
796 inline std::pair< const charT*, const charT* >
797 make_utf32_seq(const charT* p, mpl::int_<4> const*)
799 return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
801 template <class OutputIterator>
802 inline OutputIterator make_utf32_out(OutputIterator o, mpl::int_<4> const*)
806 template <class OutputIterator>
807 inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<2> const*)
811 template <class OutputIterator>
812 inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<1> const*)
817 template <class OutputIterator, class I1, class I2>
818 OutputIterator do_regex_replace(OutputIterator out,
819 std::pair<I1, I1> const& in,
821 const std::pair<I2, I2>& fmt,
822 match_flag_type flags
825 // unfortunately we have to copy the format string in order to pass in onward:
826 std::vector<UChar32> f;
827 #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
828 f.assign(fmt.first, fmt.second);
832 while(pos != fmt.second)
836 regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
837 regex_iterator<I1, UChar32, icu_regex_traits> j;
840 if(!(flags & regex_constants::format_no_copy))
841 out = re_detail::copy(in.first, in.second, out);
845 I1 last_m = in.first;
848 if(!(flags & regex_constants::format_no_copy))
849 out = re_detail::copy(i->prefix().first, i->prefix().second, out);
851 out = ::boost::re_detail::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
853 out = ::boost::re_detail::regex_format_imp(out, *i, static_cast<UChar32 const*>(0), static_cast<UChar32 const*>(0), flags, e.get_traits());
854 last_m = (*i)[0].second;
855 if(flags & regex_constants::format_first_only)
859 if(!(flags & regex_constants::format_no_copy))
860 out = re_detail::copy(last_m, in.second, out);
864 template <class BaseIterator>
865 inline const BaseIterator& extract_output_base(const BaseIterator& b)
869 template <class BaseIterator>
870 inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
874 template <class BaseIterator>
875 inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
881 template <class OutputIterator, class BidirectionalIterator, class charT>
882 inline OutputIterator u32regex_replace(OutputIterator out,
883 BidirectionalIterator first,
884 BidirectionalIterator last,
887 match_flag_type flags = match_default)
889 return re_detail::extract_output_base
890 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
894 re_detail::do_regex_replace(
895 re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
896 re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
898 re_detail::make_utf32_seq(fmt, static_cast<mpl::int_<sizeof(*fmt)> const*>(0)),
903 template <class OutputIterator, class Iterator, class charT>
904 inline OutputIterator u32regex_replace(OutputIterator out,
908 const std::basic_string<charT>& fmt,
909 match_flag_type flags = match_default)
911 return re_detail::extract_output_base
912 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
916 re_detail::do_regex_replace(
917 re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
918 re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
920 re_detail::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<mpl::int_<sizeof(charT)> const*>(0)),
925 template <class OutputIterator, class Iterator>
926 inline OutputIterator u32regex_replace(OutputIterator out,
930 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
931 match_flag_type flags = match_default)
933 return re_detail::extract_output_base
934 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
938 re_detail::do_regex_replace(
939 re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
940 re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
942 re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
947 template <class charT>
948 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
951 match_flag_type flags = match_default)
953 std::basic_string<charT> result;
954 re_detail::string_out_iterator<std::basic_string<charT> > i(result);
955 u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
959 template <class charT>
960 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
962 const std::basic_string<charT>& fmt,
963 match_flag_type flags = match_default)
965 std::basic_string<charT> result;
966 re_detail::string_out_iterator<std::basic_string<charT> > i(result);
967 u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
973 class unicode_string_out_iterator
975 U_NAMESPACE_QUALIFIER UnicodeString* out;
977 unicode_string_out_iterator(U_NAMESPACE_QUALIFIER UnicodeString& s) : out(&s) {}
978 unicode_string_out_iterator& operator++() { return *this; }
979 unicode_string_out_iterator& operator++(int) { return *this; }
980 unicode_string_out_iterator& operator*() { return *this; }
981 unicode_string_out_iterator& operator=(UChar v)
986 typedef std::ptrdiff_t difference_type;
987 typedef UChar value_type;
988 typedef value_type* pointer;
989 typedef value_type& reference;
990 typedef std::output_iterator_tag iterator_category;
995 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
998 match_flag_type flags = match_default)
1000 U_NAMESPACE_QUALIFIER UnicodeString result;
1001 re_detail::unicode_string_out_iterator i(result);
1002 u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
1006 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1008 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1009 match_flag_type flags = match_default)
1011 U_NAMESPACE_QUALIFIER UnicodeString result;
1012 re_detail::unicode_string_out_iterator i(result);
1013 re_detail::do_regex_replace(
1014 re_detail::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)),
1015 re_detail::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<mpl::int_<2> const*>(0)),
1017 re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
1022 } // namespace boost.
1025 #pragma warning (pop)
1028 #include <boost/regex/v4/u32regex_iterator.hpp>
1029 #include <boost/regex/v4/u32regex_token_iterator.hpp>