6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Unicode regular expressions on top of the ICU Library.
19 #ifndef BOOST_REGEX_ICU_HPP
20 #define BOOST_REGEX_ICU_HPP
22 #include <unicode/utypes.h>
23 #include <unicode/uchar.h>
24 #include <unicode/coll.h>
25 #include <boost/regex.hpp>
26 #include <boost/regex/pending/unicode_iterator.hpp>
27 #include <boost/mpl/int_fwd.hpp>
31 #pragma warning (push)
32 #pragma warning (disable: 4251)
37 namespace BOOST_REGEX_DETAIL_NS{
40 // Implementation details:
42 class BOOST_REGEX_DECL icu_regex_traits_implementation
44 typedef UChar32 char_type;
45 typedef std::size_t size_type;
46 typedef std::vector<char_type> string_type;
47 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
48 typedef boost::uint_least32_t char_class_type;
50 icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
53 UErrorCode success = U_ZERO_ERROR;
54 m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
55 if(U_SUCCESS(success) == 0)
57 m_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::IDENTICAL);
58 success = U_ZERO_ERROR;
59 m_primary_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
60 if(U_SUCCESS(success) == 0)
62 m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
64 U_NAMESPACE_QUALIFIER Locale getloc()const
68 string_type do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const;
69 string_type transform(const char_type* p1, const char_type* p2) const
71 return do_transform(p1, p2, m_collator.get());
73 string_type transform_primary(const char_type* p1, const char_type* p2) const
75 return do_transform(p1, p2, m_primary_collator.get());
80 std::runtime_error e("Could not initialize ICU resources");
81 boost::throw_exception(e);
83 U_NAMESPACE_QUALIFIER Locale m_locale; // The ICU locale that we're using
84 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_collator; // The full collation object
85 boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_primary_collator; // The primary collation object
88 inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
90 return boost::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
95 class BOOST_REGEX_DECL icu_regex_traits
98 typedef UChar32 char_type;
99 typedef std::size_t size_type;
100 typedef std::vector<char_type> string_type;
101 typedef U_NAMESPACE_QUALIFIER Locale locale_type;
102 #ifdef BOOST_NO_INT64_T
103 typedef std::bitset<64> char_class_type;
105 typedef boost::uint64_t char_class_type;
108 struct boost_extensions_tag{};
111 : m_pimpl(BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
114 static size_type length(const char_type* p);
116 ::boost::regex_constants::syntax_type syntax_type(char_type c)const
118 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
120 ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
122 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
124 char_type translate(char_type c) const
128 char_type translate_nocase(char_type c) const
130 return ::u_tolower(c);
132 char_type translate(char_type c, bool icase) const
134 return icase ? translate_nocase(c) : translate(c);
136 char_type tolower(char_type c) const
138 return ::u_tolower(c);
140 char_type toupper(char_type c) const
142 return ::u_toupper(c);
144 string_type transform(const char_type* p1, const char_type* p2) const
146 return m_pimpl->transform(p1, p2);
148 string_type transform_primary(const char_type* p1, const char_type* p2) const
150 return m_pimpl->transform_primary(p1, p2);
152 char_class_type lookup_classname(const char_type* p1, const char_type* p2) const;
153 string_type lookup_collatename(const char_type* p1, const char_type* p2) const;
154 bool isctype(char_type c, char_class_type f) const;
155 boost::intmax_t toi(const char_type*& p1, const char_type* p2, int radix)const
157 return BOOST_REGEX_DETAIL_NS::global_toi(p1, p2, radix, *this);
159 int value(char_type c, int radix)const
161 return u_digit(c, static_cast< ::int8_t>(radix));
163 locale_type imbue(locale_type l)
165 locale_type result(m_pimpl->getloc());
166 m_pimpl = BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(l);
169 locale_type getloc()const
171 return locale_type();
173 std::string error_string(::boost::regex_constants::error_type n) const
175 return BOOST_REGEX_DETAIL_NS::get_default_error_string(n);
178 icu_regex_traits(const icu_regex_traits&);
179 icu_regex_traits& operator=(const icu_regex_traits&);
182 // define the bitmasks offsets we need for additional character properties:
185 offset_blank = U_CHAR_CATEGORY_COUNT,
186 offset_space = U_CHAR_CATEGORY_COUNT+1,
187 offset_xdigit = U_CHAR_CATEGORY_COUNT+2,
188 offset_underscore = U_CHAR_CATEGORY_COUNT+3,
189 offset_unicode = U_CHAR_CATEGORY_COUNT+4,
190 offset_any = U_CHAR_CATEGORY_COUNT+5,
191 offset_ascii = U_CHAR_CATEGORY_COUNT+6,
192 offset_horizontal = U_CHAR_CATEGORY_COUNT+7,
193 offset_vertical = U_CHAR_CATEGORY_COUNT+8
197 // and now the masks:
199 static const char_class_type mask_blank;
200 static const char_class_type mask_space;
201 static const char_class_type mask_xdigit;
202 static const char_class_type mask_underscore;
203 static const char_class_type mask_unicode;
204 static const char_class_type mask_any;
205 static const char_class_type mask_ascii;
206 static const char_class_type mask_horizontal;
207 static const char_class_type mask_vertical;
209 static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
211 boost::shared_ptr< ::boost::BOOST_REGEX_DETAIL_NS::icu_regex_traits_implementation> m_pimpl;
217 // template instances:
219 #define BOOST_REGEX_CHAR_T UChar32
220 #undef BOOST_REGEX_TRAITS_T
221 #define BOOST_REGEX_TRAITS_T , icu_regex_traits
222 #define BOOST_REGEX_ICU_INSTANCES
223 #ifdef BOOST_REGEX_ICU_INSTANTIATE
224 # define BOOST_REGEX_INSTANTIATE
226 #include <boost/regex/v4/instances.hpp>
227 #undef BOOST_REGEX_CHAR_T
228 #undef BOOST_REGEX_TRAITS_T
229 #undef BOOST_REGEX_ICU_INSTANCES
230 #ifdef BOOST_REGEX_INSTANTIATE
231 # undef BOOST_REGEX_INSTANTIATE
237 typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
238 typedef match_results<const ::UChar32*> u32match;
239 typedef match_results<const ::UChar*> u16match;
242 // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
244 namespace BOOST_REGEX_DETAIL_NS{
246 #if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
247 template <class InputIterator>
248 inline u32regex do_make_u32regex(InputIterator i,
250 boost::regex_constants::syntax_option_type opt,
251 const boost::mpl::int_<1>*)
253 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
254 return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
257 template <class InputIterator>
258 inline u32regex do_make_u32regex(InputIterator i,
260 boost::regex_constants::syntax_option_type opt,
261 const boost::mpl::int_<2>*)
263 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
264 return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
267 template <class InputIterator>
268 inline u32regex do_make_u32regex(InputIterator i,
270 boost::regex_constants::syntax_option_type opt,
271 const boost::mpl::int_<4>*)
273 return u32regex(i, j, opt);
276 template <class InputIterator>
277 inline u32regex do_make_u32regex(InputIterator i,
279 boost::regex_constants::syntax_option_type opt,
280 const boost::mpl::int_<1>*)
282 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
283 typedef std::vector<UChar32> vector_type;
285 conv_type a(i, i, j), b(j, i, j);
292 return u32regex(&*v.begin(), v.size(), opt);
293 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
296 template <class InputIterator>
297 inline u32regex do_make_u32regex(InputIterator i,
299 boost::regex_constants::syntax_option_type opt,
300 const boost::mpl::int_<2>*)
302 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
303 typedef std::vector<UChar32> vector_type;
305 conv_type a(i, i, j), b(j, i, j);
312 return u32regex(&*v.begin(), v.size(), opt);
313 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
316 template <class InputIterator>
317 inline u32regex do_make_u32regex(InputIterator i,
319 boost::regex_constants::syntax_option_type opt,
320 const boost::mpl::int_<4>*)
322 typedef std::vector<UChar32> vector_type;
326 v.push_back((UChar32)(*i));
330 return u32regex(&*v.begin(), v.size(), opt);
331 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
337 // Construction from an iterator pair:
339 template <class InputIterator>
340 inline u32regex make_u32regex(InputIterator i,
342 boost::regex_constants::syntax_option_type opt)
344 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(i, j, opt, static_cast<boost::mpl::int_<sizeof(*i)> const*>(0));
347 // construction from UTF-8 nul-terminated strings:
349 inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
351 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<boost::mpl::int_<1> const*>(0));
353 inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
355 return 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));
358 // construction from UTF-16 nul-terminated strings:
360 #ifndef BOOST_NO_WREGEX
361 inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
363 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<boost::mpl::int_<sizeof(wchar_t)> const*>(0));
366 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
367 inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
369 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
373 // construction from basic_string class-template:
375 template<class C, class T, class A>
376 inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
378 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.begin(), s.end(), opt, static_cast<boost::mpl::int_<sizeof(C)> const*>(0));
381 // Construction from ICU string type:
383 inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
385 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
389 // regex_match overloads that widen the character type as appropriate:
391 namespace BOOST_REGEX_DETAIL_NS{
392 template<class MR1, class MR2>
393 void copy_results(MR1& out, MR2 const& in)
395 // copy results from an adapted MR2 match_results:
396 out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
397 out.set_base(in.base().base());
398 for(int i = 0; i < (int)in.size(); ++i)
400 if(in[i].matched || !i)
402 out.set_first(in[i].first.base(), i);
403 out.set_second(in[i].second.base(), i, in[i].matched);
406 #ifdef BOOST_REGEX_MATCH_EXTRA
407 // Copy full capture info as well:
408 for(int i = 0; i < (int)in.size(); ++i)
410 if(in[i].captures().size())
412 out[i].get_captures().assign(in[i].captures().size(), typename MR1::value_type());
413 for(int j = 0; j < (int)out[i].captures().size(); ++j)
415 out[i].get_captures()[j].first = in[i].captures()[j].first.base();
416 out[i].get_captures()[j].second = in[i].captures()[j].second.base();
417 out[i].get_captures()[j].matched = in[i].captures()[j].matched;
424 template <class BidiIterator, class Allocator>
425 inline bool do_regex_match(BidiIterator first, BidiIterator last,
426 match_results<BidiIterator, Allocator>& m,
428 match_flag_type flags,
429 boost::mpl::int_<4> const*)
431 return ::boost::regex_match(first, last, m, e, flags);
433 template <class BidiIterator, class Allocator>
434 bool do_regex_match(BidiIterator first, BidiIterator last,
435 match_results<BidiIterator, Allocator>& m,
437 match_flag_type flags,
438 boost::mpl::int_<2> const*)
440 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
441 typedef match_results<conv_type> match_type;
442 //typedef typename match_type::allocator_type alloc_type;
444 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
445 // copy results across to m:
446 if(result) copy_results(m, what);
449 template <class BidiIterator, class Allocator>
450 bool do_regex_match(BidiIterator first, BidiIterator last,
451 match_results<BidiIterator, Allocator>& m,
453 match_flag_type flags,
454 boost::mpl::int_<1> const*)
456 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
457 typedef match_results<conv_type> match_type;
458 //typedef typename match_type::allocator_type alloc_type;
460 bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
461 // copy results across to m:
462 if(result) copy_results(m, what);
465 } // namespace BOOST_REGEX_DETAIL_NS
467 template <class BidiIterator, class Allocator>
468 inline bool u32regex_match(BidiIterator first, BidiIterator last,
469 match_results<BidiIterator, Allocator>& m,
471 match_flag_type flags = match_default)
473 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
475 inline bool u32regex_match(const UChar* p,
476 match_results<const UChar*>& m,
478 match_flag_type flags = match_default)
480 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
482 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
483 inline bool u32regex_match(const wchar_t* p,
484 match_results<const wchar_t*>& m,
486 match_flag_type flags = match_default)
488 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));
491 inline bool u32regex_match(const char* p,
492 match_results<const char*>& m,
494 match_flag_type flags = match_default)
496 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
498 inline bool u32regex_match(const unsigned char* p,
499 match_results<const unsigned char*>& m,
501 match_flag_type flags = match_default)
503 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));
505 inline bool u32regex_match(const std::string& s,
506 match_results<std::string::const_iterator>& m,
508 match_flag_type flags = match_default)
510 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
512 #ifndef BOOST_NO_STD_WSTRING
513 inline bool u32regex_match(const std::wstring& s,
514 match_results<std::wstring::const_iterator>& m,
516 match_flag_type flags = match_default)
518 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
521 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
522 match_results<const UChar*>& m,
524 match_flag_type flags = match_default)
526 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));
529 // regex_match overloads that do not return what matched:
531 template <class BidiIterator>
532 inline bool u32regex_match(BidiIterator first, BidiIterator last,
534 match_flag_type flags = match_default)
536 match_results<BidiIterator> m;
537 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
539 inline bool u32regex_match(const UChar* p,
541 match_flag_type flags = match_default)
543 match_results<const UChar*> m;
544 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
546 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
547 inline bool u32regex_match(const wchar_t* p,
549 match_flag_type flags = match_default)
551 match_results<const wchar_t*> m;
552 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));
555 inline bool u32regex_match(const char* p,
557 match_flag_type flags = match_default)
559 match_results<const char*> m;
560 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
562 inline bool u32regex_match(const unsigned char* p,
564 match_flag_type flags = match_default)
566 match_results<const unsigned char*> m;
567 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));
569 inline bool u32regex_match(const std::string& s,
571 match_flag_type flags = match_default)
573 match_results<std::string::const_iterator> m;
574 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
576 #ifndef BOOST_NO_STD_WSTRING
577 inline bool u32regex_match(const std::wstring& s,
579 match_flag_type flags = match_default)
581 match_results<std::wstring::const_iterator> m;
582 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
585 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
587 match_flag_type flags = match_default)
589 match_results<const UChar*> m;
590 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));
594 // regex_search overloads that widen the character type as appropriate:
596 namespace BOOST_REGEX_DETAIL_NS{
597 template <class BidiIterator, class Allocator>
598 inline bool do_regex_search(BidiIterator first, BidiIterator last,
599 match_results<BidiIterator, Allocator>& m,
601 match_flag_type flags,
603 boost::mpl::int_<4> const*)
605 return ::boost::regex_search(first, last, m, e, flags, base);
607 template <class BidiIterator, class Allocator>
608 bool do_regex_search(BidiIterator first, BidiIterator last,
609 match_results<BidiIterator, Allocator>& m,
611 match_flag_type flags,
613 boost::mpl::int_<2> const*)
615 typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
616 typedef match_results<conv_type> match_type;
617 //typedef typename match_type::allocator_type alloc_type;
619 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
620 // copy results across to m:
621 if(result) copy_results(m, what);
624 template <class BidiIterator, class Allocator>
625 bool do_regex_search(BidiIterator first, BidiIterator last,
626 match_results<BidiIterator, Allocator>& m,
628 match_flag_type flags,
630 boost::mpl::int_<1> const*)
632 typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
633 typedef match_results<conv_type> match_type;
634 //typedef typename match_type::allocator_type alloc_type;
636 bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
637 // copy results across to m:
638 if(result) copy_results(m, what);
643 template <class BidiIterator, class Allocator>
644 inline bool u32regex_search(BidiIterator first, BidiIterator last,
645 match_results<BidiIterator, Allocator>& m,
647 match_flag_type flags = match_default)
649 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
651 template <class BidiIterator, class Allocator>
652 inline bool u32regex_search(BidiIterator first, BidiIterator last,
653 match_results<BidiIterator, Allocator>& m,
655 match_flag_type flags,
658 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, base, static_cast<mpl::int_<sizeof(*first)> const*>(0));
660 inline bool u32regex_search(const UChar* p,
661 match_results<const UChar*>& m,
663 match_flag_type flags = match_default)
665 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
667 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
668 inline bool u32regex_search(const wchar_t* p,
669 match_results<const wchar_t*>& m,
671 match_flag_type flags = match_default)
673 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));
676 inline bool u32regex_search(const char* p,
677 match_results<const char*>& m,
679 match_flag_type flags = match_default)
681 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
683 inline bool u32regex_search(const unsigned char* p,
684 match_results<const unsigned char*>& m,
686 match_flag_type flags = match_default)
688 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));
690 inline bool u32regex_search(const std::string& s,
691 match_results<std::string::const_iterator>& m,
693 match_flag_type flags = match_default)
695 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
697 #ifndef BOOST_NO_STD_WSTRING
698 inline bool u32regex_search(const std::wstring& s,
699 match_results<std::wstring::const_iterator>& m,
701 match_flag_type flags = match_default)
703 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));
706 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
707 match_results<const UChar*>& m,
709 match_flag_type flags = match_default)
711 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));
713 template <class BidiIterator>
714 inline bool u32regex_search(BidiIterator first, BidiIterator last,
716 match_flag_type flags = match_default)
718 match_results<BidiIterator> m;
719 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
721 inline bool u32regex_search(const UChar* p,
723 match_flag_type flags = match_default)
725 match_results<const UChar*> m;
726 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
728 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
729 inline bool u32regex_search(const wchar_t* p,
731 match_flag_type flags = match_default)
733 match_results<const wchar_t*> m;
734 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));
737 inline bool u32regex_search(const char* p,
739 match_flag_type flags = match_default)
741 match_results<const char*> m;
742 return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
744 inline bool u32regex_search(const unsigned char* p,
746 match_flag_type flags = match_default)
748 match_results<const unsigned char*> m;
749 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));
751 inline bool u32regex_search(const std::string& s,
753 match_flag_type flags = match_default)
755 match_results<std::string::const_iterator> m;
756 return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
758 #ifndef BOOST_NO_STD_WSTRING
759 inline bool u32regex_search(const std::wstring& s,
761 match_flag_type flags = match_default)
763 match_results<std::wstring::const_iterator> m;
764 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));
767 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
769 match_flag_type flags = match_default)
771 match_results<const UChar*> m;
772 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));
776 // overloads for regex_replace with utf-8 and utf-16 data types:
778 namespace BOOST_REGEX_DETAIL_NS{
780 inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
781 make_utf32_seq(I i, I j, mpl::int_<1> const*)
783 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));
786 inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
787 make_utf32_seq(I i, I j, mpl::int_<2> const*)
789 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));
792 inline std::pair< I, I >
793 make_utf32_seq(I i, I j, mpl::int_<4> const*)
795 return std::pair< I, I >(i, j);
797 template <class charT>
798 inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
799 make_utf32_seq(const charT* p, mpl::int_<1> const*)
801 std::size_t len = std::strlen((const char*)p);
802 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));
804 template <class charT>
805 inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
806 make_utf32_seq(const charT* p, mpl::int_<2> const*)
808 std::size_t len = u_strlen((const UChar*)p);
809 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));
811 template <class charT>
812 inline std::pair< const charT*, const charT* >
813 make_utf32_seq(const charT* p, mpl::int_<4> const*)
815 return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
817 template <class OutputIterator>
818 inline OutputIterator make_utf32_out(OutputIterator o, mpl::int_<4> const*)
822 template <class OutputIterator>
823 inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<2> const*)
827 template <class OutputIterator>
828 inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<1> const*)
833 template <class OutputIterator, class I1, class I2>
834 OutputIterator do_regex_replace(OutputIterator out,
835 std::pair<I1, I1> const& in,
837 const std::pair<I2, I2>& fmt,
838 match_flag_type flags
841 // unfortunately we have to copy the format string in order to pass in onward:
842 std::vector<UChar32> f;
843 #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
844 f.assign(fmt.first, fmt.second);
848 while(pos != fmt.second)
852 regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
853 regex_iterator<I1, UChar32, icu_regex_traits> j;
856 if(!(flags & regex_constants::format_no_copy))
857 out = BOOST_REGEX_DETAIL_NS::copy(in.first, in.second, out);
861 I1 last_m = in.first;
864 if(!(flags & regex_constants::format_no_copy))
865 out = BOOST_REGEX_DETAIL_NS::copy(i->prefix().first, i->prefix().second, out);
867 out = ::boost::BOOST_REGEX_DETAIL_NS::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
869 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());
870 last_m = (*i)[0].second;
871 if(flags & regex_constants::format_first_only)
875 if(!(flags & regex_constants::format_no_copy))
876 out = BOOST_REGEX_DETAIL_NS::copy(last_m, in.second, out);
880 template <class BaseIterator>
881 inline const BaseIterator& extract_output_base(const BaseIterator& b)
885 template <class BaseIterator>
886 inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
890 template <class BaseIterator>
891 inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
895 } // BOOST_REGEX_DETAIL_NS
897 template <class OutputIterator, class BidirectionalIterator, class charT>
898 inline OutputIterator u32regex_replace(OutputIterator out,
899 BidirectionalIterator first,
900 BidirectionalIterator last,
903 match_flag_type flags = match_default)
905 return BOOST_REGEX_DETAIL_NS::extract_output_base
907 BOOST_REGEX_DETAIL_NS::do_regex_replace(
908 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
909 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
911 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt, static_cast<mpl::int_<sizeof(*fmt)> const*>(0)),
916 template <class OutputIterator, class Iterator, class charT>
917 inline OutputIterator u32regex_replace(OutputIterator out,
921 const std::basic_string<charT>& fmt,
922 match_flag_type flags = match_default)
924 return BOOST_REGEX_DETAIL_NS::extract_output_base
926 BOOST_REGEX_DETAIL_NS::do_regex_replace(
927 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
928 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
930 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<mpl::int_<sizeof(charT)> const*>(0)),
935 template <class OutputIterator, class Iterator>
936 inline OutputIterator u32regex_replace(OutputIterator out,
940 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
941 match_flag_type flags = match_default)
943 return BOOST_REGEX_DETAIL_NS::extract_output_base
945 BOOST_REGEX_DETAIL_NS::do_regex_replace(
946 BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
947 BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
949 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
954 template <class charT>
955 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
958 match_flag_type flags = match_default)
960 std::basic_string<charT> result;
961 BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
962 u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
966 template <class charT>
967 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
969 const std::basic_string<charT>& fmt,
970 match_flag_type flags = match_default)
972 std::basic_string<charT> result;
973 BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
974 u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
978 namespace BOOST_REGEX_DETAIL_NS{
980 class unicode_string_out_iterator
982 U_NAMESPACE_QUALIFIER UnicodeString* out;
984 unicode_string_out_iterator(U_NAMESPACE_QUALIFIER UnicodeString& s) : out(&s) {}
985 unicode_string_out_iterator& operator++() { return *this; }
986 unicode_string_out_iterator& operator++(int) { return *this; }
987 unicode_string_out_iterator& operator*() { return *this; }
988 unicode_string_out_iterator& operator=(UChar v)
993 typedef std::ptrdiff_t difference_type;
994 typedef UChar value_type;
995 typedef value_type* pointer;
996 typedef value_type& reference;
997 typedef std::output_iterator_tag iterator_category;
1002 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1005 match_flag_type flags = match_default)
1007 U_NAMESPACE_QUALIFIER UnicodeString result;
1008 BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
1009 u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
1013 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1015 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1016 match_flag_type flags = match_default)
1018 U_NAMESPACE_QUALIFIER UnicodeString result;
1019 BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
1020 BOOST_REGEX_DETAIL_NS::do_regex_replace(
1021 BOOST_REGEX_DETAIL_NS::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)),
1022 BOOST_REGEX_DETAIL_NS::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<mpl::int_<2> const*>(0)),
1024 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
1029 } // namespace boost.
1032 #pragma warning (pop)
1035 #include <boost/regex/v4/u32regex_iterator.hpp>
1036 #include <boost/regex/v4/u32regex_token_iterator.hpp>