]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/regex/icu.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / regex / icu.hpp
1 /*
2 *
3 * Copyright (c) 2004
4 * John Maddock
5 *
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)
9 *
10 */
11
12 /*
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE icu.hpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Unicode regular expressions on top of the ICU Library.
17 */
18
19 #ifndef BOOST_REGEX_ICU_HPP
20 #define BOOST_REGEX_ICU_HPP
21
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 <bitset>
30
31 #ifdef BOOST_MSVC
32 #pragma warning (push)
33 #pragma warning (disable: 4251)
34 #endif
35
36 namespace boost{
37
38 namespace BOOST_REGEX_DETAIL_NS{
39
40 //
41 // Implementation details:
42 //
43 class BOOST_REGEX_DECL icu_regex_traits_implementation
44 {
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;
50 public:
51 icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
52 : m_locale(l)
53 {
54 UErrorCode success = U_ZERO_ERROR;
55 m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
56 if(U_SUCCESS(success) == 0)
57 init_error();
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)
62 init_error();
63 m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
64 }
65 U_NAMESPACE_QUALIFIER Locale getloc()const
66 {
67 return m_locale;
68 }
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
71 {
72 return do_transform(p1, p2, m_collator.get());
73 }
74 string_type transform_primary(const char_type* p1, const char_type* p2) const
75 {
76 return do_transform(p1, p2, m_primary_collator.get());
77 }
78 private:
79 void init_error()
80 {
81 std::runtime_error e("Could not initialize ICU resources");
82 boost::throw_exception(e);
83 }
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
87 };
88
89 inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
90 {
91 return boost::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
92 }
93
94 }
95
96 class BOOST_REGEX_DECL icu_regex_traits
97 {
98 public:
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;
105 #else
106 typedef boost::uint64_t char_class_type;
107 #endif
108
109 struct boost_extensions_tag{};
110
111 icu_regex_traits()
112 : m_pimpl(BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
113 {
114 }
115 static size_type length(const char_type* p);
116
117 ::boost::regex_constants::syntax_type syntax_type(char_type c)const
118 {
119 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
120 }
121 ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
122 {
123 return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
124 }
125 char_type translate(char_type c) const
126 {
127 return c;
128 }
129 char_type translate_nocase(char_type c) const
130 {
131 return ::u_tolower(c);
132 }
133 char_type translate(char_type c, bool icase) const
134 {
135 return icase ? translate_nocase(c) : translate(c);
136 }
137 char_type tolower(char_type c) const
138 {
139 return ::u_tolower(c);
140 }
141 char_type toupper(char_type c) const
142 {
143 return ::u_toupper(c);
144 }
145 string_type transform(const char_type* p1, const char_type* p2) const
146 {
147 return m_pimpl->transform(p1, p2);
148 }
149 string_type transform_primary(const char_type* p1, const char_type* p2) const
150 {
151 return m_pimpl->transform_primary(p1, p2);
152 }
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
157 {
158 return BOOST_REGEX_DETAIL_NS::global_toi(p1, p2, radix, *this);
159 }
160 int value(char_type c, int radix)const
161 {
162 return u_digit(c, static_cast< ::int8_t>(radix));
163 }
164 locale_type imbue(locale_type l)
165 {
166 locale_type result(m_pimpl->getloc());
167 m_pimpl = BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(l);
168 return result;
169 }
170 locale_type getloc()const
171 {
172 return locale_type();
173 }
174 std::string error_string(::boost::regex_constants::error_type n) const
175 {
176 return BOOST_REGEX_DETAIL_NS::get_default_error_string(n);
177 }
178 private:
179 icu_regex_traits(const icu_regex_traits&);
180 icu_regex_traits& operator=(const icu_regex_traits&);
181
182 //
183 // define the bitmasks offsets we need for additional character properties:
184 //
185 enum{
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
195 };
196
197 //
198 // and now the masks:
199 //
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;
209
210 static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
211
212 boost::shared_ptr< ::boost::BOOST_REGEX_DETAIL_NS::icu_regex_traits_implementation> m_pimpl;
213 };
214
215 } // namespace boost
216
217 //
218 // template instances:
219 //
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
226 #endif
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
233 #endif
234
235 namespace boost{
236
237 // types:
238 typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
239 typedef match_results<const ::UChar32*> u32match;
240 typedef match_results<const ::UChar*> u16match;
241
242 //
243 // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
244 //
245 namespace BOOST_REGEX_DETAIL_NS{
246
247 #if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
248 template <class InputIterator>
249 inline u32regex do_make_u32regex(InputIterator i,
250 InputIterator j,
251 boost::regex_constants::syntax_option_type opt,
252 const boost::mpl::int_<1>*)
253 {
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);
256 }
257
258 template <class InputIterator>
259 inline u32regex do_make_u32regex(InputIterator i,
260 InputIterator j,
261 boost::regex_constants::syntax_option_type opt,
262 const boost::mpl::int_<2>*)
263 {
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);
266 }
267
268 template <class InputIterator>
269 inline u32regex do_make_u32regex(InputIterator i,
270 InputIterator j,
271 boost::regex_constants::syntax_option_type opt,
272 const boost::mpl::int_<4>*)
273 {
274 return u32regex(i, j, opt);
275 }
276 #else
277 template <class InputIterator>
278 inline u32regex do_make_u32regex(InputIterator i,
279 InputIterator j,
280 boost::regex_constants::syntax_option_type opt,
281 const boost::mpl::int_<1>*)
282 {
283 typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
284 typedef std::vector<UChar32> vector_type;
285 vector_type v;
286 conv_type a(i, i, j), b(j, i, j);
287 while(a != b)
288 {
289 v.push_back(*a);
290 ++a;
291 }
292 if(v.size())
293 return u32regex(&*v.begin(), v.size(), opt);
294 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
295 }
296
297 template <class InputIterator>
298 inline u32regex do_make_u32regex(InputIterator i,
299 InputIterator j,
300 boost::regex_constants::syntax_option_type opt,
301 const boost::mpl::int_<2>*)
302 {
303 typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
304 typedef std::vector<UChar32> vector_type;
305 vector_type v;
306 conv_type a(i, i, j), b(j, i, j);
307 while(a != b)
308 {
309 v.push_back(*a);
310 ++a;
311 }
312 if(v.size())
313 return u32regex(&*v.begin(), v.size(), opt);
314 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
315 }
316
317 template <class InputIterator>
318 inline u32regex do_make_u32regex(InputIterator i,
319 InputIterator j,
320 boost::regex_constants::syntax_option_type opt,
321 const boost::mpl::int_<4>*)
322 {
323 typedef std::vector<UChar32> vector_type;
324 vector_type v;
325 while(i != j)
326 {
327 v.push_back((UChar32)(*i));
328 ++i;
329 }
330 if(v.size())
331 return u32regex(&*v.begin(), v.size(), opt);
332 return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
333 }
334 #endif
335 }
336
337 //
338 // Construction from an iterator pair:
339 //
340 template <class InputIterator>
341 inline u32regex make_u32regex(InputIterator i,
342 InputIterator j,
343 boost::regex_constants::syntax_option_type opt)
344 {
345 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(i, j, opt, static_cast<boost::mpl::int_<sizeof(*i)> const*>(0));
346 }
347 //
348 // construction from UTF-8 nul-terminated strings:
349 //
350 inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
351 {
352 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<boost::mpl::int_<1> const*>(0));
353 }
354 inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
355 {
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));
357 }
358 //
359 // construction from UTF-16 nul-terminated strings:
360 //
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)
363 {
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));
365 }
366 #endif
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)
369 {
370 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
371 }
372 #endif
373 //
374 // construction from basic_string class-template:
375 //
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)
378 {
379 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.begin(), s.end(), opt, static_cast<boost::mpl::int_<sizeof(C)> const*>(0));
380 }
381 //
382 // Construction from ICU string type:
383 //
384 inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
385 {
386 return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
387 }
388
389 //
390 // regex_match overloads that widen the character type as appropriate:
391 //
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)
395 {
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)
401 {
402 if(in[i].matched || !i)
403 {
404 out.set_first(in[i].first.base(), i);
405 out.set_second(in[i].second.base(), i, in[i].matched);
406 }
407 }
408 #ifdef BOOST_REGEX_MATCH_EXTRA
409 // Copy full capture info as well:
410 for(int i = 0; i < (int)in.size(); ++i)
411 {
412 if(in[i].captures().size())
413 {
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)
416 {
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;
420 }
421 }
422 }
423 #endif
424 }
425
426 template <class BidiIterator, class Allocator>
427 inline bool do_regex_match(BidiIterator first, BidiIterator last,
428 match_results<BidiIterator, Allocator>& m,
429 const u32regex& e,
430 match_flag_type flags,
431 boost::mpl::int_<4> const*)
432 {
433 return ::boost::regex_match(first, last, m, e, flags);
434 }
435 template <class BidiIterator, class Allocator>
436 bool do_regex_match(BidiIterator first, BidiIterator last,
437 match_results<BidiIterator, Allocator>& m,
438 const u32regex& e,
439 match_flag_type flags,
440 boost::mpl::int_<2> const*)
441 {
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;
445 match_type what;
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());
449 return result;
450 }
451 template <class BidiIterator, class Allocator>
452 bool do_regex_match(BidiIterator first, BidiIterator last,
453 match_results<BidiIterator, Allocator>& m,
454 const u32regex& e,
455 match_flag_type flags,
456 boost::mpl::int_<1> const*)
457 {
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;
461 match_type what;
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());
465 return result;
466 }
467 } // namespace BOOST_REGEX_DETAIL_NS
468
469 template <class BidiIterator, class Allocator>
470 inline bool u32regex_match(BidiIterator first, BidiIterator last,
471 match_results<BidiIterator, Allocator>& m,
472 const u32regex& e,
473 match_flag_type flags = match_default)
474 {
475 return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
476 }
477 inline bool u32regex_match(const UChar* p,
478 match_results<const UChar*>& m,
479 const u32regex& e,
480 match_flag_type flags = match_default)
481 {
482 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
483 }
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,
487 const u32regex& e,
488 match_flag_type flags = match_default)
489 {
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));
491 }
492 #endif
493 inline bool u32regex_match(const char* p,
494 match_results<const char*>& m,
495 const u32regex& e,
496 match_flag_type flags = match_default)
497 {
498 return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
499 }
500 inline bool u32regex_match(const unsigned char* p,
501 match_results<const unsigned char*>& m,
502 const u32regex& e,
503 match_flag_type flags = match_default)
504 {
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));
506 }
507 inline bool u32regex_match(const std::string& s,
508 match_results<std::string::const_iterator>& m,
509 const u32regex& e,
510 match_flag_type flags = match_default)
511 {
512 return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
513 }
514 #ifndef BOOST_NO_STD_WSTRING
515 inline bool u32regex_match(const std::wstring& s,
516 match_results<std::wstring::const_iterator>& m,
517 const u32regex& e,
518 match_flag_type flags = match_default)
519 {
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));
521 }
522 #endif
523 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
524 match_results<const UChar*>& m,
525 const u32regex& e,
526 match_flag_type flags = match_default)
527 {
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));
529 }
530 //
531 // regex_match overloads that do not return what matched:
532 //
533 template <class BidiIterator>
534 inline bool u32regex_match(BidiIterator first, BidiIterator last,
535 const u32regex& e,
536 match_flag_type flags = match_default)
537 {
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));
540 }
541 inline bool u32regex_match(const UChar* p,
542 const u32regex& e,
543 match_flag_type flags = match_default)
544 {
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));
547 }
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,
550 const u32regex& e,
551 match_flag_type flags = match_default)
552 {
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));
555 }
556 #endif
557 inline bool u32regex_match(const char* p,
558 const u32regex& e,
559 match_flag_type flags = match_default)
560 {
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));
563 }
564 inline bool u32regex_match(const unsigned char* p,
565 const u32regex& e,
566 match_flag_type flags = match_default)
567 {
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));
570 }
571 inline bool u32regex_match(const std::string& s,
572 const u32regex& e,
573 match_flag_type flags = match_default)
574 {
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));
577 }
578 #ifndef BOOST_NO_STD_WSTRING
579 inline bool u32regex_match(const std::wstring& s,
580 const u32regex& e,
581 match_flag_type flags = match_default)
582 {
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));
585 }
586 #endif
587 inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
588 const u32regex& e,
589 match_flag_type flags = match_default)
590 {
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));
593 }
594
595 //
596 // regex_search overloads that widen the character type as appropriate:
597 //
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,
602 const u32regex& e,
603 match_flag_type flags,
604 BidiIterator base,
605 boost::mpl::int_<4> const*)
606 {
607 return ::boost::regex_search(first, last, m, e, flags, base);
608 }
609 template <class BidiIterator, class Allocator>
610 bool do_regex_search(BidiIterator first, BidiIterator last,
611 match_results<BidiIterator, Allocator>& m,
612 const u32regex& e,
613 match_flag_type flags,
614 BidiIterator base,
615 boost::mpl::int_<2> const*)
616 {
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;
620 match_type what;
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());
624 return result;
625 }
626 template <class BidiIterator, class Allocator>
627 bool do_regex_search(BidiIterator first, BidiIterator last,
628 match_results<BidiIterator, Allocator>& m,
629 const u32regex& e,
630 match_flag_type flags,
631 BidiIterator base,
632 boost::mpl::int_<1> const*)
633 {
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;
637 match_type what;
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());
641 return result;
642 }
643 }
644
645 template <class BidiIterator, class Allocator>
646 inline bool u32regex_search(BidiIterator first, BidiIterator last,
647 match_results<BidiIterator, Allocator>& m,
648 const u32regex& e,
649 match_flag_type flags = match_default)
650 {
651 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
652 }
653 template <class BidiIterator, class Allocator>
654 inline bool u32regex_search(BidiIterator first, BidiIterator last,
655 match_results<BidiIterator, Allocator>& m,
656 const u32regex& e,
657 match_flag_type flags,
658 BidiIterator base)
659 {
660 return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, base, static_cast<mpl::int_<sizeof(*first)> const*>(0));
661 }
662 inline bool u32regex_search(const UChar* p,
663 match_results<const UChar*>& m,
664 const u32regex& e,
665 match_flag_type flags = match_default)
666 {
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));
668 }
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,
672 const u32regex& e,
673 match_flag_type flags = match_default)
674 {
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));
676 }
677 #endif
678 inline bool u32regex_search(const char* p,
679 match_results<const char*>& m,
680 const u32regex& e,
681 match_flag_type flags = match_default)
682 {
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));
684 }
685 inline bool u32regex_search(const unsigned char* p,
686 match_results<const unsigned char*>& m,
687 const u32regex& e,
688 match_flag_type flags = match_default)
689 {
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));
691 }
692 inline bool u32regex_search(const std::string& s,
693 match_results<std::string::const_iterator>& m,
694 const u32regex& e,
695 match_flag_type flags = match_default)
696 {
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));
698 }
699 #ifndef BOOST_NO_STD_WSTRING
700 inline bool u32regex_search(const std::wstring& s,
701 match_results<std::wstring::const_iterator>& m,
702 const u32regex& e,
703 match_flag_type flags = match_default)
704 {
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));
706 }
707 #endif
708 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
709 match_results<const UChar*>& m,
710 const u32regex& e,
711 match_flag_type flags = match_default)
712 {
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));
714 }
715 template <class BidiIterator>
716 inline bool u32regex_search(BidiIterator first, BidiIterator last,
717 const u32regex& e,
718 match_flag_type flags = match_default)
719 {
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));
722 }
723 inline bool u32regex_search(const UChar* p,
724 const u32regex& e,
725 match_flag_type flags = match_default)
726 {
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));
729 }
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,
732 const u32regex& e,
733 match_flag_type flags = match_default)
734 {
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));
737 }
738 #endif
739 inline bool u32regex_search(const char* p,
740 const u32regex& e,
741 match_flag_type flags = match_default)
742 {
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));
745 }
746 inline bool u32regex_search(const unsigned char* p,
747 const u32regex& e,
748 match_flag_type flags = match_default)
749 {
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));
752 }
753 inline bool u32regex_search(const std::string& s,
754 const u32regex& e,
755 match_flag_type flags = match_default)
756 {
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));
759 }
760 #ifndef BOOST_NO_STD_WSTRING
761 inline bool u32regex_search(const std::wstring& s,
762 const u32regex& e,
763 match_flag_type flags = match_default)
764 {
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));
767 }
768 #endif
769 inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
770 const u32regex& e,
771 match_flag_type flags = match_default)
772 {
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));
775 }
776
777 //
778 // overloads for regex_replace with utf-8 and utf-16 data types:
779 //
780 namespace BOOST_REGEX_DETAIL_NS{
781 template <class I>
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*)
784 {
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));
786 }
787 template <class I>
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*)
790 {
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));
792 }
793 template <class I>
794 inline std::pair< I, I >
795 make_utf32_seq(I i, I j, mpl::int_<4> const*)
796 {
797 return std::pair< I, I >(i, j);
798 }
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*)
802 {
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));
805 }
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*)
809 {
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));
812 }
813 template <class charT>
814 inline std::pair< const charT*, const charT* >
815 make_utf32_seq(const charT* p, mpl::int_<4> const*)
816 {
817 return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
818 }
819 template <class OutputIterator>
820 inline OutputIterator make_utf32_out(OutputIterator o, mpl::int_<4> const*)
821 {
822 return o;
823 }
824 template <class OutputIterator>
825 inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<2> const*)
826 {
827 return o;
828 }
829 template <class OutputIterator>
830 inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<1> const*)
831 {
832 return o;
833 }
834
835 template <class OutputIterator, class I1, class I2>
836 OutputIterator do_regex_replace(OutputIterator out,
837 std::pair<I1, I1> const& in,
838 const u32regex& e,
839 const std::pair<I2, I2>& fmt,
840 match_flag_type flags
841 )
842 {
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);
847 #else
848 f.clear();
849 I2 pos = fmt.first;
850 while(pos != fmt.second)
851 f.push_back(*pos++);
852 #endif
853
854 regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
855 regex_iterator<I1, UChar32, icu_regex_traits> j;
856 if(i == j)
857 {
858 if(!(flags & regex_constants::format_no_copy))
859 out = BOOST_REGEX_DETAIL_NS::copy(in.first, in.second, out);
860 }
861 else
862 {
863 I1 last_m = in.first;
864 while(i != j)
865 {
866 if(!(flags & regex_constants::format_no_copy))
867 out = BOOST_REGEX_DETAIL_NS::copy(i->prefix().first, i->prefix().second, out);
868 if(f.size())
869 out = ::boost::BOOST_REGEX_DETAIL_NS::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
870 else
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)
874 break;
875 ++i;
876 }
877 if(!(flags & regex_constants::format_no_copy))
878 out = BOOST_REGEX_DETAIL_NS::copy(last_m, in.second, out);
879 }
880 return out;
881 }
882 template <class BaseIterator>
883 inline const BaseIterator& extract_output_base(const BaseIterator& b)
884 {
885 return b;
886 }
887 template <class BaseIterator>
888 inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
889 {
890 return b.base();
891 }
892 template <class BaseIterator>
893 inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
894 {
895 return b.base();
896 }
897 } // BOOST_REGEX_DETAIL_NS
898
899 template <class OutputIterator, class BidirectionalIterator, class charT>
900 inline OutputIterator u32regex_replace(OutputIterator out,
901 BidirectionalIterator first,
902 BidirectionalIterator last,
903 const u32regex& e,
904 const charT* fmt,
905 match_flag_type flags = match_default)
906 {
907 return BOOST_REGEX_DETAIL_NS::extract_output_base
908 (
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)),
912 e,
913 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt, static_cast<mpl::int_<sizeof(*fmt)> const*>(0)),
914 flags)
915 );
916 }
917
918 template <class OutputIterator, class Iterator, class charT>
919 inline OutputIterator u32regex_replace(OutputIterator out,
920 Iterator first,
921 Iterator last,
922 const u32regex& e,
923 const std::basic_string<charT>& fmt,
924 match_flag_type flags = match_default)
925 {
926 return BOOST_REGEX_DETAIL_NS::extract_output_base
927 (
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)),
931 e,
932 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<mpl::int_<sizeof(charT)> const*>(0)),
933 flags)
934 );
935 }
936
937 template <class OutputIterator, class Iterator>
938 inline OutputIterator u32regex_replace(OutputIterator out,
939 Iterator first,
940 Iterator last,
941 const u32regex& e,
942 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
943 match_flag_type flags = match_default)
944 {
945 return BOOST_REGEX_DETAIL_NS::extract_output_base
946 (
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)),
950 e,
951 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
952 flags)
953 );
954 }
955
956 template <class charT>
957 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
958 const u32regex& e,
959 const charT* fmt,
960 match_flag_type flags = match_default)
961 {
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);
965 return result;
966 }
967
968 template <class charT>
969 std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
970 const u32regex& e,
971 const std::basic_string<charT>& fmt,
972 match_flag_type flags = match_default)
973 {
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);
977 return result;
978 }
979
980 namespace BOOST_REGEX_DETAIL_NS{
981
982 class unicode_string_out_iterator
983 {
984 U_NAMESPACE_QUALIFIER UnicodeString* out;
985 public:
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)
991 {
992 *out += v;
993 return *this;
994 }
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;
1000 };
1001
1002 }
1003
1004 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1005 const u32regex& e,
1006 const UChar* fmt,
1007 match_flag_type flags = match_default)
1008 {
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);
1012 return result;
1013 }
1014
1015 inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
1016 const u32regex& e,
1017 const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
1018 match_flag_type flags = match_default)
1019 {
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)),
1025 e,
1026 BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
1027 flags);
1028 return result;
1029 }
1030
1031 } // namespace boost.
1032
1033 #ifdef BOOST_MSVC
1034 #pragma warning (pop)
1035 #endif
1036
1037 #include <boost/regex/v4/u32regex_iterator.hpp>
1038 #include <boost/regex/v4/u32regex_token_iterator.hpp>
1039
1040 #endif