os/ossrv/ossrv_pub/boost_apis/boost/regex/icu.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 *
sl@0
     3
 * Copyright (c) 2004
sl@0
     4
 * John Maddock
sl@0
     5
 *
sl@0
     6
 * Use, modification and distribution are subject to the 
sl@0
     7
 * Boost Software License, Version 1.0. (See accompanying file 
sl@0
     8
 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
sl@0
     9
 *
sl@0
    10
 */
sl@0
    11
sl@0
    12
 /*
sl@0
    13
  *   LOCATION:    see http://www.boost.org for most recent version.
sl@0
    14
  *   FILE         icu.hpp
sl@0
    15
  *   VERSION      see <boost/version.hpp>
sl@0
    16
  *   DESCRIPTION: Unicode regular expressions on top of the ICU Library.
sl@0
    17
  */
sl@0
    18
sl@0
    19
#ifndef BOOST_REGEX_ICU_HPP
sl@0
    20
#define BOOST_REGEX_ICU_HPP
sl@0
    21
sl@0
    22
#include <unicode/utypes.h>
sl@0
    23
#include <unicode/uchar.h>
sl@0
    24
#include <unicode/coll.h>
sl@0
    25
#include <boost/regex.hpp>
sl@0
    26
#include <boost/regex/pending/unicode_iterator.hpp>
sl@0
    27
#include <boost/mpl/int_fwd.hpp>
sl@0
    28
#include <bitset>
sl@0
    29
sl@0
    30
sl@0
    31
namespace boost{
sl@0
    32
sl@0
    33
namespace re_detail{
sl@0
    34
sl@0
    35
// 
sl@0
    36
// Implementation details:
sl@0
    37
//
sl@0
    38
class BOOST_REGEX_DECL icu_regex_traits_implementation
sl@0
    39
{
sl@0
    40
   typedef UChar32                      char_type;
sl@0
    41
   typedef std::size_t                  size_type;
sl@0
    42
   typedef std::vector<char_type>       string_type;
sl@0
    43
   typedef U_NAMESPACE_QUALIFIER Locale locale_type;
sl@0
    44
   typedef boost::uint_least32_t        char_class_type;
sl@0
    45
public:
sl@0
    46
   icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
sl@0
    47
      : m_locale(l)
sl@0
    48
   {
sl@0
    49
      UErrorCode success = U_ZERO_ERROR;
sl@0
    50
      m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
sl@0
    51
      if(U_SUCCESS(success) == 0)
sl@0
    52
         init_error();
sl@0
    53
      m_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::IDENTICAL);
sl@0
    54
      success = U_ZERO_ERROR;
sl@0
    55
      m_primary_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
sl@0
    56
      if(U_SUCCESS(success) == 0)
sl@0
    57
         init_error();
sl@0
    58
      m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
sl@0
    59
   }
sl@0
    60
   U_NAMESPACE_QUALIFIER Locale getloc()const
sl@0
    61
   {
sl@0
    62
      return m_locale;
sl@0
    63
   }
sl@0
    64
   string_type do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const;
sl@0
    65
   string_type transform(const char_type* p1, const char_type* p2) const
sl@0
    66
   {
sl@0
    67
      return do_transform(p1, p2, m_collator.get());
sl@0
    68
   }
sl@0
    69
   string_type transform_primary(const char_type* p1, const char_type* p2) const
sl@0
    70
   {
sl@0
    71
      return do_transform(p1, p2, m_primary_collator.get());
sl@0
    72
   }
sl@0
    73
private:
sl@0
    74
   void init_error()
sl@0
    75
   {
sl@0
    76
      std::runtime_error e("Could not initialize ICU resources");
sl@0
    77
      boost::throw_exception(e);
sl@0
    78
   }
sl@0
    79
   U_NAMESPACE_QUALIFIER Locale m_locale;                                  // The ICU locale that we're using
sl@0
    80
   boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_collator;          // The full collation object
sl@0
    81
   boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_primary_collator;  // The primary collation object
sl@0
    82
};
sl@0
    83
sl@0
    84
inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
sl@0
    85
{
sl@0
    86
   return boost::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
sl@0
    87
}
sl@0
    88
sl@0
    89
}
sl@0
    90
sl@0
    91
class BOOST_REGEX_DECL icu_regex_traits
sl@0
    92
{
sl@0
    93
public:
sl@0
    94
   typedef UChar32                      char_type;
sl@0
    95
   typedef std::size_t                  size_type;
sl@0
    96
   typedef std::vector<char_type>       string_type;
sl@0
    97
   typedef U_NAMESPACE_QUALIFIER Locale locale_type;
sl@0
    98
#ifdef BOOST_NO_INT64_T
sl@0
    99
   typedef std::bitset<64>              char_class_type;
sl@0
   100
#else
sl@0
   101
   typedef boost::uint64_t              char_class_type;
sl@0
   102
#endif
sl@0
   103
sl@0
   104
   struct boost_extensions_tag{};
sl@0
   105
sl@0
   106
   icu_regex_traits()
sl@0
   107
      : m_pimpl(re_detail::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
sl@0
   108
   {
sl@0
   109
   }
sl@0
   110
   static size_type length(const char_type* p);
sl@0
   111
sl@0
   112
   ::boost::regex_constants::syntax_type syntax_type(char_type c)const
sl@0
   113
   {
sl@0
   114
      return ((c < 0x7f) && (c > 0)) ? re_detail::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
sl@0
   115
   }
sl@0
   116
   ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
sl@0
   117
   {
sl@0
   118
      return ((c < 0x7f) && (c > 0)) ? re_detail::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
sl@0
   119
   }
sl@0
   120
   char_type translate(char_type c) const
sl@0
   121
   {
sl@0
   122
      return c;
sl@0
   123
   }
sl@0
   124
   char_type translate_nocase(char_type c) const
sl@0
   125
   {
sl@0
   126
      return ::u_tolower(c);
sl@0
   127
   }
sl@0
   128
   char_type translate(char_type c, bool icase) const
sl@0
   129
   {
sl@0
   130
      return icase ? translate_nocase(c) : translate(c);
sl@0
   131
   }
sl@0
   132
   char_type tolower(char_type c) const
sl@0
   133
   {
sl@0
   134
      return ::u_tolower(c);
sl@0
   135
   }
sl@0
   136
   char_type toupper(char_type c) const
sl@0
   137
   {
sl@0
   138
      return ::u_toupper(c);
sl@0
   139
   }
sl@0
   140
   string_type transform(const char_type* p1, const char_type* p2) const
sl@0
   141
   {
sl@0
   142
      return m_pimpl->transform(p1, p2);
sl@0
   143
   }
sl@0
   144
   string_type transform_primary(const char_type* p1, const char_type* p2) const
sl@0
   145
   {
sl@0
   146
      return m_pimpl->transform_primary(p1, p2);
sl@0
   147
   }
sl@0
   148
   char_class_type lookup_classname(const char_type* p1, const char_type* p2) const;
sl@0
   149
   string_type lookup_collatename(const char_type* p1, const char_type* p2) const;
sl@0
   150
   bool isctype(char_type c, char_class_type f) const;
sl@0
   151
   int toi(const char_type*& p1, const char_type* p2, int radix)const
sl@0
   152
   {
sl@0
   153
      return re_detail::global_toi(p1, p2, radix, *this);
sl@0
   154
   }
sl@0
   155
   int value(char_type c, int radix)const
sl@0
   156
   {
sl@0
   157
      return u_digit(c, static_cast< ::int8_t>(radix));
sl@0
   158
   }
sl@0
   159
   locale_type imbue(locale_type l)
sl@0
   160
   {
sl@0
   161
      locale_type result(m_pimpl->getloc());
sl@0
   162
      m_pimpl = re_detail::get_icu_regex_traits_implementation(l);
sl@0
   163
      return result;
sl@0
   164
   }
sl@0
   165
   locale_type getloc()const
sl@0
   166
   {
sl@0
   167
      return locale_type();
sl@0
   168
   }
sl@0
   169
   std::string error_string(::boost::regex_constants::error_type n) const
sl@0
   170
   {
sl@0
   171
      return re_detail::get_default_error_string(n);
sl@0
   172
   }
sl@0
   173
private:
sl@0
   174
   icu_regex_traits(const icu_regex_traits&);
sl@0
   175
   icu_regex_traits& operator=(const icu_regex_traits&);
sl@0
   176
sl@0
   177
   //
sl@0
   178
   // define the bitmasks offsets we need for additional character properties:
sl@0
   179
   //
sl@0
   180
   enum{
sl@0
   181
      offset_blank = U_CHAR_CATEGORY_COUNT,
sl@0
   182
      offset_space = U_CHAR_CATEGORY_COUNT+1,
sl@0
   183
      offset_xdigit = U_CHAR_CATEGORY_COUNT+2,
sl@0
   184
      offset_underscore = U_CHAR_CATEGORY_COUNT+3,
sl@0
   185
      offset_unicode = U_CHAR_CATEGORY_COUNT+4,
sl@0
   186
      offset_any = U_CHAR_CATEGORY_COUNT+5,
sl@0
   187
      offset_ascii = U_CHAR_CATEGORY_COUNT+6
sl@0
   188
   };
sl@0
   189
sl@0
   190
   //
sl@0
   191
   // and now the masks:
sl@0
   192
   //
sl@0
   193
   static const char_class_type mask_blank;
sl@0
   194
   static const char_class_type mask_space;
sl@0
   195
   static const char_class_type mask_xdigit;
sl@0
   196
   static const char_class_type mask_underscore;
sl@0
   197
   static const char_class_type mask_unicode;
sl@0
   198
   static const char_class_type mask_any;
sl@0
   199
   static const char_class_type mask_ascii;
sl@0
   200
sl@0
   201
   static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
sl@0
   202
sl@0
   203
   boost::shared_ptr< ::boost::re_detail::icu_regex_traits_implementation> m_pimpl;
sl@0
   204
};
sl@0
   205
sl@0
   206
} // namespace boost
sl@0
   207
sl@0
   208
//
sl@0
   209
// template instances:
sl@0
   210
//
sl@0
   211
#define BOOST_REGEX_CHAR_T UChar32
sl@0
   212
#undef BOOST_REGEX_TRAITS_T
sl@0
   213
#define BOOST_REGEX_TRAITS_T , icu_regex_traits
sl@0
   214
#define BOOST_REGEX_ICU_INSTANCES
sl@0
   215
#ifdef BOOST_REGEX_ICU_INSTANTIATE
sl@0
   216
#  define BOOST_REGEX_INSTANTIATE
sl@0
   217
#endif
sl@0
   218
#include <boost/regex/v4/instances.hpp>
sl@0
   219
#undef BOOST_REGEX_CHAR_T
sl@0
   220
#undef BOOST_REGEX_TRAITS_T
sl@0
   221
#undef BOOST_REGEX_ICU_INSTANCES
sl@0
   222
#ifdef BOOST_REGEX_INSTANTIATE
sl@0
   223
#  undef BOOST_REGEX_INSTANTIATE
sl@0
   224
#endif
sl@0
   225
sl@0
   226
namespace boost{
sl@0
   227
sl@0
   228
// types:
sl@0
   229
typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
sl@0
   230
typedef match_results<const ::UChar32*> u32match;
sl@0
   231
typedef match_results<const ::UChar*> u16match;
sl@0
   232
sl@0
   233
//
sl@0
   234
// Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
sl@0
   235
//
sl@0
   236
namespace re_detail{
sl@0
   237
sl@0
   238
#if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
sl@0
   239
template <class InputIterator>
sl@0
   240
inline u32regex do_make_u32regex(InputIterator i, 
sl@0
   241
                              InputIterator j, 
sl@0
   242
                              boost::regex_constants::syntax_option_type opt, 
sl@0
   243
                              const boost::mpl::int_<1>*)
sl@0
   244
{
sl@0
   245
   typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
sl@0
   246
   return u32regex(conv_type(i), conv_type(j), opt);
sl@0
   247
}
sl@0
   248
sl@0
   249
template <class InputIterator>
sl@0
   250
inline u32regex do_make_u32regex(InputIterator i, 
sl@0
   251
                              InputIterator j, 
sl@0
   252
                              boost::regex_constants::syntax_option_type opt, 
sl@0
   253
                              const boost::mpl::int_<2>*)
sl@0
   254
{
sl@0
   255
   typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
sl@0
   256
   return u32regex(conv_type(i), conv_type(j), opt);
sl@0
   257
}
sl@0
   258
sl@0
   259
template <class InputIterator>
sl@0
   260
inline u32regex do_make_u32regex(InputIterator i, 
sl@0
   261
                              InputIterator j, 
sl@0
   262
                              boost::regex_constants::syntax_option_type opt, 
sl@0
   263
                              const boost::mpl::int_<4>*)
sl@0
   264
{
sl@0
   265
   return u32regex(i, j, opt);
sl@0
   266
}
sl@0
   267
#else
sl@0
   268
template <class InputIterator>
sl@0
   269
inline u32regex do_make_u32regex(InputIterator i, 
sl@0
   270
                              InputIterator j, 
sl@0
   271
                              boost::regex_constants::syntax_option_type opt, 
sl@0
   272
                              const boost::mpl::int_<1>*)
sl@0
   273
{
sl@0
   274
   typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
sl@0
   275
   typedef std::vector<UChar32> vector_type;
sl@0
   276
   vector_type v;
sl@0
   277
   conv_type a(i), b(j);
sl@0
   278
   while(a != b)
sl@0
   279
   {
sl@0
   280
      v.push_back(*a);
sl@0
   281
      ++a;
sl@0
   282
   }
sl@0
   283
   if(v.size())
sl@0
   284
      return u32regex(&*v.begin(), v.size(), opt);
sl@0
   285
   return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
sl@0
   286
}
sl@0
   287
sl@0
   288
template <class InputIterator>
sl@0
   289
inline u32regex do_make_u32regex(InputIterator i, 
sl@0
   290
                              InputIterator j, 
sl@0
   291
                              boost::regex_constants::syntax_option_type opt, 
sl@0
   292
                              const boost::mpl::int_<2>*)
sl@0
   293
{
sl@0
   294
   typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
sl@0
   295
   typedef std::vector<UChar32> vector_type;
sl@0
   296
   vector_type v;
sl@0
   297
   conv_type a(i), b(j);
sl@0
   298
   while(a != b)
sl@0
   299
   {
sl@0
   300
      v.push_back(*a);
sl@0
   301
      ++a;
sl@0
   302
   }
sl@0
   303
   if(v.size())
sl@0
   304
      return u32regex(&*v.begin(), v.size(), opt);
sl@0
   305
   return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
sl@0
   306
}
sl@0
   307
sl@0
   308
template <class InputIterator>
sl@0
   309
inline u32regex do_make_u32regex(InputIterator i, 
sl@0
   310
                              InputIterator j, 
sl@0
   311
                              boost::regex_constants::syntax_option_type opt, 
sl@0
   312
                              const boost::mpl::int_<4>*)
sl@0
   313
{
sl@0
   314
   typedef std::vector<UCHAR32> vector_type;
sl@0
   315
   vector_type v;
sl@0
   316
   while(i != j)
sl@0
   317
   {
sl@0
   318
      v.push_back((UCHAR32)(*i));
sl@0
   319
      ++a;
sl@0
   320
   }
sl@0
   321
   if(v.size())
sl@0
   322
      return u32regex(&*v.begin(), v.size(), opt);
sl@0
   323
   return u32regex(static_cast<UChar32 const*>(0), static_cast<u32regex::size_type>(0), opt);
sl@0
   324
}
sl@0
   325
#endif
sl@0
   326
}
sl@0
   327
sl@0
   328
//
sl@0
   329
// Construction from an iterator pair:
sl@0
   330
//
sl@0
   331
template <class InputIterator>
sl@0
   332
inline u32regex make_u32regex(InputIterator i, 
sl@0
   333
                              InputIterator j, 
sl@0
   334
                              boost::regex_constants::syntax_option_type opt)
sl@0
   335
{
sl@0
   336
   return re_detail::do_make_u32regex(i, j, opt, static_cast<boost::mpl::int_<sizeof(*i)> const*>(0));
sl@0
   337
}
sl@0
   338
//
sl@0
   339
// construction from UTF-8 nul-terminated strings:
sl@0
   340
//
sl@0
   341
inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
sl@0
   342
{
sl@0
   343
   return re_detail::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<boost::mpl::int_<1> const*>(0));
sl@0
   344
}
sl@0
   345
inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
sl@0
   346
{
sl@0
   347
   return re_detail::do_make_u32regex(p, p + std::strlen(reinterpret_cast<const char*>(p)), opt, static_cast<boost::mpl::int_<1> const*>(0));
sl@0
   348
}
sl@0
   349
//
sl@0
   350
// construction from UTF-16 nul-terminated strings:
sl@0
   351
//
sl@0
   352
#ifndef BOOST_NO_WREGEX
sl@0
   353
inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
sl@0
   354
{
sl@0
   355
   return re_detail::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<boost::mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   356
}
sl@0
   357
#endif
sl@0
   358
#ifndef U_WCHAR_IS_UTF16
sl@0
   359
inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
sl@0
   360
{
sl@0
   361
   return re_detail::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
sl@0
   362
}
sl@0
   363
#endif
sl@0
   364
//
sl@0
   365
// construction from basic_string class-template:
sl@0
   366
//
sl@0
   367
template<class C, class T, class A>
sl@0
   368
inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
sl@0
   369
{
sl@0
   370
   return re_detail::do_make_u32regex(s.begin(), s.end(), opt, static_cast<boost::mpl::int_<sizeof(C)> const*>(0));
sl@0
   371
}
sl@0
   372
//
sl@0
   373
// Construction from ICU string type:
sl@0
   374
//
sl@0
   375
inline u32regex make_u32regex(const UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
sl@0
   376
{
sl@0
   377
   return re_detail::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
sl@0
   378
}
sl@0
   379
sl@0
   380
//
sl@0
   381
// regex_match overloads that widen the character type as appropriate:
sl@0
   382
//
sl@0
   383
namespace re_detail{
sl@0
   384
template<class MR1, class MR2>
sl@0
   385
void copy_results(MR1& out, MR2 const& in)
sl@0
   386
{
sl@0
   387
   // copy results from an adapted MR2 match_results:
sl@0
   388
   out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
sl@0
   389
   out.set_base(in.base().base());
sl@0
   390
   for(int i = 0; i < (int)in.size(); ++i)
sl@0
   391
   {
sl@0
   392
      if(in[i].matched)
sl@0
   393
      {
sl@0
   394
         out.set_first(in[i].first.base(), i);
sl@0
   395
         out.set_second(in[i].second.base(), i);
sl@0
   396
      }
sl@0
   397
   }
sl@0
   398
}
sl@0
   399
sl@0
   400
template <class BidiIterator, class Allocator>
sl@0
   401
inline bool do_regex_match(BidiIterator first, BidiIterator last, 
sl@0
   402
                 match_results<BidiIterator, Allocator>& m, 
sl@0
   403
                 const u32regex& e, 
sl@0
   404
                 match_flag_type flags,
sl@0
   405
                 boost::mpl::int_<4> const*)
sl@0
   406
{
sl@0
   407
   return ::boost::regex_match(first, last, m, e, flags);
sl@0
   408
}
sl@0
   409
template <class BidiIterator, class Allocator>
sl@0
   410
bool do_regex_match(BidiIterator first, BidiIterator last, 
sl@0
   411
                 match_results<BidiIterator, Allocator>& m, 
sl@0
   412
                 const u32regex& e, 
sl@0
   413
                 match_flag_type flags,
sl@0
   414
                 boost::mpl::int_<2> const*)
sl@0
   415
{
sl@0
   416
   typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
sl@0
   417
   typedef match_results<conv_type>                   match_type;
sl@0
   418
   typedef typename match_type::allocator_type        alloc_type;
sl@0
   419
   match_type what;
sl@0
   420
   bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
sl@0
   421
   // copy results across to m:
sl@0
   422
   if(result) copy_results(m, what);
sl@0
   423
   return result;
sl@0
   424
}
sl@0
   425
template <class BidiIterator, class Allocator>
sl@0
   426
bool do_regex_match(BidiIterator first, BidiIterator last, 
sl@0
   427
                 match_results<BidiIterator, Allocator>& m, 
sl@0
   428
                 const u32regex& e, 
sl@0
   429
                 match_flag_type flags,
sl@0
   430
                 boost::mpl::int_<1> const*)
sl@0
   431
{
sl@0
   432
   typedef u8_to_u32_iterator<BidiIterator, UChar32>  conv_type;
sl@0
   433
   typedef match_results<conv_type>                   match_type;
sl@0
   434
   typedef typename match_type::allocator_type        alloc_type;
sl@0
   435
   match_type what;
sl@0
   436
   bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
sl@0
   437
   // copy results across to m:
sl@0
   438
   if(result) copy_results(m, what);
sl@0
   439
   return result;
sl@0
   440
}
sl@0
   441
} // namespace re_detail
sl@0
   442
sl@0
   443
template <class BidiIterator, class Allocator>
sl@0
   444
inline bool u32regex_match(BidiIterator first, BidiIterator last, 
sl@0
   445
                 match_results<BidiIterator, Allocator>& m, 
sl@0
   446
                 const u32regex& e, 
sl@0
   447
                 match_flag_type flags = match_default)
sl@0
   448
{
sl@0
   449
   return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
sl@0
   450
}
sl@0
   451
inline bool u32regex_match(const UChar* p, 
sl@0
   452
                 match_results<const UChar*>& m, 
sl@0
   453
                 const u32regex& e, 
sl@0
   454
                 match_flag_type flags = match_default)
sl@0
   455
{
sl@0
   456
   return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
sl@0
   457
}
sl@0
   458
#if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
sl@0
   459
inline bool u32regex_match(const wchar_t* p, 
sl@0
   460
                 match_results<const wchar_t*>& m, 
sl@0
   461
                 const u32regex& e, 
sl@0
   462
                 match_flag_type flags = match_default)
sl@0
   463
{
sl@0
   464
   return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   465
}
sl@0
   466
#endif
sl@0
   467
inline bool u32regex_match(const char* p, 
sl@0
   468
                 match_results<const char*>& m, 
sl@0
   469
                 const u32regex& e, 
sl@0
   470
                 match_flag_type flags = match_default)
sl@0
   471
{
sl@0
   472
   return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
sl@0
   473
}
sl@0
   474
inline bool u32regex_match(const unsigned char* p, 
sl@0
   475
                 match_results<const unsigned char*>& m, 
sl@0
   476
                 const u32regex& e, 
sl@0
   477
                 match_flag_type flags = match_default)
sl@0
   478
{
sl@0
   479
   return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
sl@0
   480
}
sl@0
   481
inline bool u32regex_match(const std::string& s, 
sl@0
   482
                        match_results<std::string::const_iterator>& m, 
sl@0
   483
                        const u32regex& e, 
sl@0
   484
                        match_flag_type flags = match_default)
sl@0
   485
{
sl@0
   486
   return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
sl@0
   487
}
sl@0
   488
#ifndef BOOST_NO_STD_WSTRING
sl@0
   489
inline bool u32regex_match(const std::wstring& s, 
sl@0
   490
                        match_results<std::wstring::const_iterator>& m, 
sl@0
   491
                        const u32regex& e, 
sl@0
   492
                        match_flag_type flags = match_default)
sl@0
   493
{
sl@0
   494
   return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   495
}
sl@0
   496
#endif
sl@0
   497
inline bool u32regex_match(const UnicodeString& s, 
sl@0
   498
                        match_results<const UChar*>& m, 
sl@0
   499
                        const u32regex& e, 
sl@0
   500
                        match_flag_type flags = match_default)
sl@0
   501
{
sl@0
   502
   return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   503
}
sl@0
   504
//
sl@0
   505
// regex_match overloads that do not return what matched:
sl@0
   506
//
sl@0
   507
template <class BidiIterator>
sl@0
   508
inline bool u32regex_match(BidiIterator first, BidiIterator last, 
sl@0
   509
                 const u32regex& e, 
sl@0
   510
                 match_flag_type flags = match_default)
sl@0
   511
{
sl@0
   512
   match_results<BidiIterator> m;
sl@0
   513
   return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
sl@0
   514
}
sl@0
   515
inline bool u32regex_match(const UChar* p, 
sl@0
   516
                 const u32regex& e, 
sl@0
   517
                 match_flag_type flags = match_default)
sl@0
   518
{
sl@0
   519
   match_results<const UChar*> m;
sl@0
   520
   return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
sl@0
   521
}
sl@0
   522
#if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
sl@0
   523
inline bool u32regex_match(const wchar_t* p, 
sl@0
   524
                 const u32regex& e, 
sl@0
   525
                 match_flag_type flags = match_default)
sl@0
   526
{
sl@0
   527
   match_results<const wchar_t*> m;
sl@0
   528
   return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   529
}
sl@0
   530
#endif
sl@0
   531
inline bool u32regex_match(const char* p, 
sl@0
   532
                 const u32regex& e, 
sl@0
   533
                 match_flag_type flags = match_default)
sl@0
   534
{
sl@0
   535
   match_results<const char*> m;
sl@0
   536
   return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
sl@0
   537
}
sl@0
   538
inline bool u32regex_match(const unsigned char* p, 
sl@0
   539
                 const u32regex& e, 
sl@0
   540
                 match_flag_type flags = match_default)
sl@0
   541
{
sl@0
   542
   match_results<const unsigned char*> m;
sl@0
   543
   return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
sl@0
   544
}
sl@0
   545
inline bool u32regex_match(const std::string& s, 
sl@0
   546
                        const u32regex& e, 
sl@0
   547
                        match_flag_type flags = match_default)
sl@0
   548
{
sl@0
   549
   match_results<std::string::const_iterator> m;
sl@0
   550
   return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
sl@0
   551
}
sl@0
   552
#ifndef BOOST_NO_STD_WSTRING
sl@0
   553
inline bool u32regex_match(const std::wstring& s, 
sl@0
   554
                        const u32regex& e, 
sl@0
   555
                        match_flag_type flags = match_default)
sl@0
   556
{
sl@0
   557
   match_results<std::wstring::const_iterator> m;
sl@0
   558
   return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   559
}
sl@0
   560
#endif
sl@0
   561
inline bool u32regex_match(const UnicodeString& s, 
sl@0
   562
                        const u32regex& e, 
sl@0
   563
                        match_flag_type flags = match_default)
sl@0
   564
{
sl@0
   565
   match_results<const UChar*> m;
sl@0
   566
   return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   567
}
sl@0
   568
sl@0
   569
//
sl@0
   570
// regex_search overloads that widen the character type as appropriate:
sl@0
   571
//
sl@0
   572
namespace re_detail{
sl@0
   573
template <class BidiIterator, class Allocator>
sl@0
   574
inline bool do_regex_search(BidiIterator first, BidiIterator last, 
sl@0
   575
                 match_results<BidiIterator, Allocator>& m, 
sl@0
   576
                 const u32regex& e, 
sl@0
   577
                 match_flag_type flags,
sl@0
   578
                 BidiIterator base,
sl@0
   579
                 boost::mpl::int_<4> const*)
sl@0
   580
{
sl@0
   581
   return ::boost::regex_search(first, last, m, e, flags, base);
sl@0
   582
}
sl@0
   583
template <class BidiIterator, class Allocator>
sl@0
   584
bool do_regex_search(BidiIterator first, BidiIterator last, 
sl@0
   585
                 match_results<BidiIterator, Allocator>& m, 
sl@0
   586
                 const u32regex& e, 
sl@0
   587
                 match_flag_type flags,
sl@0
   588
                 BidiIterator base,
sl@0
   589
                 boost::mpl::int_<2> const*)
sl@0
   590
{
sl@0
   591
   typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
sl@0
   592
   typedef match_results<conv_type>                   match_type;
sl@0
   593
   typedef typename match_type::allocator_type        alloc_type;
sl@0
   594
   match_type what;
sl@0
   595
   bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags, conv_type(base));
sl@0
   596
   // copy results across to m:
sl@0
   597
   if(result) copy_results(m, what);
sl@0
   598
   return result;
sl@0
   599
}
sl@0
   600
template <class BidiIterator, class Allocator>
sl@0
   601
bool do_regex_search(BidiIterator first, BidiIterator last, 
sl@0
   602
                 match_results<BidiIterator, Allocator>& m, 
sl@0
   603
                 const u32regex& e, 
sl@0
   604
                 match_flag_type flags,
sl@0
   605
                 BidiIterator base,
sl@0
   606
                 boost::mpl::int_<1> const*)
sl@0
   607
{
sl@0
   608
   typedef u8_to_u32_iterator<BidiIterator, UChar32>  conv_type;
sl@0
   609
   typedef match_results<conv_type>                   match_type;
sl@0
   610
   typedef typename match_type::allocator_type        alloc_type;
sl@0
   611
   match_type what;
sl@0
   612
   bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags, conv_type(base));
sl@0
   613
   // copy results across to m:
sl@0
   614
   if(result) copy_results(m, what);
sl@0
   615
   return result;
sl@0
   616
}
sl@0
   617
}
sl@0
   618
