icu.hpp 40 KB

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