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,
188 offset_horizontal = U_CHAR_CATEGORY_COUNT+7,
189 offset_vertical = U_CHAR_CATEGORY_COUNT+8
193 // and now the masks:
195 static const char_class_type mask_blank;
196 static const char_class_type mask_space;
197 static const char_class_type mask_xdigit;
198 static const char_class_type mask_underscore;
199 static const char_class_type mask_unicode;
200 static const char_class_type mask_any;
201 static const char_class_type mask_ascii;
202 static const char_class_type mask_horizontal;
203 static const char_class_type mask_vertical;
205 static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
207 boost::shared_ptr< ::boost::re_detail::icu_regex_traits_implementation> m_pimpl;
213 // template instances:
215 #define BOOST_REGEX_CHAR_T UChar32
216 #undef BOOST_REGEX_TRAITS_T
217 #define BOOST_REGEX_TRAITS_T , icu_regex_traits
218 #define BOOST_REGEX_ICU_INSTANCES
219 #ifdef BOOST_REGEX_ICU_INSTANTIATE
220 # define BOOST_REGEX_INSTANTIATE
222 #include <boost/regex/v4/instances.hpp>
223 #undef BOOST_REGEX_CHAR_T
224 #undef BOOST_REGEX_TRAITS_T
225 #undef BOOST_REGEX_ICU_INSTANCES
226 #ifdef BOOST_REGEX_INSTANTIATE
227 # undef BOOST_REGEX_INSTANTIATE
233 typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
234 typedef match_results<const ::UChar32*> u32match;
235 typedef match_results<const ::UChar*> u16match;
238 // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
242 #if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
243 template <class InputIterator>
244 inline u32regex do_make_u32regex(InputIterator i,
246 boost::regex_constants::syntax_option_type opt,
247 const boost::mpl::int_<1>*)
249 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
250 return u32regex(conv_type(i), conv_type(j), opt);
253 template <class InputIterator>
254 inline u32regex do_make_u32regex(InputIterator i,
256 boost::regex_constants::syntax_option_type opt,
257 const boost::mpl::int_<2>*)
259 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
260 return u32regex(conv_type(i), conv_type(j), opt);
263 template <class InputIterator>
264 inline u32regex do_make_u32regex(InputIterator i,
266 boost::regex_constants::syntax_option_type opt,
267 const boost::mpl::int_<4>*)
269 return u32regex(i, j, opt);
272 template <class InputIterator>
273 inline u32regex do_make_u32regex(InputIterator i,
275 boost::regex_constants::syntax_option_type opt,
276 const boost::mpl::int_<1>*)
278 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
279 typedef std::vector<UChar32> vector_type;
281 conv_type a(i), b(j);
288 return u32regex(&*v.begin(), v.size(), opt);
289 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
292 template <class InputIterator>
293 inline u32regex do_make_u32regex(InputIterator i,
295 boost::regex_constants::syntax_option_type opt,
296 const boost::mpl::int_<2>*)
298 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
299 typedef std::vector<UChar32> vector_type;
301 conv_type a(i), b(j);
308 return u32regex(&*v.begin(), v.size(), opt);
309 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
312 template <class InputIterator>
313 inline u32regex do_make_u32regex(InputIterator i,
315 boost::regex_constants::syntax_option_type opt,
316 const boost::mpl::int_<4>*)
318 typedef std::vector<UChar32> vector_type;
322 v.push_back((UChar32)(*i));
326 return u32regex(&*v.begin(), v.size(), opt);
327 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
333 // Construction from an iterator pair:
335 template <class InputIterator>
336 inline u32regex make_u32regex(InputIterator i,
338 boost::regex_constants::syntax_option_type opt)
340 return re_detail::do_make_u32regex(i, j, opt, static_cast<boost::mpl::int_<sizeof(*i)> const*>(0));
343 // construction from UTF-8 nul-terminated strings:
345 inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
347 return re_detail::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<boost::mpl::int_<1> const*>(0));
349 inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
351 return re_detail::do_make_u32regex(p, p + std::strlen(reinterpret_cast<const char*>(p)), opt, static_cast<boost::mpl::int_<1> const*>(0));
354 // construction from UTF-16 nul-terminated strings:
356 #ifndef BOOST_NO_WREGEX
357 inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
359 return re_detail::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<boost::mpl::int_<sizeof(wchar_t)> const*>(0));
362 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
363 inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
365 return re_detail::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
369 // construction from basic_string class-template:
371 template<class C, class T, class A>
372 inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
374 return re_detail::do_make_u32regex(s.begin(), s.end(), opt, static_cast<boost::mpl::int_<sizeof(C)> const*>(0));
377 // Construction from ICU string type:
379 inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
381 return re_detail::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
385 // regex_match overloads that widen the character type as appropriate:
388 template<class MR1, class MR2>
389 void copy_results(MR1& out, MR2 const& in)
391 // copy results from an adapted MR2 match_results:
392 out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
393 out.set_base(in.base().base());
394 for(int i = 0; i < (int)in.size(); ++i)
398 out.set_first(in[i].first.base(), i);
399 out.set_second(in[i].second.base(), i);
404 template <class BidiIterator, class Allocator>
405 inline bool do_regex_match(BidiIterator first, BidiIterator last,
406 match_results<BidiIterator, Allocator>& m,
408 match_flag_type flags,
409 boost::mpl::int_<4> const*)
411 return ::boost::regex_match(first, last, m, e, flags);
413 template <class BidiIterator, class Allocator>
414 bool do_regex_match(BidiIterator first, BidiIterator last,
415 match_results<BidiIterator, Allocator>& m,
417 match_flag_type flags,
418 boost::mpl::int_<2> const*)
420 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
421 typedef match_results<conv_type> match_type;
422 typedef typename match_type::allocator_type alloc_type;
424 bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
425 // copy results across to m:
426 if(result) copy_results(m, what);
429 template <class BidiIterator, class Allocator>
430 bool do_regex_match(BidiIterator first, BidiIterator last,
431 match_results<BidiIterator, Allocator>& m,
433 match_flag_type flags,
434 boost::mpl::int_<1> const*)
436 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
437 typedef match_results<conv_type> match_type;
438 typedef typename match_type::allocator_type alloc_type;
440 bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
441 // copy results across to m:
442 if(result) copy_results(m, what);
445 } // namespace re_detail
447 template <class BidiIterator, class Allocator>
448 inline bool u32regex_match(BidiIterator first, BidiIterator last,
449 match_results<BidiIterator, Allocator>& m,
451 match_flag_type flags = match_default)
453 return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
455 inline bool u32regex_match(const UChar* p,
456 match_results<const UChar*>& m,
458 match_flag_type flags = match_default)
460 return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
462 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
463 inline bool u32regex_match(const wchar_t* p,
464 match_results<const wchar_t*>& m,
466 match_flag_type flags = match_default)
468 return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
471 inline bool u32regex_match(const char* p,
472 match_results<const char*>& m,
474 match_flag_type flags = match_default)
476 return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
478 inline bool u32regex_match(const unsigned char* p,
479 match_results<const unsigned char*>& m,
481 match_flag_type flags = match_default)
483 return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
485 inline bool u32regex_match(const std::string& s,
486 match_results<std::string::const_iterator>& m,
488 match_flag_type flags = match_default)
490 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
492 #ifndef BOOST_NO_STD_WSTRING
493 inline bool u32regex_match(const std::wstring& s,
494 match_results<std::wstring::const_iterator>& m,
496 match_flag_type flags = match_default)
498 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
501 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
502 match_results<const UChar*>& m,
504 match_flag_type flags = match_default)
506 return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
509 // regex_match overloads that do not return what matched:
511 template <class BidiIterator>
512 inline bool u32regex_match(BidiIterator first, BidiIterator last,
514 match_flag_type flags = match_default)
516 match_results<BidiIterator> m;
517 return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
519 inline bool u32regex_match(const UChar* p,
521 match_flag_type flags = match_default)
523 match_results<const UChar*> m;
524 return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
526 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
527 inline bool u32regex_match(const wchar_t* p,
529 match_flag_type flags = match_default)
531 match_results<const wchar_t*> m;
532 return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
535 inline bool u32regex_match(const char* p,
537 match_flag_type flags = match_default)
539 match_results<const char*> m;
540 return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
542 inline bool u32regex_match(const unsigned char* p,
544 match_flag_type flags = match_default)
546 match_results<const unsigned char*> m;
547 return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
549 inline bool u32regex_match(const std::string& s,
551 match_flag_type flags = match_default)
553 match_results<std::string::const_iterator> m;
554 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
556 #ifndef BOOST_NO_STD_WSTRING
557 inline bool u32regex_match(const std::wstring& s,
559 match_flag_type flags = match_default)
561 match_results<std::wstring::const_iterator> m;
562 return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
565 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
567 match_flag_type flags = match_default)
569 match_results<const UChar*> m;
570 return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
574 // regex_search overloads that widen the character type as appropriate:
577 template <class BidiIterator, class Allocator>
578 inline bool do_regex_search(BidiIterator first, BidiIterator last,
579 match_results<BidiIterator, Allocator>& m,
581 match_flag_type flags,
583 boost::mpl::int_<4> const*)
585 return ::boost::regex_search(first, last, m, e, flags, base);
587 template <class BidiIterator, class Allocator>
588 bool do_regex_search(BidiIterator first, BidiIterator last,
589 match_results<BidiIterator, Allocator>& m,
591 match_flag_type flags,
593 boost::mpl::int_<2> const*)
595 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
596 typedef match_results<conv_type> match_type;
597 typedef typename match_type::allocator_type alloc_type;
599 bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags, conv_type(base));
600 // copy results across to m:
601 if(result) copy_results(m, what);
604 template <class BidiIterator, class Allocator>
605 bool do_regex_search(BidiIterator first, BidiIterator last,
606 match_results<BidiIterator, Allocator>& m,
608 match_flag_type flags,
610 boost::mpl::int_<1> const*)
612 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
613 typedef match_results<conv_type> match_type;
614 typedef typename match_type::allocator_type alloc_type;
616 bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags, conv_type(base));
617 // copy results across to m:
618 if(result) copy_results(m, what);
623 template <class BidiIterator, class Allocator>
624 inline bool u32regex_search(BidiIterator first, BidiIterator last,
625 match_results<BidiIterator, Allocator>& m,
627 match_flag_type flags = match_default)
629 return re_detail::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
631 template <class BidiIterator, class Allocator>
632 inline bool u32regex_search(BidiIterator first, BidiIterator last,
633 match_results<BidiIterator, Allocator>& m,
635 match_flag_type flags,
638 return re_detail::do_regex_search(first, last, m, e, flags, base, static_cast<mpl::int_<sizeof(*first)> const*>(0));
640 inline bool u32regex_search(const UChar* p,
641 match_results<const UChar*>& m,
643 match_flag_type flags = match_default)
645 return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
647 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
648 inline bool u32regex_search(const wchar_t* p,
649 match_results<const wchar_t*>& m,
651 match_flag_type flags = match_default)
653 return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
656 inline bool u32regex_search(const char* p,
657 match_results<const char*>& m,
659 match_flag_type flags = match_default)
661 return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
663 inline bool u32regex_search(const unsigned char* p,
664 match_results<const unsigned char*>& m,
666 match_flag_type flags = match_default)
668 return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
670 inline bool u32regex_search(const std::string& s,
671 match_results<std::string::const_iterator>& m,
673 match_flag_type flags = match_default)
675 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
677 #ifndef BOOST_NO_STD_WSTRING
678 inline bool u32regex_search(const std::wstring& s,
679 match_results<std::wstring::const_iterator>& m,
681 match_flag_type flags = match_default)
683 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
686 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
687 match_results<const UChar*>& m,
689 match_flag_type flags = match_default)
691 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));
693 template <class BidiIterator>
694 inline bool u32regex_search(BidiIterator first, BidiIterator last,
696 match_flag_type flags = match_default)
698 match_results<BidiIterator> m;
699 return re_detail::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
701 inline bool u32regex_search(const UChar* p,
703 match_flag_type flags = match_default)
705 match_results<const UChar*> m;
706 return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
708 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
709 inline bool u32regex_search(const wchar_t* p,
711 match_flag_type flags = match_default)
713 match_results<const wchar_t*> m;
714 return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
717 inline bool u32regex_search(const char* p,
719 match_flag_type flags = match_default)
721 match_results<const char*> m;
722 return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
724 inline bool u32regex_search(const unsigned char* p,
726 match_flag_type flags = match_default)
728 match_results<const unsigned char*> m;
729 return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
731 inline bool u32regex_search(const std::string& s,
733 match_flag_type flags = match_default)
735 match_results<std::string::const_iterator> m;
736 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
738 #ifndef BOOST_NO_STD_WSTRING
739 inline bool u32regex_search(const std::wstring& s,
741 match_flag_type flags = match_default)
743 match_results<std::wstring::const_iterator> m;
744 return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
747 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
749 match_flag_type flags = match_default)
751 match_results<const UChar*> m;
752 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));
756 // overloads for regex_replace with utf-8 and utf-16 data types:
760 inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
761 make_utf32_seq(I i, I j, mpl::int_<1> const*)
763 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));
766 inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
767 make_utf32_seq(I i, I j, mpl::int_<2> const*)
769 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));
772 inline std::pair< I, I >
773 make_utf32_seq(I i, I j, mpl::int_<4> const*)
775 return std::pair< I, I >(i, j);
777 template <class charT>
778 inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
779 make_utf32_seq(const charT* p, mpl::int_<1> const*)
781 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)));
783 template <class charT>
784 inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
785 make_utf32_seq(const charT* p, mpl::int_<2> const*)
787 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)));
789 template <class charT>
790 inline std::pair< const charT*, const charT* >
791 make_utf32_seq(const charT* p, mpl::int_<4> const*)
793 return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
795 template <class OutputIterator>
796 inline OutputIterator make_utf32_out(OutputIterator o, mpl::int_<4> const*)
800 template <class OutputIterator>
801 inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<2> const*)
805 template <class OutputIterator>
806 inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<1> const*)
811 template <class OutputIterator, class I1, class I2>
812 OutputIterator do_regex_replace(OutputIterator out,
813 std::pair<I1, I1> const& in,
815 const std::pair<I2, I2>& fmt,
816 match_flag_type flags
819 // unfortunately we have to copy the format string in order to pass in onward:
820 std::vector<UChar32> f;
821 #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
822 f.assign(fmt.first, fmt.second);
826 while(pos != fmt.second)
830 regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
831 regex_iterator<I1, UChar32, icu_regex_traits> j;
834 if(!(flags & regex_constants::format_no_copy))
835 out = re_detail::copy(in.first, in.second, out);
839 I1 last_m = in.first;
842 if(!(flags & regex_constants::format_no_copy))
843 out = re_detail::copy(i->prefix().first, i->prefix().second, out);
845 out = ::boost::re_detail::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
847 out = ::boost::re_detail::regex_format_imp(out, *i, static_cast<UChar32 const*>(0), static_cast<UChar32 const*>(0), flags, e.get_traits());
848 last_m = (*i)[0].second;
849 if(flags & regex_constants::format_first_only)
853 if(!(flags & regex_constants::format_no_copy))
854 out = re_detail::copy(last_m, in.second, out);
858 template <class BaseIterator>
859 inline const BaseIterator& extract_output_base(const BaseIterator& b)
863 template <class BaseIterator>
864 inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
868 template <class BaseIterator>
869 inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
875 template <class OutputIterator, class BidirectionalIterator, class charT>
876 inline OutputIterator u32regex_replace(OutputIterator out,
877 BidirectionalIterator first,
878 BidirectionalIterator last,
881 match_flag_type flags = match_default)
883 return re_detail::extract_output_base
884 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
888 re_detail::do_regex_replace(
889 re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
890 re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
892 re_detail::make_utf32_seq(fmt, static_cast<mpl::int_<sizeof(*fmt)> const*>(0)),
897 template <class OutputIterator, class Iterator, class charT>
898 inline OutputIterator u32regex_replace(OutputIterator out,
902 const std::basic_string<charT>& fmt,
903 match_flag_type flags = match_default)
905 return re_detail::extract_output_base
906 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
910 re_detail::do_regex_replace(
911 re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
912 re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
914 re_detail::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<mpl::int_<sizeof(charT)> const*>(0)),
919 template <class OutputIterator, class Iterator>
920 inline OutputIterator u32regex_replace(OutputIterator out,
924 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
925 match_flag_type flags = match_default)
927 return re_detail::extract_output_base
928 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
932 re_detail::do_regex_replace(
933 re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
934 re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
936 re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
941 template <class charT>
942 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
945 match_flag_type flags = match_default)
947 std::basic_string<charT> result;
948 re_detail::string_out_iterator<std::basic_string<charT> > i(result);
949 u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
953 template <class charT>
954 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
956 const std::basic_string<charT>& fmt,
957 match_flag_type flags = match_default)
959 std::basic_string<charT> result;
960 re_detail::string_out_iterator<std::basic_string<charT> > i(result);
961 u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
967 class unicode_string_out_iterator
969 U_NAMESPACE_QUALIFIER UnicodeString* out;
971 unicode_string_out_iterator(U_NAMESPACE_QUALIFIER UnicodeString& s) : out(&s) {}
972 unicode_string_out_iterator& operator++() { return *this; }
973 unicode_string_out_iterator& operator++(int) { return *this; }
974 unicode_string_out_iterator& operator*() { return *this; }
975 unicode_string_out_iterator& operator=(UChar v)
980 typedef std::ptrdiff_t difference_type;
981 typedef UChar value_type;
982 typedef value_type* pointer;
983 typedef value_type& reference;
984 typedef std::output_iterator_tag iterator_category;
989 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
992 match_flag_type flags = match_default)
994 U_NAMESPACE_QUALIFIER UnicodeString result;
995 re_detail::unicode_string_out_iterator i(result);
996 u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
1000 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1002 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1003 match_flag_type flags = match_default)
1005 U_NAMESPACE_QUALIFIER UnicodeString result;
1006 re_detail::unicode_string_out_iterator i(result);
1007 re_detail::do_regex_replace(
1008 re_detail::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)),
1009 re_detail::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<mpl::int_<2> const*>(0)),
1011 re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
1016 } // namespace boost.
1018 #include <boost/regex/v4/u32regex_iterator.hpp>
1019 #include <boost/regex/v4/u32regex_token_iterator.hpp>