sl@0
   619
template <class BidiIterator, class Allocator>
sl@0
   620
inline bool u32regex_search(BidiIterator first, BidiIterator last, 
sl@0
   621
                 match_results<BidiIterator, Allocator>& m, 
sl@0
   622
                 const u32regex& e, 
sl@0
   623
                 match_flag_type flags = match_default)
sl@0
   624
{
sl@0
   625
   return re_detail::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
sl@0
   626
}
sl@0
   627
template <class BidiIterator, class Allocator>
sl@0
   628
inline bool u32regex_search(BidiIterator first, BidiIterator last, 
sl@0
   629
                 match_results<BidiIterator, Allocator>& m, 
sl@0
   630
                 const u32regex& e, 
sl@0
   631
                 match_flag_type flags,
sl@0
   632
                 BidiIterator base)
sl@0
   633
{
sl@0
   634
   return re_detail::do_regex_search(first, last, m, e, flags, base, static_cast<mpl::int_<sizeof(*first)> const*>(0));
sl@0
   635
}
sl@0
   636
inline bool u32regex_search(const UChar* p, 
sl@0
   637
                 match_results<const UChar*>& m, 
sl@0
   638
                 const u32regex& e, 
sl@0
   639
                 match_flag_type flags = match_default)
sl@0
   640
{
sl@0
   641
   return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
sl@0
   642
}
sl@0
   643
