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>
29 #include <boost/static_assert.hpp>
33 #pragma warning (push)
34 #pragma warning (disable: 4251)
39 namespace BOOST_REGEX_DETAIL_NS{
42 // Implementation details:
44 class BOOST_REGEX_DECL icu_regex_traits_implementation
46 typedef UChar32 char_type;
47 typedef std::size_t size_type;
48 typedef std::vector<char_type> string_type;
49 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
50 typedef boost::uint_least32_t char_class_type;
52 icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
55 UErrorCode success = U_ZERO_ERROR;
56 m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
57 if(U_SUCCESS(success) == 0)
59 m_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::IDENTICAL);
60 success = U_ZERO_ERROR;
61 m_primary_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
62 if(U_SUCCESS(success) == 0)
64 m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
66 U_NAMESPACE_QUALIFIER Locale getloc()const
70 string_type do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const;
71 string_type transform(const char_type* p1, const char_type* p2) const
73 return do_transform(p1, p2, m_collator.get());
75 string_type transform_primary(const char_type* p1, const char_type* p2) const
77 return do_transform(p1, p2, m_primary_collator.get());
82 std::runtime_error e("Could not initialize ICU resources");
83 boost::throw_exception(e);
85 U_NAMESPACE_QUALIFIER Locale m_locale; // The ICU locale that we're using
86 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_collator; // The full collation object
87 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_primary_collator; // The primary collation object
90 inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
92 return boost::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
97 class BOOST_REGEX_DECL icu_regex_traits
100 typedef UChar32 char_type;
101 typedef std::size_t size_type;
102 typedef std::vector<char_type> string_type;
103 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
104 #ifdef BOOST_NO_INT64_T
105 typedef std::bitset<64> char_class_type;
107 typedef boost::uint64_t char_class_type;
110 struct boost_extensions_tag{};
113 : m_pimpl(BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
116 static size_type length(const char_type* p);
118 ::boost::regex_constants::syntax_type syntax_type(char_type c)const
120 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
122 ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
124 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
126 char_type translate(char_type c) const
130 char_type translate_nocase(char_type c) const
132 return ::u_tolower(c);
134 char_type translate(char_type c, bool icase) const
136 return icase ? translate_nocase(c) : translate(c);
138 char_type tolower(char_type c) const
140 return ::u_tolower(c);
142 char_type toupper(char_type c) const
144 return ::u_toupper(c);
146 string_type transform(const char_type* p1, const char_type* p2) const
148 return m_pimpl->transform(p1, p2);
150 string_type transform_primary(const char_type* p1, const char_type* p2) const
152 return m_pimpl->transform_primary(p1, p2);
154 char_class_type lookup_classname(const char_type* p1, const char_type* p2) const;
155 string_type lookup_collatename(const char_type* p1, const char_type* p2) const;
156 bool isctype(char_type c, char_class_type f) const;
157 boost::intmax_t toi(const char_type*& p1, const char_type* p2, int radix)const
159 return BOOST_REGEX_DETAIL_NS::global_toi(p1, p2, radix, *this);
161 int value(char_type c, int radix)const
163 return u_digit(c, static_cast< ::int8_t>(radix));
165 locale_type imbue(locale_type l)
167 locale_type result(m_pimpl->getloc());
168 m_pimpl = BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(l);
171 locale_type getloc()const
173 return locale_type();
175 std::string error_string(::boost::regex_constants::error_type n) const
177 return BOOST_REGEX_DETAIL_NS::get_default_error_string(n);
180 icu_regex_traits(const icu_regex_traits&);
181 icu_regex_traits& operator=(const icu_regex_traits&);
184 // define the bitmasks offsets we need for additional character properties:
187 offset_blank = U_CHAR_CATEGORY_COUNT,
188 offset_space = U_CHAR_CATEGORY_COUNT+1,
189 offset_xdigit = U_CHAR_CATEGORY_COUNT+2,
190 offset_underscore = U_CHAR_CATEGORY_COUNT+3,
191 offset_unicode = U_CHAR_CATEGORY_COUNT+4,
192 offset_any = U_CHAR_CATEGORY_COUNT+5,
193 offset_ascii = U_CHAR_CATEGORY_COUNT+6,
194 offset_horizontal = U_CHAR_CATEGORY_COUNT+7,
195 offset_vertical = U_CHAR_CATEGORY_COUNT+8
199 // and now the masks:
201 static const char_class_type mask_blank;
202 static const char_class_type mask_space;
203 static const char_class_type mask_xdigit;
204 static const char_class_type mask_underscore;
205 static const char_class_type mask_unicode;
206 static const char_class_type mask_any;
207 static const char_class_type mask_ascii;
208 static const char_class_type mask_horizontal;
209 static const char_class_type mask_vertical;
211 static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
213 boost::shared_ptr< ::boost::BOOST_REGEX_DETAIL_NS::icu_regex_traits_implementation> m_pimpl;
219 // template instances:
221 #define BOOST_REGEX_CHAR_T UChar32
222 #undef BOOST_REGEX_TRAITS_T
223 #define BOOST_REGEX_TRAITS_T , icu_regex_traits
224 #define BOOST_REGEX_ICU_INSTANCES
225 #ifdef BOOST_REGEX_ICU_INSTANTIATE
226 # define BOOST_REGEX_INSTANTIATE
228 #include <boost/regex/v4/instances.hpp>
229 #undef BOOST_REGEX_CHAR_T
230 #undef BOOST_REGEX_TRAITS_T
231 #undef BOOST_REGEX_ICU_INSTANCES
232 #ifdef BOOST_REGEX_INSTANTIATE
233 # undef BOOST_REGEX_INSTANTIATE
239 typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
240 typedef match_results<const ::UChar32*> u32match;
241 typedef match_results<const ::UChar*> u16match;
244 // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
246 namespace BOOST_REGEX_DETAIL_NS{
248 #if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
249 template <class InputIterator>
250 inline u32regex do_make_u32regex(InputIterator i,
252 boost::regex_constants::syntax_option_type opt,
253 const boost::mpl::int_<1>*)
255 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
256 return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
259 template <class InputIterator>
260 inline u32regex do_make_u32regex(InputIterator i,
262 boost::regex_constants::syntax_option_type opt,
263 const boost::mpl::int_<2>*)
265 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
266 return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
269 template <class InputIterator>
270 inline u32regex do_make_u32regex(InputIterator i,
272 boost::regex_constants::syntax_option_type opt,
273 const boost::mpl::int_<4>*)
275 return u32regex(i, j, opt);
278 template <class InputIterator>
279 inline u32regex do_make_u32regex(InputIterator i,
281 boost::regex_constants::syntax_option_type opt,
282 const boost::mpl::int_<1>*)
284 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
285 typedef std::vector<UChar32> vector_type;
287 conv_type a(i, i, j), b(j, i, j);
294 return u32regex(&*v.begin(), v.size(), opt);
295 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
298 template <class InputIterator>
299 inline u32regex do_make_u32regex(InputIterator i,
301 boost::regex_constants::syntax_option_type opt,
302 const boost::mpl::int_<2>*)
304 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
305 typedef std::vector<UChar32> vector_type;
307 conv_type a(i, i, j), b(j, i, j);
314 return u32regex(&*v.begin(), v.size(), opt);
315 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
318 template <class InputIterator>
319 inline u32regex do_make_u32regex(InputIterator i,
321 boost::regex_constants::syntax_option_type opt,
322 const boost::mpl::int_<4>*)
324 typedef std::vector<UChar32> vector_type;
328 v.push_back((UChar32)(*i));
332 return u32regex(&*v.begin(), v.size(), opt);
333 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
338 // BOOST_REGEX_UCHAR_IS_WCHAR_T
340 // Source inspection of unicode/umachine.h in ICU version 59 indicates that:
342 // On version 59, UChar is always char16_t in C++ mode (and uint16_t in C mode)
344 // On earlier versions, the logic is
346 // #if U_SIZEOF_WCHAR_T==2
347 // typedef wchar_t OldUChar;
348 // #elif defined(__CHAR16_TYPE__)
349 // typedef __CHAR16_TYPE__ OldUChar;
351 // typedef uint16_t OldUChar;
354 // That is, UChar is wchar_t only on versions below 59, when U_SIZEOF_WCHAR_T==2
358 #define BOOST_REGEX_UCHAR_IS_WCHAR_T (U_ICU_VERSION_MAJOR_NUM < 59 && U_SIZEOF_WCHAR_T == 2)
360 #if BOOST_REGEX_UCHAR_IS_WCHAR_T
361 BOOST_STATIC_ASSERT((boost::is_same<UChar, wchar_t>::value));
363 BOOST_STATIC_ASSERT(!(boost::is_same<UChar, wchar_t>::value));
367 // Construction from an iterator pair:
369 template <class InputIterator>
370 inline u32regex make_u32regex(InputIterator i,
372 boost::regex_constants::syntax_option_type opt)
374 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(i, j, opt, static_cast<boost::mpl::int_<sizeof(*i)> const*>(0));
377 // construction from UTF-8 nul-terminated strings:
379 inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
381 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<boost::mpl::int_<1> const*>(0));
383 inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
385 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));
388 // construction from UTF-16 nul-terminated strings:
390 #ifndef BOOST_NO_WREGEX
391 inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
393 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<boost::mpl::int_<sizeof(wchar_t)> const*>(0));
396 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T
397 inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
399 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
403 // construction from basic_string class-template:
405 template<class C, class T, class A>
406 inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
408 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.begin(), s.end(), opt, static_cast<boost::mpl::int_<sizeof(C)> const*>(0));
411 // Construction from ICU string type:
413 inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
415 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
419 // regex_match overloads that widen the character type as appropriate:
421 namespace BOOST_REGEX_DETAIL_NS{
422 template<class MR1, class MR2, class NSubs>
423 void copy_results(MR1& out, MR2 const& in, NSubs named_subs)
425 // copy results from an adapted MR2 match_results:
426 out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
427 out.set_base(in.base().base());
428 out.set_named_subs(named_subs);
429 for(int i = 0; i < (int)in.size(); ++i)
431 if(in[i].matched || !i)
433 out.set_first(in[i].first.base(), i);
434 out.set_second(in[i].second.base(), i, in[i].matched);
437 #ifdef BOOST_REGEX_MATCH_EXTRA
438 // Copy full capture info as well:
439 for(int i = 0; i < (int)in.size(); ++i)
441 if(in[i].captures().size())
443 out[i].get_captures().assign(in[i].captures().size(), typename MR1::value_type());
444 for(int j = 0; j < (int)out[i].captures().size(); ++j)
446 out[i].get_captures()[j].first = in[i].captures()[j].first.base();
447 out[i].get_captures()[j].second = in[i].captures()[j].second.base();
448 out[i].get_captures()[j].matched = in[i].captures()[j].matched;
455 template <class BidiIterator, class Allocator>
456 inline bool do_regex_match(BidiIterator first, BidiIterator last,
457 match_results<BidiIterator, Allocator>& m,
459 match_flag_type flags,
460 boost::mpl::int_<4> const*)
462 return ::boost::regex_match(first, last, m, e, flags);
464 template <class BidiIterator, class Allocator>
465 bool do_regex_match(BidiIterator first, BidiIterator last,
466 match_results<BidiIterator, Allocator>& m,
468 match_flag_type flags,
469 boost::mpl::int_<2> const*)
471 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
472 typedef match_results<conv_type> match_type;
473 //typedef typename match_type::allocator_type alloc_type;
475 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
476 // copy results across to m:
477 if(result) copy_results(m, what, e.get_named_subs());
480 template <class BidiIterator, class Allocator>
481 bool do_regex_match(BidiIterator first, BidiIterator last,
482 match_results<BidiIterator, Allocator>& m,
484 match_flag_type flags,
485 boost::mpl::int_<1> const*)
487 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
488 typedef match_results<conv_type> match_type;
489 //typedef typename match_type::allocator_type alloc_type;
491 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
492 // copy results across to m:
493 if(result) copy_results(m, what, e.get_named_subs());
496 } // namespace BOOST_REGEX_DETAIL_NS
498 template <class BidiIterator, class Allocator>
499 inline bool u32regex_match(BidiIterator first, BidiIterator last,
500 match_results<BidiIterator, Allocator>& m,
502 match_flag_type flags = match_default)
504 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
506 inline bool u32regex_match(const UChar* p,
507 match_results<const UChar*>& m,
509 match_flag_type flags = match_default)
511 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
513 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
514 inline bool u32regex_match(const wchar_t* p,
515 match_results<const wchar_t*>& m,
517 match_flag_type flags = match_default)
519 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));
522 inline bool u32regex_match(const char* p,
523 match_results<const char*>& m,
525 match_flag_type flags = match_default)
527 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
529 inline bool u32regex_match(const unsigned char* p,
530 match_results<const unsigned char*>& m,
532 match_flag_type flags = match_default)
534 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));
536 inline bool u32regex_match(const std::string& s,
537 match_results<std::string::const_iterator>& m,
539 match_flag_type flags = match_default)
541 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
543 #ifndef BOOST_NO_STD_WSTRING
544 inline bool u32regex_match(const std::wstring& s,
545 match_results<std::wstring::const_iterator>& m,
547 match_flag_type flags = match_default)
549 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
552 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
553 match_results<const UChar*>& m,
555 match_flag_type flags = match_default)
557 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));
560 // regex_match overloads that do not return what matched:
562 template <class BidiIterator>
563 inline bool u32regex_match(BidiIterator first, BidiIterator last,
565 match_flag_type flags = match_default)
567 match_results<BidiIterator> m;
568 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
570 inline bool u32regex_match(const UChar* p,
572 match_flag_type flags = match_default)
574 match_results<const UChar*> m;
575 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
577 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
578 inline bool u32regex_match(const wchar_t* p,
580 match_flag_type flags = match_default)
582 match_results<const wchar_t*> m;
583 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));
586 inline bool u32regex_match(const char* p,
588 match_flag_type flags = match_default)
590 match_results<const char*> m;
591 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
593 inline bool u32regex_match(const unsigned char* p,
595 match_flag_type flags = match_default)
597 match_results<const unsigned char*> m;
598 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));
600 inline bool u32regex_match(const std::string& s,
602 match_flag_type flags = match_default)
604 match_results<std::string::const_iterator> m;
605 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
607 #ifndef BOOST_NO_STD_WSTRING
608 inline bool u32regex_match(const std::wstring& s,
610 match_flag_type flags = match_default)
612 match_results<std::wstring::const_iterator> m;
613 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
616 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
618 match_flag_type flags = match_default)
620 match_results<const UChar*> m;
621 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));
625 // regex_search overloads that widen the character type as appropriate:
627 namespace BOOST_REGEX_DETAIL_NS{
628 template <class BidiIterator, class Allocator>
629 inline bool do_regex_search(BidiIterator first, BidiIterator last,
630 match_results<BidiIterator, Allocator>& m,
632 match_flag_type flags,
634 boost::mpl::int_<4> const*)
636 return ::boost::regex_search(first, last, m, e, flags, base);
638 template <class BidiIterator, class Allocator>
639 bool do_regex_search(BidiIterator first, BidiIterator last,
640 match_results<BidiIterator, Allocator>& m,
642 match_flag_type flags,
644 boost::mpl::int_<2> const*)
646 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
647 typedef match_results<conv_type> match_type;
648 //typedef typename match_type::allocator_type alloc_type;
650 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
651 // copy results across to m:
652 if(result) copy_results(m, what, e.get_named_subs());
655 template <class BidiIterator, class Allocator>
656 bool do_regex_search(BidiIterator first, BidiIterator last,
657 match_results<BidiIterator, Allocator>& m,
659 match_flag_type flags,
661 boost::mpl::int_<1> const*)
663 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
664 typedef match_results<conv_type> match_type;
665 //typedef typename match_type::allocator_type alloc_type;
667 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
668 // copy results across to m:
669 if(result) copy_results(m, what, e.get_named_subs());
674 template <class BidiIterator, class Allocator>
675 inline bool u32regex_search(BidiIterator first, BidiIterator last,
676 match_results<BidiIterator, Allocator>& m,
678 match_flag_type flags = match_default)
680 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
682 template <class BidiIterator, class Allocator>
683 inline bool u32regex_search(BidiIterator first, BidiIterator last,
684 match_results<BidiIterator, Allocator>& m,
686 match_flag_type flags,
689 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, base, static_cast<mpl::int_<sizeof(*first)> const*>(0));
691 inline bool u32regex_search(const UChar* p,
692 match_results<const UChar*>& m,
694 match_flag_type flags = match_default)
696 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
698 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
699 inline bool u32regex_search(const wchar_t* p,
700 match_results<const wchar_t*>& m,
702 match_flag_type flags = match_default)
704 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));
707 inline bool u32regex_search(const char* p,
708 match_results<const char*>& m,
710 match_flag_type flags = match_default)
712 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
714 inline bool u32regex_search(const unsigned char* p,
715 match_results<const unsigned char*>& m,
717 match_flag_type flags = match_default)
719 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));
721 inline bool u32regex_search(const std::string& s,
722 match_results<std::string::const_iterator>& m,
724 match_flag_type flags = match_default)
726 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
728 #ifndef BOOST_NO_STD_WSTRING
729 inline bool u32regex_search(const std::wstring& s,
730 match_results<std::wstring::const_iterator>& m,
732 match_flag_type flags = match_default)
734 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));
737 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
738 match_results<const UChar*>& m,
740 match_flag_type flags = match_default)
742 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));
744 template <class BidiIterator>
745 inline bool u32regex_search(BidiIterator first, BidiIterator last,
747 match_flag_type flags = match_default)
749 match_results<BidiIterator> m;
750 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
752 inline bool u32regex_search(const UChar* p,
754 match_flag_type flags = match_default)
756 match_results<const UChar*> m;
757 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
759 #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
760 inline bool u32regex_search(const wchar_t* p,
762 match_flag_type flags = match_default)
764 match_results<const wchar_t*> m;
765 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));
768 inline bool u32regex_search(const char* p,
770 match_flag_type flags = match_default)
772 match_results<const char*> m;
773 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
775 inline bool u32regex_search(const unsigned char* p,
777 match_flag_type flags = match_default)
779 match_results<const unsigned char*> m;
780 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));
782 inline bool u32regex_search(const std::string& s,
784 match_flag_type flags = match_default)
786 match_results<std::string::const_iterator> m;
787 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
789 #ifndef BOOST_NO_STD_WSTRING
790 inline bool u32regex_search(const std::wstring& s,
792 match_flag_type flags = match_default)
794 match_results<std::wstring::const_iterator> m;
795 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));
798 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
800 match_flag_type flags = match_default)
802 match_results<const UChar*> m;
803 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));
807 // overloads for regex_replace with utf-8 and utf-16 data types:
809 namespace BOOST_REGEX_DETAIL_NS{
811 inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
812 make_utf32_seq(I i, I j, mpl::int_<1> const*)
814 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));
817 inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
818 make_utf32_seq(I i, I j, mpl::int_<2> const*)
820 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));
823 inline std::pair< I, I >
824 make_utf32_seq(I i, I j, mpl::int_<4> const*)
826 return std::pair< I, I >(i, j);
828 template <class charT>
829 inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
830 make_utf32_seq(const charT* p, mpl::int_<1> const*)
832 std::size_t len = std::strlen((const char*)p);
833 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));
835 template <class charT>
836 inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
837 make_utf32_seq(const charT* p, mpl::int_<2> const*)
839 std::size_t len = u_strlen((const UChar*)p);
840 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));
842 template <class charT>
843 inline std::pair< const charT*, const charT* >
844 make_utf32_seq(const charT* p, mpl::int_<4> const*)
846 return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
848 template <class OutputIterator>
849 inline OutputIterator make_utf32_out(OutputIterator o, mpl::int_<4> const*)
853 template <class OutputIterator>
854 inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<2> const*)
858 template <class OutputIterator>
859 inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<1> const*)
864 template <class OutputIterator, class I1, class I2>
865 OutputIterator do_regex_replace(OutputIterator out,
866 std::pair<I1, I1> const& in,
868 const std::pair<I2, I2>& fmt,
869 match_flag_type flags
872 // unfortunately we have to copy the format string in order to pass in onward:
873 std::vector<UChar32> f;
874 #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
875 f.assign(fmt.first, fmt.second);
879 while(pos != fmt.second)
883 regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
884 regex_iterator<I1, UChar32, icu_regex_traits> j;
887 if(!(flags & regex_constants::format_no_copy))
888 out = BOOST_REGEX_DETAIL_NS::copy(in.first, in.second, out);
892 I1 last_m = in.first;
895 if(!(flags & regex_constants::format_no_copy))
896 out = BOOST_REGEX_DETAIL_NS::copy(i->prefix().first, i->prefix().second, out);
898 out = ::boost::BOOST_REGEX_DETAIL_NS::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
900 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());
901 last_m = (*i)[0].second;
902 if(flags & regex_constants::format_first_only)
906 if(!(flags & regex_constants::format_no_copy))
907 out = BOOST_REGEX_DETAIL_NS::copy(last_m, in.second, out);
911 template <class BaseIterator>
912 inline const BaseIterator& extract_output_base(const BaseIterator& b)
916 template <class BaseIterator>
917 inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
921 template <class BaseIterator>
922 inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
926 } // BOOST_REGEX_DETAIL_NS
928 template <class OutputIterator, class BidirectionalIterator, class charT>
929 inline OutputIterator u32regex_replace(OutputIterator out,
930 BidirectionalIterator first,
931 BidirectionalIterator last,
934 match_flag_type flags = match_default)
936 return BOOST_REGEX_DETAIL_NS::extract_output_base
938 BOOST_REGEX_DETAIL_NS::do_regex_replace(
939 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
940 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
942 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt, static_cast<mpl::int_<sizeof(*fmt)> const*>(0)),
947 template <class OutputIterator, class Iterator, class charT>
948 inline OutputIterator u32regex_replace(OutputIterator out,
952 const std::basic_string<charT>& fmt,
953 match_flag_type flags = match_default)
955 return BOOST_REGEX_DETAIL_NS::extract_output_base
957 BOOST_REGEX_DETAIL_NS::do_regex_replace(
958 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
959 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
961 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<mpl::int_<sizeof(charT)> const*>(0)),
966 template <class OutputIterator, class Iterator>
967 inline OutputIterator u32regex_replace(OutputIterator out,
971 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
972 match_flag_type flags = match_default)
974 return BOOST_REGEX_DETAIL_NS::extract_output_base
976 BOOST_REGEX_DETAIL_NS::do_regex_replace(
977 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
978 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
980 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
985 template <class charT>
986 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
989 match_flag_type flags = match_default)
991 std::basic_string<charT> result;
992 BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
993 u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
997 template <class charT>
998 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
1000 const std::basic_string<charT>& fmt,
1001 match_flag_type flags = match_default)
1003 std::basic_string<charT> result;
1004 BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
1005 u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
1009 namespace BOOST_REGEX_DETAIL_NS{
1011 class unicode_string_out_iterator
1013 U_NAMESPACE_QUALIFIER UnicodeString* out;
1015 unicode_string_out_iterator(U_NAMESPACE_QUALIFIER UnicodeString& s) : out(&s) {}
1016 unicode_string_out_iterator& operator++() { return *this; }
1017 unicode_string_out_iterator& operator++(int) { return *this; }
1018 unicode_string_out_iterator& operator*() { return *this; }
1019 unicode_string_out_iterator& operator=(UChar v)
1024 typedef std::ptrdiff_t difference_type;
1025 typedef UChar value_type;
1026 typedef value_type* pointer;
1027 typedef value_type& reference;
1028 typedef std::output_iterator_tag iterator_category;
1033 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1036 match_flag_type flags = match_default)
1038 U_NAMESPACE_QUALIFIER UnicodeString result;
1039 BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
1040 u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
1044 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1046 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1047 match_flag_type flags = match_default)
1049 U_NAMESPACE_QUALIFIER UnicodeString result;
1050 BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
1051 BOOST_REGEX_DETAIL_NS::do_regex_replace(
1052 BOOST_REGEX_DETAIL_NS::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)),
1053 BOOST_REGEX_DETAIL_NS::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<mpl::int_<2> const*>(0)),
1055 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
1060 } // namespace boost.
1063 #pragma warning (pop)
1066 #include <boost/regex/v4/u32regex_iterator.hpp>
1067 #include <boost/regex/v4/u32regex_token_iterator.hpp>