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 <boost/config.hpp>
23 #include <unicode/utypes.h>
24 #include <unicode/uchar.h>
25 #include <unicode/coll.h>
26 #include <boost/regex.hpp>
27 #include <boost/regex/pending/unicode_iterator.hpp>
28 #include <boost/mpl/int_fwd.hpp>
32 #pragma warning (push)
33 #pragma warning (disable: 4251)
38 namespace BOOST_REGEX_DETAIL_NS{
41 // Implementation details:
43 class BOOST_REGEX_DECL icu_regex_traits_implementation
45 typedef UChar32 char_type;
46 typedef std::size_t size_type;
47 typedef std::vector<char_type> string_type;
48 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
49 typedef boost::uint_least32_t char_class_type;
51 icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
54 UErrorCode success = U_ZERO_ERROR;
55 m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
56 if(U_SUCCESS(success) == 0)
58 m_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::IDENTICAL);
59 success = U_ZERO_ERROR;
60 m_primary_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
61 if(U_SUCCESS(success) == 0)
63 m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
65 U_NAMESPACE_QUALIFIER Locale getloc()const
69 string_type do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const;
70 string_type transform(const char_type* p1, const char_type* p2) const
72 return do_transform(p1, p2, m_collator.get());
74 string_type transform_primary(const char_type* p1, const char_type* p2) const
76 return do_transform(p1, p2, m_primary_collator.get());
81 std::runtime_error e("Could not initialize ICU resources");
82 boost::throw_exception(e);
84 U_NAMESPACE_QUALIFIER Locale m_locale; // The ICU locale that we're using
85 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_collator; // The full collation object
86 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_primary_collator; // The primary collation object
89 inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
91 return boost::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
96 class BOOST_REGEX_DECL icu_regex_traits
99 typedef UChar32 char_type;
100 typedef std::size_t size_type;
101 typedef std::vector<char_type> string_type;
102 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
103 #ifdef BOOST_NO_INT64_T
104 typedef std::bitset<64> char_class_type;
106 typedef boost::uint64_t char_class_type;
109 struct boost_extensions_tag{};
112 : m_pimpl(BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
115 static size_type length(const char_type* p);
117 ::boost::regex_constants::syntax_type syntax_type(char_type c)const
119 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
121 ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
123 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
125 char_type translate(char_type c) const
129 char_type translate_nocase(char_type c) const
131 return ::u_tolower(c);
133 char_type translate(char_type c, bool icase) const
135 return icase ? translate_nocase(c) : translate(c);
137 char_type tolower(char_type c) const
139 return ::u_tolower(c);
141 char_type toupper(char_type c) const
143 return ::u_toupper(c);
145 string_type transform(const char_type* p1, const char_type* p2) const
147 return m_pimpl->transform(p1, p2);
149 string_type transform_primary(const char_type* p1, const char_type* p2) const
151 return m_pimpl->transform_primary(p1, p2);
153 char_class_type lookup_classname(const char_type* p1, const char_type* p2) const;
154 string_type lookup_collatename(const char_type* p1, const char_type* p2) const;
155 bool isctype(char_type c, char_class_type f) const;
156 boost::intmax_t toi(const char_type*& p1, const char_type* p2, int radix)const
158 return BOOST_REGEX_DETAIL_NS::global_toi(p1, p2, radix, *this);
160 int value(char_type c, int radix)const
162 return u_digit(c, static_cast< ::int8_t>(radix));
164 locale_type imbue(locale_type l)
166 locale_type result(m_pimpl->getloc());
167 m_pimpl = BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(l);
170 locale_type getloc()const
172 return locale_type();
174 std::string error_string(::boost::regex_constants::error_type n) const
176 return BOOST_REGEX_DETAIL_NS::get_default_error_string(n);
179 icu_regex_traits(const icu_regex_traits&);
180 icu_regex_traits& operator=(const icu_regex_traits&);
183 // define the bitmasks offsets we need for additional character properties:
186 offset_blank = U_CHAR_CATEGORY_COUNT,
187 offset_space = U_CHAR_CATEGORY_COUNT+1,
188 offset_xdigit = U_CHAR_CATEGORY_COUNT+2,
189 offset_underscore = U_CHAR_CATEGORY_COUNT+3,
190 offset_unicode = U_CHAR_CATEGORY_COUNT+4,
191 offset_any = U_CHAR_CATEGORY_COUNT+5,
192 offset_ascii = U_CHAR_CATEGORY_COUNT+6,
193 offset_horizontal = U_CHAR_CATEGORY_COUNT+7,
194 offset_vertical = U_CHAR_CATEGORY_COUNT+8
198 // and now the masks:
200 static const char_class_type mask_blank;
201 static const char_class_type mask_space;
202 static const char_class_type mask_xdigit;
203 static const char_class_type mask_underscore;
204 static const char_class_type mask_unicode;
205 static const char_class_type mask_any;
206 static const char_class_type mask_ascii;
207 static const char_class_type mask_horizontal;
208 static const char_class_type mask_vertical;
210 static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
212 boost::shared_ptr< ::boost::BOOST_REGEX_DETAIL_NS::icu_regex_traits_implementation> m_pimpl;
218 // template instances:
220 #define BOOST_REGEX_CHAR_T UChar32
221 #undef BOOST_REGEX_TRAITS_T
222 #define BOOST_REGEX_TRAITS_T , icu_regex_traits
223 #define BOOST_REGEX_ICU_INSTANCES
224 #ifdef BOOST_REGEX_ICU_INSTANTIATE
225 # define BOOST_REGEX_INSTANTIATE
227 #include <boost/regex/v4/instances.hpp>
228 #undef BOOST_REGEX_CHAR_T
229 #undef BOOST_REGEX_TRAITS_T
230 #undef BOOST_REGEX_ICU_INSTANCES
231 #ifdef BOOST_REGEX_INSTANTIATE
232 # undef BOOST_REGEX_INSTANTIATE
238 typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
239 typedef match_results<const ::UChar32*> u32match;
240 typedef match_results<const ::UChar*> u16match;
243 // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
245 namespace BOOST_REGEX_DETAIL_NS{
247 #if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
248 template <class InputIterator>
249 inline u32regex do_make_u32regex(InputIterator i,
251 boost::regex_constants::syntax_option_type opt,
252 const boost::mpl::int_<1>*)
254 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
255 return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
258 template <class InputIterator>
259 inline u32regex do_make_u32regex(InputIterator i,
261 boost::regex_constants::syntax_option_type opt,
262 const boost::mpl::int_<2>*)
264 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
265 return u32regex(conv_type(i, i, j), conv_type(j, 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_<4>*)
274 return u32regex(i, j, opt);
277 template <class InputIterator>
278 inline u32regex do_make_u32regex(InputIterator i,
280 boost::regex_constants::syntax_option_type opt,
281 const boost::mpl::int_<1>*)
283 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
284 typedef std::vector<UChar32> vector_type;
286 conv_type a(i, i, j), b(j, i, j);
293 return u32regex(&*v.begin(), v.size(), opt);
294 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
297 template <class InputIterator>
298 inline u32regex do_make_u32regex(InputIterator i,
300 boost::regex_constants::syntax_option_type opt,
301 const boost::mpl::int_<2>*)
303 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
304 typedef std::vector<UChar32> vector_type;
306 conv_type a(i, i, j), b(j, i, j);
313 return u32regex(&*v.begin(), v.size(), opt);
314 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
317 template <class InputIterator>
318 inline u32regex do_make_u32regex(InputIterator i,
320 boost::regex_constants::syntax_option_type opt,
321 const boost::mpl::int_<4>*)
323 typedef std::vector<UChar32> vector_type;
327 v.push_back((UChar32)(*i));
331 return u32regex(&*v.begin(), v.size(), opt);
332 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
338 // Construction from an iterator pair:
340 template <class InputIterator>
341 inline u32regex make_u32regex(InputIterator i,
343 boost::regex_constants::syntax_option_type opt)
345 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(i, j, opt, static_cast<boost::mpl::int_<sizeof(*i)> const*>(0));
348 // construction from UTF-8 nul-terminated strings:
350 inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
352 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<boost::mpl::int_<1> const*>(0));
354 inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
356 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(reinterpret_cast<const char*>(p)), opt, static_cast<boost::mpl::int_<1> const*>(0));
359 // construction from UTF-16 nul-terminated strings:
361 #ifndef BOOST_NO_WREGEX
362 inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
364 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<boost::mpl::int_<sizeof(wchar_t)> const*>(0));
367 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
368 inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
370 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
374 // construction from basic_string class-template:
376 template<class C, class T, class A>
377 inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
379 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.begin(), s.end(), opt, static_cast<boost::mpl::int_<sizeof(C)> const*>(0));
382 // Construction from ICU string type:
384 inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
386 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
390 // regex_match overloads that widen the character type as appropriate:
392 namespace BOOST_REGEX_DETAIL_NS{
393 template<class MR1, class MR2, class NSubs>
394 void copy_results(MR1& out, MR2 const& in, NSubs named_subs)
396 // copy results from an adapted MR2 match_results:
397 out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
398 out.set_base(in.base().base());
399 out.set_named_subs(named_subs);
400 for(int i = 0; i < (int)in.size(); ++i)
402 if(in[i].matched || !i)
404 out.set_first(in[i].first.base(), i);
405 out.set_second(in[i].second.base(), i, in[i].matched);
408 #ifdef BOOST_REGEX_MATCH_EXTRA
409 // Copy full capture info as well:
410 for(int i = 0; i < (int)in.size(); ++i)
412 if(in[i].captures().size())
414 out[i].get_captures().assign(in[i].captures().size(), typename MR1::value_type());
415 for(int j = 0; j < (int)out[i].captures().size(); ++j)
417 out[i].get_captures()[j].first = in[i].captures()[j].first.base();
418 out[i].get_captures()[j].second = in[i].captures()[j].second.base();
419 out[i].get_captures()[j].matched = in[i].captures()[j].matched;
426 template <class BidiIterator, class Allocator>
427 inline bool do_regex_match(BidiIterator first, BidiIterator last,
428 match_results<BidiIterator, Allocator>& m,
430 match_flag_type flags,
431 boost::mpl::int_<4> const*)
433 return ::boost::regex_match(first, last, m, e, flags);
435 template <class BidiIterator, class Allocator>
436 bool do_regex_match(BidiIterator first, BidiIterator last,
437 match_results<BidiIterator, Allocator>& m,
439 match_flag_type flags,
440 boost::mpl::int_<2> const*)
442 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
443 typedef match_results<conv_type> match_type;
444 //typedef typename match_type::allocator_type alloc_type;
446 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
447 // copy results across to m:
448 if(result) copy_results(m, what, e.get_named_subs());
451 template <class BidiIterator, class Allocator>
452 bool do_regex_match(BidiIterator first, BidiIterator last,
453 match_results<BidiIterator, Allocator>& m,
455 match_flag_type flags,
456 boost::mpl::int_<1> const*)
458 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
459 typedef match_results<conv_type> match_type;
460 //typedef typename match_type::allocator_type alloc_type;
462 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
463 // copy results across to m:
464 if(result) copy_results(m, what, e.get_named_subs());
467 } // namespace BOOST_REGEX_DETAIL_NS
469 template <class BidiIterator, class Allocator>
470 inline bool u32regex_match(BidiIterator first, BidiIterator last,
471 match_results<BidiIterator, Allocator>& m,
473 match_flag_type flags = match_default)
475 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
477 inline bool u32regex_match(const UChar* p,
478 match_results<const UChar*>& m,
480 match_flag_type flags = match_default)
482 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
484 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
485 inline bool u32regex_match(const wchar_t* p,
486 match_results<const wchar_t*>& m,
488 match_flag_type flags = match_default)
490 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
493 inline bool u32regex_match(const char* p,
494 match_results<const char*>& m,
496 match_flag_type flags = match_default)
498 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
500 inline bool u32regex_match(const unsigned char* p,
501 match_results<const unsigned char*>& m,
503 match_flag_type flags = match_default)
505 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
507 inline bool u32regex_match(const std::string& s,
508 match_results<std::string::const_iterator>& m,
510 match_flag_type flags = match_default)
512 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
514 #ifndef BOOST_NO_STD_WSTRING
515 inline bool u32regex_match(const std::wstring& s,
516 match_results<std::wstring::const_iterator>& m,
518 match_flag_type flags = match_default)
520 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
523 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
524 match_results<const UChar*>& m,
526 match_flag_type flags = match_default)
528 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
531 // regex_match overloads that do not return what matched:
533 template <class BidiIterator>
534 inline bool u32regex_match(BidiIterator first, BidiIterator last,
536 match_flag_type flags = match_default)
538 match_results<BidiIterator> m;
539 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
541 inline bool u32regex_match(const UChar* p,
543 match_flag_type flags = match_default)
545 match_results<const UChar*> m;
546 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
548 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
549 inline bool u32regex_match(const wchar_t* p,
551 match_flag_type flags = match_default)
553 match_results<const wchar_t*> m;
554 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
557 inline bool u32regex_match(const char* p,
559 match_flag_type flags = match_default)
561 match_results<const char*> m;
562 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
564 inline bool u32regex_match(const unsigned char* p,
566 match_flag_type flags = match_default)
568 match_results<const unsigned char*> m;
569 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
571 inline bool u32regex_match(const std::string& s,
573 match_flag_type flags = match_default)
575 match_results<std::string::const_iterator> m;
576 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
578 #ifndef BOOST_NO_STD_WSTRING
579 inline bool u32regex_match(const std::wstring& s,
581 match_flag_type flags = match_default)
583 match_results<std::wstring::const_iterator> m;
584 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
587 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
589 match_flag_type flags = match_default)
591 match_results<const UChar*> m;
592 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
596 // regex_search overloads that widen the character type as appropriate:
598 namespace BOOST_REGEX_DETAIL_NS{
599 template <class BidiIterator, class Allocator>
600 inline bool do_regex_search(BidiIterator first, BidiIterator last,
601 match_results<BidiIterator, Allocator>& m,
603 match_flag_type flags,
605 boost::mpl::int_<4> const*)
607 return ::boost::regex_search(first, last, m, e, flags, base);
609 template <class BidiIterator, class Allocator>
610 bool do_regex_search(BidiIterator first, BidiIterator last,
611 match_results<BidiIterator, Allocator>& m,
613 match_flag_type flags,
615 boost::mpl::int_<2> const*)
617 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
618 typedef match_results<conv_type> match_type;
619 //typedef typename match_type::allocator_type alloc_type;
621 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
622 // copy results across to m:
623 if(result) copy_results(m, what, e.get_named_subs());
626 template <class BidiIterator, class Allocator>
627 bool do_regex_search(BidiIterator first, BidiIterator last,
628 match_results<BidiIterator, Allocator>& m,
630 match_flag_type flags,
632 boost::mpl::int_<1> const*)
634 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
635 typedef match_results<conv_type> match_type;
636 //typedef typename match_type::allocator_type alloc_type;
638 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
639 // copy results across to m:
640 if(result) copy_results(m, what, e.get_named_subs());
645 template <class BidiIterator, class Allocator>
646 inline bool u32regex_search(BidiIterator first, BidiIterator last,
647 match_results<BidiIterator, Allocator>& m,
649 match_flag_type flags = match_default)
651 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
653 template <class BidiIterator, class Allocator>
654 inline bool u32regex_search(BidiIterator first, BidiIterator last,
655 match_results<BidiIterator, Allocator>& m,
657 match_flag_type flags,
660 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, base, static_cast<mpl::int_<sizeof(*first)> const*>(0));
662 inline bool u32regex_search(const UChar* p,
663 match_results<const UChar*>& m,
665 match_flag_type flags = match_default)
667 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
669 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
670 inline bool u32regex_search(const wchar_t* p,
671 match_results<const wchar_t*>& m,
673 match_flag_type flags = match_default)
675 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
678 inline bool u32regex_search(const char* p,
679 match_results<const char*>& m,
681 match_flag_type flags = match_default)
683 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
685 inline bool u32regex_search(const unsigned char* p,
686 match_results<const unsigned char*>& m,
688 match_flag_type flags = match_default)
690 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
692 inline bool u32regex_search(const std::string& s,
693 match_results<std::string::const_iterator>& m,
695 match_flag_type flags = match_default)
697 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
699 #ifndef BOOST_NO_STD_WSTRING
700 inline bool u32regex_search(const std::wstring& s,
701 match_results<std::wstring::const_iterator>& m,
703 match_flag_type flags = match_default)
705 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
708 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
709 match_results<const UChar*>& m,
711 match_flag_type flags = match_default)
713 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
715 template <class BidiIterator>
716 inline bool u32regex_search(BidiIterator first, BidiIterator last,
718 match_flag_type flags = match_default)
720 match_results<BidiIterator> m;
721 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
723 inline bool u32regex_search(const UChar* p,
725 match_flag_type flags = match_default)
727 match_results<const UChar*> m;
728 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
730 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
731 inline bool u32regex_search(const wchar_t* p,
733 match_flag_type flags = match_default)
735 match_results<const wchar_t*> m;
736 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
739 inline bool u32regex_search(const char* p,
741 match_flag_type flags = match_default)
743 match_results<const char*> m;
744 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
746 inline bool u32regex_search(const unsigned char* p,
748 match_flag_type flags = match_default)
750 match_results<const unsigned char*> m;
751 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
753 inline bool u32regex_search(const std::string& s,
755 match_flag_type flags = match_default)
757 match_results<std::string::const_iterator> m;
758 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
760 #ifndef BOOST_NO_STD_WSTRING
761 inline bool u32regex_search(const std::wstring& s,
763 match_flag_type flags = match_default)
765 match_results<std::wstring::const_iterator> m;
766 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
769 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
771 match_flag_type flags = match_default)
773 match_results<const UChar*> m;
774 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
778 // overloads for regex_replace with utf-8 and utf-16 data types:
780 namespace BOOST_REGEX_DETAIL_NS{
782 inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
783 make_utf32_seq(I i, I j, mpl::int_<1> const*)
785 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));
788 inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
789 make_utf32_seq(I i, I j, mpl::int_<2> const*)
791 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));
794 inline std::pair< I, I >
795 make_utf32_seq(I i, I j, mpl::int_<4> const*)
797 return std::pair< I, I >(i, j);
799 template <class charT>
800 inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
801 make_utf32_seq(const charT* p, mpl::int_<1> const*)
803 std::size_t len = std::strlen((const char*)p);
804 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));
806 template <class charT>
807 inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
808 make_utf32_seq(const charT* p, mpl::int_<2> const*)
810 std::size_t len = u_strlen((const UChar*)p);
811 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));
813 template <class charT>
814 inline std::pair< const charT*, const charT* >
815 make_utf32_seq(const charT* p, mpl::int_<4> const*)
817 return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
819 template <class OutputIterator>
820 inline OutputIterator make_utf32_out(OutputIterator o, mpl::int_<4> const*)
824 template <class OutputIterator>
825 inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<2> const*)
829 template <class OutputIterator>
830 inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<1> const*)
835 template <class OutputIterator, class I1, class I2>
836 OutputIterator do_regex_replace(OutputIterator out,
837 std::pair<I1, I1> const& in,
839 const std::pair<I2, I2>& fmt,
840 match_flag_type flags
843 // unfortunately we have to copy the format string in order to pass in onward:
844 std::vector<UChar32> f;
845 #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
846 f.assign(fmt.first, fmt.second);
850 while(pos != fmt.second)
854 regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
855 regex_iterator<I1, UChar32, icu_regex_traits> j;
858 if(!(flags & regex_constants::format_no_copy))
859 out = BOOST_REGEX_DETAIL_NS::copy(in.first, in.second, out);
863 I1 last_m = in.first;
866 if(!(flags & regex_constants::format_no_copy))
867 out = BOOST_REGEX_DETAIL_NS::copy(i->prefix().first, i->prefix().second, out);
869 out = ::boost::BOOST_REGEX_DETAIL_NS::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
871 out = ::boost::BOOST_REGEX_DETAIL_NS::regex_format_imp(out, *i, static_cast<UChar32 const*>(0), static_cast<UChar32 const*>(0), flags, e.get_traits());
872 last_m = (*i)[0].second;
873 if(flags & regex_constants::format_first_only)
877 if(!(flags & regex_constants::format_no_copy))
878 out = BOOST_REGEX_DETAIL_NS::copy(last_m, in.second, out);
882 template <class BaseIterator>
883 inline const BaseIterator& extract_output_base(const BaseIterator& b)
887 template <class BaseIterator>
888 inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
892 template <class BaseIterator>
893 inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
897 } // BOOST_REGEX_DETAIL_NS
899 template <class OutputIterator, class BidirectionalIterator, class charT>
900 inline OutputIterator u32regex_replace(OutputIterator out,
901 BidirectionalIterator first,
902 BidirectionalIterator last,
905 match_flag_type flags = match_default)
907 return BOOST_REGEX_DETAIL_NS::extract_output_base
909 BOOST_REGEX_DETAIL_NS::do_regex_replace(
910 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
911 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
913 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt, static_cast<mpl::int_<sizeof(*fmt)> const*>(0)),
918 template <class OutputIterator, class Iterator, class charT>
919 inline OutputIterator u32regex_replace(OutputIterator out,
923 const std::basic_string<charT>& fmt,
924 match_flag_type flags = match_default)
926 return BOOST_REGEX_DETAIL_NS::extract_output_base
928 BOOST_REGEX_DETAIL_NS::do_regex_replace(
929 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
930 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
932 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<mpl::int_<sizeof(charT)> const*>(0)),
937 template <class OutputIterator, class Iterator>
938 inline OutputIterator u32regex_replace(OutputIterator out,
942 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
943 match_flag_type flags = match_default)
945 return BOOST_REGEX_DETAIL_NS::extract_output_base
947 BOOST_REGEX_DETAIL_NS::do_regex_replace(
948 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
949 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
951 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
956 template <class charT>
957 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
960 match_flag_type flags = match_default)
962 std::basic_string<charT> result;
963 BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
964 u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
968 template <class charT>
969 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
971 const std::basic_string<charT>& fmt,
972 match_flag_type flags = match_default)
974 std::basic_string<charT> result;
975 BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
976 u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
980 namespace BOOST_REGEX_DETAIL_NS{
982 class unicode_string_out_iterator
984 U_NAMESPACE_QUALIFIER UnicodeString* out;
986 unicode_string_out_iterator(U_NAMESPACE_QUALIFIER UnicodeString& s) : out(&s) {}
987 unicode_string_out_iterator& operator++() { return *this; }
988 unicode_string_out_iterator& operator++(int) { return *this; }
989 unicode_string_out_iterator& operator*() { return *this; }
990 unicode_string_out_iterator& operator=(UChar v)
995 typedef std::ptrdiff_t difference_type;
996 typedef UChar value_type;
997 typedef value_type* pointer;
998 typedef value_type& reference;
999 typedef std::output_iterator_tag iterator_category;
1004 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1007 match_flag_type flags = match_default)
1009 U_NAMESPACE_QUALIFIER UnicodeString result;
1010 BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
1011 u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
1015 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1017 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1018 match_flag_type flags = match_default)
1020 U_NAMESPACE_QUALIFIER UnicodeString result;
1021 BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
1022 BOOST_REGEX_DETAIL_NS::do_regex_replace(
1023 BOOST_REGEX_DETAIL_NS::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)),
1024 BOOST_REGEX_DETAIL_NS::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<mpl::int_<2> const*>(0)),
1026 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
1031 } // namespace boost.
1034 #pragma warning (pop)
1037 #include <boost/regex/v4/u32regex_iterator.hpp>
1038 #include <boost/regex/v4/u32regex_token_iterator.hpp>