#if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
sl@0
   644
inline bool u32regex_search(const wchar_t* p, 
sl@0
   645
                 match_results<const wchar_t*>& m, 
sl@0
   646
                 const u32regex& e, 
sl@0
   647
                 match_flag_type flags = match_default)
sl@0
   648
{
sl@0
   649
   return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   650
}
sl@0
   651
#endif
sl@0
   652
inline bool u32regex_search(const char* p, 
sl@0
   653
                 match_results<const char*>& m, 
sl@0
   654
                 const u32regex& e, 
sl@0
   655
                 match_flag_type flags = match_default)
sl@0
   656
{
sl@0
   657
   return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
sl@0
   658
}
sl@0
   659
inline bool u32regex_search(const unsigned char* p, 
sl@0
   660
                 match_results<const unsigned char*>& m, 
sl@0
   661
                 const u32regex& e, 
sl@0
   662
                 match_flag_type flags = match_default)
sl@0
   663
{
sl@0
   664
   return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
sl@0
   665
}
sl@0
   666
inline bool u32regex_search(const std::string& s, 
sl@0
   667
                        match_results<std::string::const_iterator>& m, 
sl@0
   668
                        const u32regex& e, 
sl@0
   669
                        match_flag_type flags = match_default)
sl@0
   670
{
sl@0
   671
   return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
sl@0
   672
}
sl@0
   673
#ifndef BOOST_NO_STD_WSTRING
sl@0
   674
inline bool u32regex_search(const std::wstring& s, 
sl@0
   675
                        match_results<std::wstring::const_iterator>& m, 
sl@0
   676
                        const u32regex& e, 
sl@0
   677
                        match_flag_type flags = match_default)
sl@0
   678
{
sl@0
   679
   return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   680
}
sl@0
   681
#endif
sl@0
   682
inline bool u32regex_search(const UnicodeString& s, 
sl@0
   683
                        match_results<const UChar*>& m, 
sl@0
   684
                        const u32regex& e, 
sl@0
   685
                        match_flag_type flags = match_default)
sl@0
   686
{
sl@0
   687
   return re_detail::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   688
}
sl@0
   689
template <class BidiIterator>
sl@0
   690
inline bool u32regex_search(BidiIterator first, BidiIterator last, 
sl@0
   691
                 const u32regex& e, 
sl@0
   692
                 match_flag_type flags = match_default)
sl@0
   693
{
sl@0
   694
   match_results<BidiIterator> m;
sl@0
   695
   return re_detail::do_regex_search(first, last, m, e, flags, first, static_cast<mpl::int_<sizeof(*first)> const*>(0));
sl@0
   696
}
sl@0
   697
inline bool u32regex_search(const UChar* p, 
sl@0
   698
                 const u32regex& e, 
sl@0
   699
                 match_flag_type flags = match_default)
sl@0
   700
{
sl@0
   701
   match_results<const UChar*> m;
sl@0
   702
   return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
sl@0
   703
}
sl@0
   704
#if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
sl@0
   705
inline bool u32regex_search(const wchar_t* p, 
sl@0
   706
                 const u32regex& e, 
sl@0
   707
                 match_flag_type flags = match_default)
sl@0
   708
{
sl@0
   709
   match_results<const wchar_t*> m;
sl@0
   710
   return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   711
}
sl@0
   712
#endif
sl@0
   713
inline bool u32regex_search(const char* p, 
sl@0
   714
                 const u32regex& e, 
sl@0
   715
                 match_flag_type flags = match_default)
sl@0
   716
{
sl@0
   717
   match_results<const char*> m;
sl@0
   718
   return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
sl@0
   719
}
sl@0
   720
inline bool u32regex_search(const unsigned char* p, 
sl@0
   721
                 const u32regex& e, 
sl@0
   722
                 match_flag_type flags = match_default)
sl@0
   723
{
sl@0
   724
   match_results<const unsigned char*> m;
sl@0
   725
   return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<mpl::int_<1> const*>(0));
sl@0
   726
}
sl@0
   727
inline bool u32regex_search(const std::string& s, 
sl@0
   728
                        const u32regex& e, 
sl@0
   729
                        match_flag_type flags = match_default)
sl@0
   730
{
sl@0
   731
   match_results<std::string::const_iterator> m;
sl@0
   732
   return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<1> const*>(0));
sl@0
   733
}
sl@0
   734
#ifndef BOOST_NO_STD_WSTRING
sl@0
   735
inline bool u32regex_search(const std::wstring& s, 
sl@0
   736
                        const u32regex& e, 
sl@0
   737
                        match_flag_type flags = match_default)
sl@0
   738
{
sl@0
   739
   match_results<std::wstring::const_iterator> m;
sl@0
   740
   return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   741
}
sl@0
   742
#endif
sl@0
   743
inline bool u32regex_search(const UnicodeString& s, 
sl@0
   744
                        const u32regex& e, 
sl@0
   745
                        match_flag_type flags = match_default)
sl@0
   746
{
sl@0
   747
   match_results<const UChar*> m;
sl@0
   748
   return re_detail::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
sl@0
   749
}
sl@0
   750
sl@0
   751
//
sl@0
   752
// overloads for regex_replace with utf-8 and utf-16 data types:
sl@0
   753
//
sl@0
   754
namespace re_detail{
sl@0
   755
template <class I>
sl@0
   756
inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
sl@0
   757
   make_utf32_seq(I i, I j, mpl::int_<1> const*)
sl@0
   758
{
sl@0
   759
   return std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >(boost::u8_to_u32_iterator<I>(i), boost::u8_to_u32_iterator<I>(j));
sl@0
   760
}
sl@0
   761
template <class I>
sl@0
   762
inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
sl@0
   763
   make_utf32_seq(I i, I j, mpl::int_<2> const*)
sl@0
   764
{
sl@0
   765
   return std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >(boost::u16_to_u32_iterator<I>(i), boost::u16_to_u32_iterator<I>(j));
sl@0
   766
}
sl@0
   767
template <class I>
sl@0
   768
inline std::pair< I, I >
sl@0
   769
   make_utf32_seq(I i, I j, mpl::int_<4> const*)
sl@0
   770
{
sl@0
   771
   return std::pair< I, I >(i, j);
sl@0
   772
}
sl@0
   773
template <class charT>
sl@0
   774
inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
sl@0
   775
   make_utf32_seq(const charT* p, mpl::int_<1> const*)
sl@0
   776
{
sl@0
   777
   return std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >(boost::u8_to_u32_iterator<const charT*>(p), boost::u8_to_u32_iterator<const charT*>(p+std::strlen((const char*)p)));
sl@0
   778
}
sl@0
   779
template <class charT>
sl@0
   780
inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
sl@0
   781
   make_utf32_seq(const charT* p, mpl::int_<2> const*)
sl@0
   782
{
sl@0
   783
   return std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >(boost::u16_to_u32_iterator<const charT*>(p), boost::u16_to_u32_iterator<const charT*>(p+u_strlen((const UChar*)p)));
sl@0
   784
}
sl@0
   785
template <class charT>
sl@0
   786
inline std::pair< const charT*, const charT* >
sl@0
   787
   make_utf32_seq(const charT* p, mpl::int_<4> const*)
sl@0
   788
{
sl@0
   789
   return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
sl@0
   790
}
sl@0
   791
template <class OutputIterator>
sl@0
   792
inline OutputIterator make_utf32_out(OutputIterator o, mpl::int_<4> const*)
sl@0
   793
{
sl@0
   794
   return o;
sl@0
   795
}
sl@0
   796
template <class OutputIterator>
sl@0
   797
inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<2> const*)
sl@0
   798
{
sl@0
   799
   return o;
sl@0
   800
}
sl@0
   801
template <class OutputIterator>
sl@0
   802
inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<1> const*)
sl@0
   803
{
sl@0
   804
   return o;
sl@0
   805
}
sl@0
   806
sl@0
   807
template <class OutputIterator, class I1, class I2>
sl@0
   808
OutputIterator do_regex_replace(OutputIterator out,
sl@0
   809
                                 std::pair<I1, I1> const& in,
sl@0
   810
                                 const u32regex& e, 
sl@0
   811
                                 const std::pair<I2, I2>& fmt, 
sl@0
   812
                                 match_flag_type flags
sl@0
   813
                                 )
sl@0
   814
{
sl@0
   815
   // unfortunately we have to copy the format string in order to pass in onward:
sl@0
   816
   std::vector<UChar32> f;
sl@0
   817
#ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
sl@0
   818
   f.assign(fmt.first, fmt.second);
sl@0
   819
#else
sl@0
   820
   f.clear();
sl@0
   821
   I2 pos = fmt.first;
sl@0
   822
   while(pos != fmt.second)
sl@0
   823
      f.push_back(*pos++);
sl@0
   824
#endif
sl@0
   825
   
sl@0
   826
   regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
sl@0
   827
   regex_iterator<I1, UChar32, icu_regex_traits> j;
sl@0
   828
   if(i == j)
sl@0
   829
   {
sl@0
   830
      if(!(flags & regex_constants::format_no_copy))
sl@0
   831
         out = re_detail::copy(in.first, in.second, out);
sl@0
   832
   }
sl@0
   833
   else
sl@0
   834
   {
sl@0
   835
      I1 last_m = in.first;
sl@0
   836
      while(i != j)
sl@0
   837
      {
sl@0
   838
         if(!(flags & regex_constants::format_no_copy))
sl@0
   839
            out = re_detail::copy(i->prefix().first, i->prefix().second, out); 
sl@0
   840
         if(f.size())
sl@0
   841
            out = ::boost::re_detail::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
sl@0
   842
         else
sl@0
   843
            out = ::boost::re_detail::regex_format_imp(out, *i, static_cast<UChar32 const*>(0), static_cast<UChar32 const*>(0), flags, e.get_traits());
sl@0
   844
         last_m = (*i)[0].second;
sl@0
   845
         if(flags & regex_constants::format_first_only)
sl@0
   846
            break;
sl@0
   847
         ++i;
sl@0
   848
      }
sl@0
   849
      if(!(flags & regex_constants::format_no_copy))
sl@0
   850
         out = re_detail::copy(last_m, in.second, out);
sl@0
   851
   }
sl@0
   852
   return out;
sl@0
   853
}
sl@0
   854
template <class BaseIterator>
sl@0
   855
inline const BaseIterator& extract_output_base(const BaseIterator& b)
sl@0
   856
{
sl@0
   857
   return b;
sl@0
   858
}
sl@0
   859
template <class BaseIterator>
sl@0
   860
inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
sl@0
   861
{
sl@0
   862
   return b.base();
sl@0
   863
}
sl@0
   864
template <class BaseIterator>
sl@0
   865
inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
sl@0
   866
{
sl@0
   867
   return b.base();
sl@0
   868
}
sl@0
   869
}  // re_detail
sl@0
   870
sl@0
   871
template <class OutputIterator, class BidirectionalIterator, class charT>
sl@0
   872
inline OutputIterator u32regex_replace(OutputIterator out,
sl@0
   873
                         BidirectionalIterator first,
sl@0
   874
                         BidirectionalIterator last,
sl@0
   875
                         const u32regex& e, 
sl@0
   876
                         const charT* fmt, 
sl@0
   877
                         match_flag_type flags = match_default)
sl@0
   878
{
sl@0
   879
   return re_detail::extract_output_base
sl@0
   880
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
sl@0
   881
   <OutputIterator>
sl@0
   882
#endif
sl@0
   883
    (
sl@0
   884
      re_detail::do_regex_replace(
sl@0
   885
         re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
sl@0
   886
         re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
sl@0
   887
         e,
sl@0
   888
         re_detail::make_utf32_seq(fmt, static_cast<mpl::int_<sizeof(*fmt)> const*>(0)),
sl@0
   889
         flags)
sl@0
   890
      );
sl@0
   891
}
sl@0
   892
sl@0
   893
template <class OutputIterator, class Iterator, class charT>
sl@0
   894
inline OutputIterator u32regex_replace(OutputIterator out,
sl@0
   895
                         Iterator first,
sl@0
   896
                         Iterator last,
sl@0
   897
                         const u32regex& e, 
sl@0
   898
                         const std::basic_string<charT>& fmt,
sl@0
   899
                         match_flag_type flags = match_default)
sl@0
   900
{
sl@0
   901
   return re_detail::extract_output_base
sl@0
   902
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
sl@0
   903
   <OutputIterator>
sl@0
   904
#endif
sl@0
   905
    (
sl@0
   906
      re_detail::do_regex_replace(
sl@0
   907
         re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
sl@0
   908
         re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
sl@0
   909
         e,
sl@0
   910
         re_detail::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<mpl::int_<sizeof(charT)> const*>(0)),
sl@0
   911
         flags)
sl@0
   912
      );
sl@0
   913
}
sl@0
   914
sl@0
   915
template <class OutputIterator, class Iterator>
sl@0
   916
inline OutputIterator u32regex_replace(OutputIterator out,
sl@0
   917
                         Iterator first,
sl@0
   918
                         Iterator last,
sl@0
   919
                         const u32regex& e, 
sl@0
   920
                         const UnicodeString& fmt,
sl@0
   921
                         match_flag_type flags = match_default)
sl@0
   922
{
sl@0
   923
   return re_detail::extract_output_base
sl@0
   924
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
sl@0
   925
   <OutputIterator>
sl@0
   926
#endif
sl@0
   927
   (
sl@0
   928
      re_detail::do_regex_replace(
sl@0
   929
         re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
sl@0
   930
         re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
sl@0
   931
         e,
sl@0
   932
         re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
sl@0
   933
         flags)
sl@0
   934
      );
sl@0
   935
}
sl@0
   936
sl@0
   937
template <class charT>
sl@0
   938
std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
sl@0
   939
                         const u32regex& e, 
sl@0
   940
                         const charT* fmt,
sl@0
   941
                         match_flag_type flags = match_default)
sl@0
   942
{
sl@0
   943
   std::basic_string<charT> result;
sl@0
   944
   re_detail::string_out_iterator<std::basic_string<charT> > i(result);
sl@0
   945
   u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
sl@0
   946
   return result;
sl@0
   947
}
sl@0
   948
sl@0
   949
template <class charT>
sl@0
   950
std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
sl@0
   951
                         const u32regex& e, 
sl@0
   952
                         const std::basic_string<charT>& fmt,
sl@0
   953
                         match_flag_type flags = match_default)
sl@0
   954
{
sl@0
   955
   std::basic_string<charT> result;
sl@0
   956
   re_detail::string_out_iterator<std::basic_string<charT> > i(result);
sl@0
   957
   u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
sl@0
   958
   return result;
sl@0
   959
}
sl@0
   960
sl@0
   961
namespace re_detail{
sl@0
   962
sl@0
   963
class unicode_string_out_iterator
sl@0
   964
{
sl@0
   965
   UnicodeString* out;
sl@0
   966
public:
sl@0
   967
   unicode_string_out_iterator(UnicodeString& s) : out(&s) {}
sl@0
   968
   unicode_string_out_iterator& operator++() { return *this; }
sl@0
   969
   unicode_string_out_iterator& operator++(int) { return *this; }
sl@0
   970
   unicode_string_out_iterator& operator*() { return *this; }
sl@0
   971
   unicode_string_out_iterator& operator=(UChar v) 
sl@0
   972
   { 
sl@0
   973
      *out += v; 
sl@0
   974
      return *this; 
sl@0
   975
   }
sl@0
   976
   typedef std::ptrdiff_t difference_type;
sl@0
   977
   typedef UChar value_type;
sl@0
   978
   typedef value_type* pointer;
sl@0
   979
   typedef value_type& reference;
sl@0
   980
   typedef std::output_iterator_tag iterator_category;
sl@0
   981
};
sl@0
   982
sl@0
   983
}
sl@0
   984
sl@0
   985
inline UnicodeString u32regex_replace(const UnicodeString& s,
sl@0
   986
                         const u32regex& e, 
sl@0
   987
                         const UChar* fmt,
sl@0
   988
                         match_flag_type flags = match_default)
sl@0
   989
{
sl@0
   990
   UnicodeString result;
sl@0
   991
   re_detail::unicode_string_out_iterator i(result);
sl@0
   992
   u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
sl@0
   993
   return result;
sl@0
   994
}
sl@0
   995
sl@0
   996
inline UnicodeString u32regex_replace(const UnicodeString& s,
sl@0
   997
                         const u32regex& e, 
sl@0
   998
                         const UnicodeString& fmt,
sl@0
   999
                         match_flag_type flags = match_default)
sl@0
  1000
{
sl@0
  1001
   UnicodeString result;
sl@0
  1002
   re_detail::unicode_string_out_iterator i(result);
sl@0
  1003
   re_detail::do_regex_replace(
sl@0
  1004
         re_detail::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)),
sl@0
  1005
         re_detail::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<mpl::int_<2> const*>(0)),
sl@0
  1006
         e,
sl@0
  1007
         re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
sl@0
  1008
         flags);
sl@0
  1009
   return result;
sl@0
  1010
}
sl@0
  1011
sl@0
  1012
} // namespace boost.
sl@0
  1013
sl@0
  1014
#include <boost/regex/v4/u32regex_iterator.hpp>
sl@0
  1015
#include <boost/regex/v4/u32regex_token_iterator.hpp>
sl@0
  1016
sl@0
  1017
#endif