icu.hpp 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  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_V5_HPP
  18. #define BOOST_REGEX_ICU_V5_HPP
  19. #include <unicode/utypes.h>
  20. #include <unicode/uchar.h>
  21. #include <unicode/coll.h>
  22. #include <type_traits>
  23. #include <functional>
  24. #include <boost/regex.hpp>
  25. #include <boost/regex/v5/unicode_iterator.hpp>
  26. #ifdef BOOST_REGEX_MSVC
  27. #pragma warning (push)
  28. #pragma warning (disable: 4251)
  29. #endif
  30. namespace boost{
  31. namespace BOOST_REGEX_DETAIL_NS{
  32. //
  33. // Implementation details:
  34. //
  35. class icu_regex_traits_implementation
  36. {
  37. typedef UChar32 char_type;
  38. typedef std::size_t size_type;
  39. typedef std::vector<char_type> string_type;
  40. typedef U_NAMESPACE_QUALIFIER Locale locale_type;
  41. typedef std::uint_least32_t char_class_type;
  42. public:
  43. icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
  44. : m_locale(l)
  45. {
  46. UErrorCode success = U_ZERO_ERROR;
  47. m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
  48. if(U_SUCCESS(success) == 0)
  49. init_error();
  50. m_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::IDENTICAL);
  51. success = U_ZERO_ERROR;
  52. m_primary_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
  53. if(U_SUCCESS(success) == 0)
  54. init_error();
  55. m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
  56. }
  57. U_NAMESPACE_QUALIFIER Locale getloc()const
  58. {
  59. return m_locale;
  60. }
  61. string_type do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const
  62. {
  63. // TODO make thread safe!!!! :
  64. typedef u32_to_u16_iterator<const char_type*, ::UChar> itt;
  65. itt i(p1), j(p2);
  66. std::vector< ::UChar> t(i, j);
  67. std::uint8_t result[100];
  68. std::int32_t len;
  69. if (!t.empty())
  70. len = pcoll->getSortKey(&*t.begin(), static_cast<std::int32_t>(t.size()), result, sizeof(result));
  71. else
  72. len = pcoll->getSortKey(static_cast<UChar const*>(0), static_cast<std::int32_t>(0), result, sizeof(result));
  73. if (std::size_t(len) > sizeof(result))
  74. {
  75. std::unique_ptr< std::uint8_t[]> presult(new ::uint8_t[len + 1]);
  76. if (!t.empty())
  77. len = pcoll->getSortKey(&*t.begin(), static_cast<std::int32_t>(t.size()), presult.get(), len + 1);
  78. else
  79. len = pcoll->getSortKey(static_cast<UChar const*>(0), static_cast<std::int32_t>(0), presult.get(), len + 1);
  80. if ((0 == presult[len - 1]) && (len > 1))
  81. --len;
  82. return string_type(presult.get(), presult.get() + len);
  83. }
  84. if ((0 == result[len - 1]) && (len > 1))
  85. --len;
  86. return string_type(result, result + len);
  87. }
  88. string_type transform(const char_type* p1, const char_type* p2) const
  89. {
  90. return do_transform(p1, p2, m_collator.get());
  91. }
  92. string_type transform_primary(const char_type* p1, const char_type* p2) const
  93. {
  94. return do_transform(p1, p2, m_primary_collator.get());
  95. }
  96. private:
  97. void init_error()
  98. {
  99. std::runtime_error e("Could not initialize ICU resources");
  100. #ifndef BOOST_REGEX_STANDALONE
  101. boost::throw_exception(e);
  102. #else
  103. throw e;
  104. #endif
  105. }
  106. U_NAMESPACE_QUALIFIER Locale m_locale; // The ICU locale that we're using
  107. std::unique_ptr< U_NAMESPACE_QUALIFIER Collator> m_collator; // The full collation object
  108. std::unique_ptr< U_NAMESPACE_QUALIFIER Collator> m_primary_collator; // The primary collation object
  109. };
  110. inline std::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
  111. {
  112. return std::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
  113. }
  114. }
  115. class icu_regex_traits
  116. {
  117. public:
  118. typedef UChar32 char_type;
  119. typedef std::size_t size_type;
  120. typedef std::vector<char_type> string_type;
  121. typedef U_NAMESPACE_QUALIFIER Locale locale_type;
  122. typedef std::uint64_t char_class_type;
  123. struct boost_extensions_tag{};
  124. icu_regex_traits()
  125. : m_pimpl(BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
  126. {
  127. }
  128. static size_type length(const char_type* p)
  129. {
  130. size_type result = 0;
  131. while (*p)
  132. {
  133. ++p;
  134. ++result;
  135. }
  136. return result;
  137. }
  138. ::boost::regex_constants::syntax_type syntax_type(char_type c)const
  139. {
  140. return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
  141. }
  142. ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
  143. {
  144. return ((c < 0x7f) && (c > 0)) ? BOOST_REGEX_DETAIL_NS::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
  145. }
  146. char_type translate(char_type c) const
  147. {
  148. return c;
  149. }
  150. char_type translate_nocase(char_type c) const
  151. {
  152. return ::u_tolower(c);
  153. }
  154. char_type translate(char_type c, bool icase) const
  155. {
  156. return icase ? translate_nocase(c) : translate(c);
  157. }
  158. char_type tolower(char_type c) const
  159. {
  160. return ::u_tolower(c);
  161. }
  162. char_type toupper(char_type c) const
  163. {
  164. return ::u_toupper(c);
  165. }
  166. string_type transform(const char_type* p1, const char_type* p2) const
  167. {
  168. return m_pimpl->transform(p1, p2);
  169. }
  170. string_type transform_primary(const char_type* p1, const char_type* p2) const
  171. {
  172. return m_pimpl->transform_primary(p1, p2);
  173. }
  174. char_class_type lookup_classname(const char_type* p1, const char_type* p2) const
  175. {
  176. constexpr char_class_type mask_blank = char_class_type(1) << offset_blank;
  177. constexpr char_class_type mask_space = char_class_type(1) << offset_space;
  178. constexpr char_class_type mask_xdigit = char_class_type(1) << offset_xdigit;
  179. constexpr char_class_type mask_underscore = char_class_type(1) << offset_underscore;
  180. constexpr char_class_type mask_unicode = char_class_type(1) << offset_unicode;
  181. constexpr char_class_type mask_any = char_class_type(1) << offset_any;
  182. constexpr char_class_type mask_ascii = char_class_type(1) << offset_ascii;
  183. constexpr char_class_type mask_horizontal = char_class_type(1) << offset_horizontal;
  184. constexpr char_class_type mask_vertical = char_class_type(1) << offset_vertical;
  185. static const char_class_type masks[] =
  186. {
  187. 0,
  188. U_GC_L_MASK | U_GC_ND_MASK,
  189. U_GC_L_MASK,
  190. mask_blank,
  191. U_GC_CC_MASK | U_GC_CF_MASK | U_GC_ZL_MASK | U_GC_ZP_MASK,
  192. U_GC_ND_MASK,
  193. U_GC_ND_MASK,
  194. (0x3FFFFFFFu) & ~(U_GC_CC_MASK | U_GC_CF_MASK | U_GC_CS_MASK | U_GC_CN_MASK | U_GC_Z_MASK),
  195. mask_horizontal,
  196. U_GC_LL_MASK,
  197. U_GC_LL_MASK,
  198. ~(U_GC_C_MASK),
  199. U_GC_P_MASK,
  200. char_class_type(U_GC_Z_MASK) | mask_space,
  201. char_class_type(U_GC_Z_MASK) | mask_space,
  202. U_GC_LU_MASK,
  203. mask_unicode,
  204. U_GC_LU_MASK,
  205. mask_vertical,
  206. char_class_type(U_GC_L_MASK | U_GC_ND_MASK | U_GC_MN_MASK) | mask_underscore,
  207. char_class_type(U_GC_L_MASK | U_GC_ND_MASK | U_GC_MN_MASK) | mask_underscore,
  208. char_class_type(U_GC_ND_MASK) | mask_xdigit,
  209. };
  210. int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2);
  211. if (idx >= 0)
  212. return masks[idx + 1];
  213. char_class_type result = lookup_icu_mask(p1, p2);
  214. if (result != 0)
  215. return result;
  216. if (idx < 0)
  217. {
  218. string_type s(p1, p2);
  219. string_type::size_type i = 0;
  220. while (i < s.size())
  221. {
  222. s[i] = static_cast<char>((::u_tolower)(s[i]));
  223. if (::u_isspace(s[i]) || (s[i] == '-') || (s[i] == '_'))
  224. s.erase(s.begin() + i, s.begin() + i + 1);
  225. else
  226. {
  227. s[i] = static_cast<char>((::u_tolower)(s[i]));
  228. ++i;
  229. }
  230. }
  231. if (!s.empty())
  232. idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size());
  233. if (idx >= 0)
  234. return masks[idx + 1];
  235. if (!s.empty())
  236. result = lookup_icu_mask(&*s.begin(), &*s.begin() + s.size());
  237. if (result != 0)
  238. return result;
  239. }
  240. BOOST_REGEX_ASSERT(std::size_t(idx + 1) < sizeof(masks) / sizeof(masks[0]));
  241. return masks[idx + 1];
  242. }
  243. string_type lookup_collatename(const char_type* p1, const char_type* p2) const
  244. {
  245. string_type result;
  246. if (std::find_if(p1, p2, std::bind(std::greater< ::UChar32>(), std::placeholders::_1, 0x7f)) == p2)
  247. {
  248. std::string s(p1, p2);
  249. // Try Unicode name:
  250. UErrorCode err = U_ZERO_ERROR;
  251. UChar32 c = ::u_charFromName(U_UNICODE_CHAR_NAME, s.c_str(), &err);
  252. if (U_SUCCESS(err))
  253. {
  254. result.push_back(c);
  255. return result;
  256. }
  257. // Try Unicode-extended name:
  258. err = U_ZERO_ERROR;
  259. c = ::u_charFromName(U_EXTENDED_CHAR_NAME, s.c_str(), &err);
  260. if (U_SUCCESS(err))
  261. {
  262. result.push_back(c);
  263. return result;
  264. }
  265. // try POSIX name:
  266. s = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(s);
  267. result.assign(s.begin(), s.end());
  268. }
  269. if (result.empty() && (p2 - p1 == 1))
  270. result.push_back(*p1);
  271. return result;
  272. }
  273. bool isctype(char_type c, char_class_type f) const
  274. {
  275. constexpr char_class_type mask_blank = char_class_type(1) << offset_blank;
  276. constexpr char_class_type mask_space = char_class_type(1) << offset_space;
  277. constexpr char_class_type mask_xdigit = char_class_type(1) << offset_xdigit;
  278. constexpr char_class_type mask_underscore = char_class_type(1) << offset_underscore;
  279. constexpr char_class_type mask_unicode = char_class_type(1) << offset_unicode;
  280. constexpr char_class_type mask_any = char_class_type(1) << offset_any;
  281. constexpr char_class_type mask_ascii = char_class_type(1) << offset_ascii;
  282. constexpr char_class_type mask_horizontal = char_class_type(1) << offset_horizontal;
  283. constexpr char_class_type mask_vertical = char_class_type(1) << offset_vertical;
  284. // check for standard catagories first:
  285. char_class_type m = char_class_type(static_cast<char_class_type>(1) << u_charType(c));
  286. if ((m & f) != 0)
  287. return true;
  288. // now check for special cases:
  289. if (((f & mask_blank) != 0) && u_isblank(c))
  290. return true;
  291. if (((f & mask_space) != 0) && u_isspace(c))
  292. return true;
  293. if (((f & mask_xdigit) != 0) && (u_digit(c, 16) >= 0))
  294. return true;
  295. if (((f & mask_unicode) != 0) && (c >= 0x100))
  296. return true;
  297. if (((f & mask_underscore) != 0) && (c == '_'))
  298. return true;
  299. if (((f & mask_any) != 0) && (c <= 0x10FFFF))
  300. return true;
  301. if (((f & mask_ascii) != 0) && (c <= 0x7F))
  302. return true;
  303. if (((f & mask_vertical) != 0) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == static_cast<char_type>('\v')) || (m == U_GC_ZL_MASK) || (m == U_GC_ZP_MASK)))
  304. return true;
  305. if (((f & mask_horizontal) != 0) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && u_isspace(c) && (c != static_cast<char_type>('\v')))
  306. return true;
  307. return false;
  308. }
  309. std::intmax_t toi(const char_type*& p1, const char_type* p2, int radix)const
  310. {
  311. return BOOST_REGEX_DETAIL_NS::global_toi(p1, p2, radix, *this);
  312. }
  313. int value(char_type c, int radix)const
  314. {
  315. return u_digit(c, static_cast< std::int8_t>(radix));
  316. }
  317. locale_type imbue(locale_type l)
  318. {
  319. locale_type result(m_pimpl->getloc());
  320. m_pimpl = BOOST_REGEX_DETAIL_NS::get_icu_regex_traits_implementation(l);
  321. return result;
  322. }
  323. locale_type getloc()const
  324. {
  325. return locale_type();
  326. }
  327. std::string error_string(::boost::regex_constants::error_type n) const
  328. {
  329. return BOOST_REGEX_DETAIL_NS::get_default_error_string(n);
  330. }
  331. private:
  332. icu_regex_traits(const icu_regex_traits&);
  333. icu_regex_traits& operator=(const icu_regex_traits&);
  334. //
  335. // define the bitmasks offsets we need for additional character properties:
  336. //
  337. enum{
  338. offset_blank = U_CHAR_CATEGORY_COUNT,
  339. offset_space = U_CHAR_CATEGORY_COUNT+1,
  340. offset_xdigit = U_CHAR_CATEGORY_COUNT+2,
  341. offset_underscore = U_CHAR_CATEGORY_COUNT+3,
  342. offset_unicode = U_CHAR_CATEGORY_COUNT+4,
  343. offset_any = U_CHAR_CATEGORY_COUNT+5,
  344. offset_ascii = U_CHAR_CATEGORY_COUNT+6,
  345. offset_horizontal = U_CHAR_CATEGORY_COUNT+7,
  346. offset_vertical = U_CHAR_CATEGORY_COUNT+8
  347. };
  348. static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2)
  349. {
  350. constexpr char_class_type mask_blank = char_class_type(1) << offset_blank;
  351. constexpr char_class_type mask_space = char_class_type(1) << offset_space;
  352. constexpr char_class_type mask_xdigit = char_class_type(1) << offset_xdigit;
  353. constexpr char_class_type mask_underscore = char_class_type(1) << offset_underscore;
  354. constexpr char_class_type mask_unicode = char_class_type(1) << offset_unicode;
  355. constexpr char_class_type mask_any = char_class_type(1) << offset_any;
  356. constexpr char_class_type mask_ascii = char_class_type(1) << offset_ascii;
  357. constexpr char_class_type mask_horizontal = char_class_type(1) << offset_horizontal;
  358. constexpr char_class_type mask_vertical = char_class_type(1) << offset_vertical;
  359. static const ::UChar32 prop_name_table[] = {
  360. /* any */ 'a', 'n', 'y',
  361. /* ascii */ 'a', 's', 'c', 'i', 'i',
  362. /* assigned */ 'a', 's', 's', 'i', 'g', 'n', 'e', 'd',
  363. /* c* */ 'c', '*',
  364. /* cc */ 'c', 'c',
  365. /* cf */ 'c', 'f',
  366. /* closepunctuation */ 'c', 'l', 'o', 's', 'e', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
  367. /* cn */ 'c', 'n',
  368. /* co */ 'c', 'o',
  369. /* connectorpunctuation */ 'c', 'o', 'n', 'n', 'e', 'c', 't', 'o', 'r', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
  370. /* control */ 'c', 'o', 'n', 't', 'r', 'o', 'l',
  371. /* cs */ 'c', 's',
  372. /* currencysymbol */ 'c', 'u', 'r', 'r', 'e', 'n', 'c', 'y', 's', 'y', 'm', 'b', 'o', 'l',
  373. /* dashpunctuation */ 'd', 'a', 's', 'h', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
  374. /* decimaldigitnumber */ 'd', 'e', 'c', 'i', 'm', 'a', 'l', 'd', 'i', 'g', 'i', 't', 'n', 'u', 'm', 'b', 'e', 'r',
  375. /* enclosingmark */ 'e', 'n', 'c', 'l', 'o', 's', 'i', 'n', 'g', 'm', 'a', 'r', 'k',
  376. /* finalpunctuation */ 'f', 'i', 'n', 'a', 'l', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
  377. /* format */ 'f', 'o', 'r', 'm', 'a', 't',
  378. /* initialpunctuation */ 'i', 'n', 'i', 't', 'i', 'a', 'l', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
  379. /* l* */ 'l', '*',
  380. /* letter */ 'l', 'e', 't', 't', 'e', 'r',
  381. /* letternumber */ 'l', 'e', 't', 't', 'e', 'r', 'n', 'u', 'm', 'b', 'e', 'r',
  382. /* lineseparator */ 'l', 'i', 'n', 'e', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
  383. /* ll */ 'l', 'l',
  384. /* lm */ 'l', 'm',
  385. /* lo */ 'l', 'o',
  386. /* lowercaseletter */ 'l', 'o', 'w', 'e', 'r', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
  387. /* lt */ 'l', 't',
  388. /* lu */ 'l', 'u',
  389. /* m* */ 'm', '*',
  390. /* mark */ 'm', 'a', 'r', 'k',
  391. /* mathsymbol */ 'm', 'a', 't', 'h', 's', 'y', 'm', 'b', 'o', 'l',
  392. /* mc */ 'm', 'c',
  393. /* me */ 'm', 'e',
  394. /* mn */ 'm', 'n',
  395. /* modifierletter */ 'm', 'o', 'd', 'i', 'f', 'i', 'e', 'r', 'l', 'e', 't', 't', 'e', 'r',
  396. /* modifiersymbol */ 'm', 'o', 'd', 'i', 'f', 'i', 'e', 'r', 's', 'y', 'm', 'b', 'o', 'l',
  397. /* n* */ 'n', '*',
  398. /* nd */ 'n', 'd',
  399. /* nl */ 'n', 'l',
  400. /* no */ 'n', 'o',
  401. /* nonspacingmark */ 'n', 'o', 'n', 's', 'p', 'a', 'c', 'i', 'n', 'g', 'm', 'a', 'r', 'k',
  402. /* notassigned */ 'n', 'o', 't', 'a', 's', 's', 'i', 'g', 'n', 'e', 'd',
  403. /* number */ 'n', 'u', 'm', 'b', 'e', 'r',
  404. /* openpunctuation */ 'o', 'p', 'e', 'n', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
  405. /* other */ 'o', 't', 'h', 'e', 'r',
  406. /* otherletter */ 'o', 't', 'h', 'e', 'r', 'l', 'e', 't', 't', 'e', 'r',
  407. /* othernumber */ 'o', 't', 'h', 'e', 'r', 'n', 'u', 'm', 'b', 'e', 'r',
  408. /* otherpunctuation */ 'o', 't', 'h', 'e', 'r', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
  409. /* othersymbol */ 'o', 't', 'h', 'e', 'r', 's', 'y', 'm', 'b', 'o', 'l',
  410. /* p* */ 'p', '*',
  411. /* paragraphseparator */ 'p', 'a', 'r', 'a', 'g', 'r', 'a', 'p', 'h', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
  412. /* pc */ 'p', 'c',
  413. /* pd */ 'p', 'd',
  414. /* pe */ 'p', 'e',
  415. /* pf */ 'p', 'f',
  416. /* pi */ 'p', 'i',
  417. /* po */ 'p', 'o',
  418. /* privateuse */ 'p', 'r', 'i', 'v', 'a', 't', 'e', 'u', 's', 'e',
  419. /* ps */ 'p', 's',
  420. /* punctuation */ 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
  421. /* s* */ 's', '*',
  422. /* sc */ 's', 'c',
  423. /* separator */ 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
  424. /* sk */ 's', 'k',
  425. /* sm */ 's', 'm',
  426. /* so */ 's', 'o',
  427. /* spaceseparator */ 's', 'p', 'a', 'c', 'e', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
  428. /* spacingcombiningmark */ 's', 'p', 'a', 'c', 'i', 'n', 'g', 'c', 'o', 'm', 'b', 'i', 'n', 'i', 'n', 'g', 'm', 'a', 'r', 'k',
  429. /* surrogate */ 's', 'u', 'r', 'r', 'o', 'g', 'a', 't', 'e',
  430. /* symbol */ 's', 'y', 'm', 'b', 'o', 'l',
  431. /* titlecase */ 't', 'i', 't', 'l', 'e', 'c', 'a', 's', 'e',
  432. /* titlecaseletter */ 't', 'i', 't', 'l', 'e', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
  433. /* uppercaseletter */ 'u', 'p', 'p', 'e', 'r', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
  434. /* z* */ 'z', '*',
  435. /* zl */ 'z', 'l',
  436. /* zp */ 'z', 'p',
  437. /* zs */ 'z', 's',
  438. };
  439. static const BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32> range_data[] = {
  440. { prop_name_table + 0, prop_name_table + 3, }, // any
  441. { prop_name_table + 3, prop_name_table + 8, }, // ascii
  442. { prop_name_table + 8, prop_name_table + 16, }, // assigned
  443. { prop_name_table + 16, prop_name_table + 18, }, // c*
  444. { prop_name_table + 18, prop_name_table + 20, }, // cc
  445. { prop_name_table + 20, prop_name_table + 22, }, // cf
  446. { prop_name_table + 22, prop_name_table + 38, }, // closepunctuation
  447. { prop_name_table + 38, prop_name_table + 40, }, // cn
  448. { prop_name_table + 40, prop_name_table + 42, }, // co
  449. { prop_name_table + 42, prop_name_table + 62, }, // connectorpunctuation
  450. { prop_name_table + 62, prop_name_table + 69, }, // control
  451. { prop_name_table + 69, prop_name_table + 71, }, // cs
  452. { prop_name_table + 71, prop_name_table + 85, }, // currencysymbol
  453. { prop_name_table + 85, prop_name_table + 100, }, // dashpunctuation
  454. { prop_name_table + 100, prop_name_table + 118, }, // decimaldigitnumber
  455. { prop_name_table + 118, prop_name_table + 131, }, // enclosingmark
  456. { prop_name_table + 131, prop_name_table + 147, }, // finalpunctuation
  457. { prop_name_table + 147, prop_name_table + 153, }, // format
  458. { prop_name_table + 153, prop_name_table + 171, }, // initialpunctuation
  459. { prop_name_table + 171, prop_name_table + 173, }, // l*
  460. { prop_name_table + 173, prop_name_table + 179, }, // letter
  461. { prop_name_table + 179, prop_name_table + 191, }, // letternumber
  462. { prop_name_table + 191, prop_name_table + 204, }, // lineseparator
  463. { prop_name_table + 204, prop_name_table + 206, }, // ll
  464. { prop_name_table + 206, prop_name_table + 208, }, // lm
  465. { prop_name_table + 208, prop_name_table + 210, }, // lo
  466. { prop_name_table + 210, prop_name_table + 225, }, // lowercaseletter
  467. { prop_name_table + 225, prop_name_table + 227, }, // lt
  468. { prop_name_table + 227, prop_name_table + 229, }, // lu
  469. { prop_name_table + 229, prop_name_table + 231, }, // m*
  470. { prop_name_table + 231, prop_name_table + 235, }, // mark
  471. { prop_name_table + 235, prop_name_table + 245, }, // mathsymbol
  472. { prop_name_table + 245, prop_name_table + 247, }, // mc
  473. { prop_name_table + 247, prop_name_table + 249, }, // me
  474. { prop_name_table + 249, prop_name_table + 251, }, // mn
  475. { prop_name_table + 251, prop_name_table + 265, }, // modifierletter
  476. { prop_name_table + 265, prop_name_table + 279, }, // modifiersymbol
  477. { prop_name_table + 279, prop_name_table + 281, }, // n*
  478. { prop_name_table + 281, prop_name_table + 283, }, // nd
  479. { prop_name_table + 283, prop_name_table + 285, }, // nl
  480. { prop_name_table + 285, prop_name_table + 287, }, // no
  481. { prop_name_table + 287, prop_name_table + 301, }, // nonspacingmark
  482. { prop_name_table + 301, prop_name_table + 312, }, // notassigned
  483. { prop_name_table + 312, prop_name_table + 318, }, // number
  484. { prop_name_table + 318, prop_name_table + 333, }, // openpunctuation
  485. { prop_name_table + 333, prop_name_table + 338, }, // other
  486. { prop_name_table + 338, prop_name_table + 349, }, // otherletter
  487. { prop_name_table + 349, prop_name_table + 360, }, // othernumber
  488. { prop_name_table + 360, prop_name_table + 376, }, // otherpunctuation
  489. { prop_name_table + 376, prop_name_table + 387, }, // othersymbol
  490. { prop_name_table + 387, prop_name_table + 389, }, // p*
  491. { prop_name_table + 389, prop_name_table + 407, }, // paragraphseparator
  492. { prop_name_table + 407, prop_name_table + 409, }, // pc
  493. { prop_name_table + 409, prop_name_table + 411, }, // pd
  494. { prop_name_table + 411, prop_name_table + 413, }, // pe
  495. { prop_name_table + 413, prop_name_table + 415, }, // pf
  496. { prop_name_table + 415, prop_name_table + 417, }, // pi
  497. { prop_name_table + 417, prop_name_table + 419, }, // po
  498. { prop_name_table + 419, prop_name_table + 429, }, // privateuse
  499. { prop_name_table + 429, prop_name_table + 431, }, // ps
  500. { prop_name_table + 431, prop_name_table + 442, }, // punctuation
  501. { prop_name_table + 442, prop_name_table + 444, }, // s*
  502. { prop_name_table + 444, prop_name_table + 446, }, // sc
  503. { prop_name_table + 446, prop_name_table + 455, }, // separator
  504. { prop_name_table + 455, prop_name_table + 457, }, // sk
  505. { prop_name_table + 457, prop_name_table + 459, }, // sm
  506. { prop_name_table + 459, prop_name_table + 461, }, // so
  507. { prop_name_table + 461, prop_name_table + 475, }, // spaceseparator
  508. { prop_name_table + 475, prop_name_table + 495, }, // spacingcombiningmark
  509. { prop_name_table + 495, prop_name_table + 504, }, // surrogate
  510. { prop_name_table + 504, prop_name_table + 510, }, // symbol
  511. { prop_name_table + 510, prop_name_table + 519, }, // titlecase
  512. { prop_name_table + 519, prop_name_table + 534, }, // titlecaseletter
  513. { prop_name_table + 534, prop_name_table + 549, }, // uppercaseletter
  514. { prop_name_table + 549, prop_name_table + 551, }, // z*
  515. { prop_name_table + 551, prop_name_table + 553, }, // zl
  516. { prop_name_table + 553, prop_name_table + 555, }, // zp
  517. { prop_name_table + 555, prop_name_table + 557, }, // zs
  518. };
  519. static const icu_regex_traits::char_class_type icu_class_map[] = {
  520. mask_any, // any
  521. mask_ascii, // ascii
  522. (0x3FFFFFFFu) & ~(U_GC_CN_MASK), // assigned
  523. U_GC_C_MASK, // c*
  524. U_GC_CC_MASK, // cc
  525. U_GC_CF_MASK, // cf
  526. U_GC_PE_MASK, // closepunctuation
  527. U_GC_CN_MASK, // cn
  528. U_GC_CO_MASK, // co
  529. U_GC_PC_MASK, // connectorpunctuation
  530. U_GC_CC_MASK, // control
  531. U_GC_CS_MASK, // cs
  532. U_GC_SC_MASK, // currencysymbol
  533. U_GC_PD_MASK, // dashpunctuation
  534. U_GC_ND_MASK, // decimaldigitnumber
  535. U_GC_ME_MASK, // enclosingmark
  536. U_GC_PF_MASK, // finalpunctuation
  537. U_GC_CF_MASK, // format
  538. U_GC_PI_MASK, // initialpunctuation
  539. U_GC_L_MASK, // l*
  540. U_GC_L_MASK, // letter
  541. U_GC_NL_MASK, // letternumber
  542. U_GC_ZL_MASK, // lineseparator
  543. U_GC_LL_MASK, // ll
  544. U_GC_LM_MASK, // lm
  545. U_GC_LO_MASK, // lo
  546. U_GC_LL_MASK, // lowercaseletter
  547. U_GC_LT_MASK, // lt
  548. U_GC_LU_MASK, // lu
  549. U_GC_M_MASK, // m*
  550. U_GC_M_MASK, // mark
  551. U_GC_SM_MASK, // mathsymbol
  552. U_GC_MC_MASK, // mc
  553. U_GC_ME_MASK, // me
  554. U_GC_MN_MASK, // mn
  555. U_GC_LM_MASK, // modifierletter
  556. U_GC_SK_MASK, // modifiersymbol
  557. U_GC_N_MASK, // n*
  558. U_GC_ND_MASK, // nd
  559. U_GC_NL_MASK, // nl
  560. U_GC_NO_MASK, // no
  561. U_GC_MN_MASK, // nonspacingmark
  562. U_GC_CN_MASK, // notassigned
  563. U_GC_N_MASK, // number
  564. U_GC_PS_MASK, // openpunctuation
  565. U_GC_C_MASK, // other
  566. U_GC_LO_MASK, // otherletter
  567. U_GC_NO_MASK, // othernumber
  568. U_GC_PO_MASK, // otherpunctuation
  569. U_GC_SO_MASK, // othersymbol
  570. U_GC_P_MASK, // p*
  571. U_GC_ZP_MASK, // paragraphseparator
  572. U_GC_PC_MASK, // pc
  573. U_GC_PD_MASK, // pd
  574. U_GC_PE_MASK, // pe
  575. U_GC_PF_MASK, // pf
  576. U_GC_PI_MASK, // pi
  577. U_GC_PO_MASK, // po
  578. U_GC_CO_MASK, // privateuse
  579. U_GC_PS_MASK, // ps
  580. U_GC_P_MASK, // punctuation
  581. U_GC_S_MASK, // s*
  582. U_GC_SC_MASK, // sc
  583. U_GC_Z_MASK, // separator
  584. U_GC_SK_MASK, // sk
  585. U_GC_SM_MASK, // sm
  586. U_GC_SO_MASK, // so
  587. U_GC_ZS_MASK, // spaceseparator
  588. U_GC_MC_MASK, // spacingcombiningmark
  589. U_GC_CS_MASK, // surrogate
  590. U_GC_S_MASK, // symbol
  591. U_GC_LT_MASK, // titlecase
  592. U_GC_LT_MASK, // titlecaseletter
  593. U_GC_LU_MASK, // uppercaseletter
  594. U_GC_Z_MASK, // z*
  595. U_GC_ZL_MASK, // zl
  596. U_GC_ZP_MASK, // zp
  597. U_GC_ZS_MASK, // zs
  598. };
  599. const BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32>* ranges_begin = range_data;
  600. const BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32>* ranges_end = range_data + (sizeof(range_data) / sizeof(range_data[0]));
  601. BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32> t = { p1, p2, };
  602. const BOOST_REGEX_DETAIL_NS::character_pointer_range< ::UChar32>* p = std::lower_bound(ranges_begin, ranges_end, t);
  603. if ((p != ranges_end) && (t == *p))
  604. return icu_class_map[p - ranges_begin];
  605. return 0;
  606. }
  607. std::shared_ptr< ::boost::BOOST_REGEX_DETAIL_NS::icu_regex_traits_implementation> m_pimpl;
  608. };
  609. } // namespace boost
  610. namespace boost{
  611. // types:
  612. typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
  613. typedef match_results<const ::UChar32*> u32match;
  614. typedef match_results<const ::UChar*> u16match;
  615. //
  616. // Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
  617. //
  618. namespace BOOST_REGEX_DETAIL_NS{
  619. template <class InputIterator>
  620. inline u32regex do_make_u32regex(InputIterator i,
  621. InputIterator j,
  622. boost::regex_constants::syntax_option_type opt,
  623. const std::integral_constant<int, 1>*)
  624. {
  625. typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
  626. return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
  627. }
  628. template <class InputIterator>
  629. inline u32regex do_make_u32regex(InputIterator i,
  630. InputIterator j,
  631. boost::regex_constants::syntax_option_type opt,
  632. const std::integral_constant<int, 2>*)
  633. {
  634. typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
  635. return u32regex(conv_type(i, i, j), conv_type(j, i, j), opt);
  636. }
  637. template <class InputIterator>
  638. inline u32regex do_make_u32regex(InputIterator i,
  639. InputIterator j,
  640. boost::regex_constants::syntax_option_type opt,
  641. const std::integral_constant<int, 4>*)
  642. {
  643. return u32regex(i, j, opt);
  644. }
  645. }
  646. // BOOST_REGEX_UCHAR_IS_WCHAR_T
  647. //
  648. // Source inspection of unicode/umachine.h in ICU version 59 indicates that:
  649. //
  650. // On version 59, UChar is always char16_t in C++ mode (and uint16_t in C mode)
  651. //
  652. // On earlier versions, the logic is
  653. //
  654. // #if U_SIZEOF_WCHAR_T==2
  655. // typedef wchar_t OldUChar;
  656. // #elif defined(__CHAR16_TYPE__)
  657. // typedef __CHAR16_TYPE__ OldUChar;
  658. // #else
  659. // typedef uint16_t OldUChar;
  660. // #endif
  661. //
  662. // That is, UChar is wchar_t only on versions below 59, when U_SIZEOF_WCHAR_T==2
  663. //
  664. // Hence,
  665. #define BOOST_REGEX_UCHAR_IS_WCHAR_T (U_ICU_VERSION_MAJOR_NUM < 59 && U_SIZEOF_WCHAR_T == 2)
  666. #if BOOST_REGEX_UCHAR_IS_WCHAR_T
  667. static_assert((std::is_same<UChar, wchar_t>::value), "Configuration logic has failed!");
  668. #else
  669. static_assert(!(std::is_same<UChar, wchar_t>::value), "Configuration logic has failed!");
  670. #endif
  671. //
  672. // Construction from an iterator pair:
  673. //
  674. template <class InputIterator>
  675. inline u32regex make_u32regex(InputIterator i,
  676. InputIterator j,
  677. boost::regex_constants::syntax_option_type opt)
  678. {
  679. return BOOST_REGEX_DETAIL_NS::do_make_u32regex(i, j, opt, static_cast<std::integral_constant<int, sizeof(*i)> const*>(0));
  680. }
  681. //
  682. // construction from UTF-8 nul-terminated strings:
  683. //
  684. inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
  685. {
  686. return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<std::integral_constant<int, 1> const*>(0));
  687. }
  688. inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
  689. {
  690. return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::strlen(reinterpret_cast<const char*>(p)), opt, static_cast<std::integral_constant<int, 1> const*>(0));
  691. }
  692. //
  693. // construction from UTF-16 nul-terminated strings:
  694. //
  695. #ifndef BOOST_NO_WREGEX
  696. inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
  697. {
  698. return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
  699. }
  700. #endif
  701. #if !BOOST_REGEX_UCHAR_IS_WCHAR_T
  702. inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
  703. {
  704. return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<std::integral_constant<int, 2> const*>(0));
  705. }
  706. #endif
  707. //
  708. // construction from basic_string class-template:
  709. //
  710. template<class C, class T, class A>
  711. inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
  712. {
  713. return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.begin(), s.end(), opt, static_cast<std::integral_constant<int, sizeof(C)> const*>(0));
  714. }
  715. //
  716. // Construction from ICU string type:
  717. //
  718. inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
  719. {
  720. return BOOST_REGEX_DETAIL_NS::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<std::integral_constant<int, 2> const*>(0));
  721. }
  722. //
  723. // regex_match overloads that widen the character type as appropriate:
  724. //
  725. namespace BOOST_REGEX_DETAIL_NS{
  726. template<class MR1, class MR2, class NSubs>
  727. void copy_results(MR1& out, MR2 const& in, NSubs named_subs)
  728. {
  729. // copy results from an adapted MR2 match_results:
  730. out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
  731. out.set_base(in.base().base());
  732. out.set_named_subs(named_subs);
  733. for(int i = 0; i < (int)in.size(); ++i)
  734. {
  735. if(in[i].matched || !i)
  736. {
  737. out.set_first(in[i].first.base(), i);
  738. out.set_second(in[i].second.base(), i, in[i].matched);
  739. }
  740. }
  741. #ifdef BOOST_REGEX_MATCH_EXTRA
  742. // Copy full capture info as well:
  743. for(int i = 0; i < (int)in.size(); ++i)
  744. {
  745. if(in[i].captures().size())
  746. {
  747. out[i].get_captures().assign(in[i].captures().size(), typename MR1::value_type());
  748. for(int j = 0; j < (int)out[i].captures().size(); ++j)
  749. {
  750. out[i].get_captures()[j].first = in[i].captures()[j].first.base();
  751. out[i].get_captures()[j].second = in[i].captures()[j].second.base();
  752. out[i].get_captures()[j].matched = in[i].captures()[j].matched;
  753. }
  754. }
  755. }
  756. #endif
  757. }
  758. template <class BidiIterator, class Allocator>
  759. inline bool do_regex_match(BidiIterator first, BidiIterator last,
  760. match_results<BidiIterator, Allocator>& m,
  761. const u32regex& e,
  762. match_flag_type flags,
  763. std::integral_constant<int, 4> const*)
  764. {
  765. return ::boost::regex_match(first, last, m, e, flags);
  766. }
  767. template <class BidiIterator, class Allocator>
  768. bool do_regex_match(BidiIterator first, BidiIterator last,
  769. match_results<BidiIterator, Allocator>& m,
  770. const u32regex& e,
  771. match_flag_type flags,
  772. std::integral_constant<int, 2> const*)
  773. {
  774. typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
  775. typedef match_results<conv_type> match_type;
  776. //typedef typename match_type::allocator_type alloc_type;
  777. match_type what;
  778. bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
  779. // copy results across to m:
  780. if(result) copy_results(m, what, e.get_named_subs());
  781. return result;
  782. }
  783. template <class BidiIterator, class Allocator>
  784. bool do_regex_match(BidiIterator first, BidiIterator last,
  785. match_results<BidiIterator, Allocator>& m,
  786. const u32regex& e,
  787. match_flag_type flags,
  788. std::integral_constant<int, 1> const*)
  789. {
  790. typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
  791. typedef match_results<conv_type> match_type;
  792. //typedef typename match_type::allocator_type alloc_type;
  793. match_type what;
  794. bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
  795. // copy results across to m:
  796. if(result) copy_results(m, what, e.get_named_subs());
  797. return result;
  798. }
  799. } // namespace BOOST_REGEX_DETAIL_NS
  800. template <class BidiIterator, class Allocator>
  801. inline bool u32regex_match(BidiIterator first, BidiIterator last,
  802. match_results<BidiIterator, Allocator>& m,
  803. const u32regex& e,
  804. match_flag_type flags = match_default)
  805. {
  806. return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
  807. }
  808. inline bool u32regex_match(const UChar* p,
  809. match_results<const UChar*>& m,
  810. const u32regex& e,
  811. match_flag_type flags = match_default)
  812. {
  813. return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<std::integral_constant<int, 2> const*>(0));
  814. }
  815. #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
  816. inline bool u32regex_match(const wchar_t* p,
  817. match_results<const wchar_t*>& m,
  818. const u32regex& e,
  819. match_flag_type flags = match_default)
  820. {
  821. return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
  822. }
  823. #endif
  824. inline bool u32regex_match(const char* p,
  825. match_results<const char*>& m,
  826. const u32regex& e,
  827. match_flag_type flags = match_default)
  828. {
  829. return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
  830. }
  831. inline bool u32regex_match(const unsigned char* p,
  832. match_results<const unsigned char*>& m,
  833. const u32regex& e,
  834. match_flag_type flags = match_default)
  835. {
  836. return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
  837. }
  838. inline bool u32regex_match(const std::string& s,
  839. match_results<std::string::const_iterator>& m,
  840. const u32regex& e,
  841. match_flag_type flags = match_default)
  842. {
  843. return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
  844. }
  845. #ifndef BOOST_NO_STD_WSTRING
  846. inline bool u32regex_match(const std::wstring& s,
  847. match_results<std::wstring::const_iterator>& m,
  848. const u32regex& e,
  849. match_flag_type flags = match_default)
  850. {
  851. return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
  852. }
  853. #endif
  854. inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
  855. match_results<const UChar*>& m,
  856. const u32regex& e,
  857. match_flag_type flags = match_default)
  858. {
  859. return BOOST_REGEX_DETAIL_NS::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<std::integral_constant<int, 2> const*>(0));
  860. }
  861. //
  862. // regex_match overloads that do not return what matched:
  863. //
  864. template <class BidiIterator>
  865. inline bool u32regex_match(BidiIterator first, BidiIterator last,
  866. const u32regex& e,
  867. match_flag_type flags = match_default)
  868. {
  869. match_results<BidiIterator> m;
  870. return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
  871. }
  872. inline bool u32regex_match(const UChar* p,
  873. const u32regex& e,
  874. match_flag_type flags = match_default)
  875. {
  876. match_results<const UChar*> m;
  877. return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<std::integral_constant<int, 2> const*>(0));
  878. }
  879. #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
  880. inline bool u32regex_match(const wchar_t* p,
  881. const u32regex& e,
  882. match_flag_type flags = match_default)
  883. {
  884. match_results<const wchar_t*> m;
  885. return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
  886. }
  887. #endif
  888. inline bool u32regex_match(const char* p,
  889. const u32regex& e,
  890. match_flag_type flags = match_default)
  891. {
  892. match_results<const char*> m;
  893. return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
  894. }
  895. inline bool u32regex_match(const unsigned char* p,
  896. const u32regex& e,
  897. match_flag_type flags = match_default)
  898. {
  899. match_results<const unsigned char*> m;
  900. return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
  901. }
  902. inline bool u32regex_match(const std::string& s,
  903. const u32regex& e,
  904. match_flag_type flags = match_default)
  905. {
  906. match_results<std::string::const_iterator> m;
  907. return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<std::integral_constant<int, 1> const*>(0));
  908. }
  909. #ifndef BOOST_NO_STD_WSTRING
  910. inline bool u32regex_match(const std::wstring& s,
  911. const u32regex& e,
  912. match_flag_type flags = match_default)
  913. {
  914. match_results<std::wstring::const_iterator> m;
  915. return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
  916. }
  917. #endif
  918. inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
  919. const u32regex& e,
  920. match_flag_type flags = match_default)
  921. {
  922. match_results<const UChar*> m;
  923. return BOOST_REGEX_DETAIL_NS::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<std::integral_constant<int, 2> const*>(0));
  924. }
  925. //
  926. // regex_search overloads that widen the character type as appropriate:
  927. //
  928. namespace BOOST_REGEX_DETAIL_NS{
  929. template <class BidiIterator, class Allocator>
  930. inline bool do_regex_search(BidiIterator first, BidiIterator last,
  931. match_results<BidiIterator, Allocator>& m,
  932. const u32regex& e,
  933. match_flag_type flags,
  934. BidiIterator base,
  935. std::integral_constant<int, 4> const*)
  936. {
  937. return ::boost::regex_search(first, last, m, e, flags, base);
  938. }
  939. template <class BidiIterator, class Allocator>
  940. bool do_regex_search(BidiIterator first, BidiIterator last,
  941. match_results<BidiIterator, Allocator>& m,
  942. const u32regex& e,
  943. match_flag_type flags,
  944. BidiIterator base,
  945. std::integral_constant<int, 2> const*)
  946. {
  947. typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
  948. typedef match_results<conv_type> match_type;
  949. //typedef typename match_type::allocator_type alloc_type;
  950. match_type what;
  951. bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
  952. // copy results across to m:
  953. if(result) copy_results(m, what, e.get_named_subs());
  954. return result;
  955. }
  956. template <class BidiIterator, class Allocator>
  957. bool do_regex_search(BidiIterator first, BidiIterator last,
  958. match_results<BidiIterator, Allocator>& m,
  959. const u32regex& e,
  960. match_flag_type flags,
  961. BidiIterator base,
  962. std::integral_constant<int, 1> const*)
  963. {
  964. typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
  965. typedef match_results<conv_type> match_type;
  966. //typedef typename match_type::allocator_type alloc_type;
  967. match_type what;
  968. bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
  969. // copy results across to m:
  970. if(result) copy_results(m, what, e.get_named_subs());
  971. return result;
  972. }
  973. }
  974. template <class BidiIterator, class Allocator>
  975. inline bool u32regex_search(BidiIterator first, BidiIterator last,
  976. match_results<BidiIterator, Allocator>& m,
  977. const u32regex& e,
  978. match_flag_type flags = match_default)
  979. {
  980. return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
  981. }
  982. template <class BidiIterator, class Allocator>
  983. inline bool u32regex_search(BidiIterator first, BidiIterator last,
  984. match_results<BidiIterator, Allocator>& m,
  985. const u32regex& e,
  986. match_flag_type flags,
  987. BidiIterator base)
  988. {
  989. return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, base, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
  990. }
  991. inline bool u32regex_search(const UChar* p,
  992. match_results<const UChar*>& m,
  993. const u32regex& e,
  994. match_flag_type flags = match_default)
  995. {
  996. return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<std::integral_constant<int, 2> const*>(0));
  997. }
  998. #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
  999. inline bool u32regex_search(const wchar_t* p,
  1000. match_results<const wchar_t*>& m,
  1001. const u32regex& e,
  1002. match_flag_type flags = match_default)
  1003. {
  1004. return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
  1005. }
  1006. #endif
  1007. inline bool u32regex_search(const char* p,
  1008. match_results<const char*>& m,
  1009. const u32regex& e,
  1010. match_flag_type flags = match_default)
  1011. {
  1012. return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<std::integral_constant<int, 1> const*>(0));
  1013. }
  1014. inline bool u32regex_search(const unsigned char* p,
  1015. match_results<const unsigned char*>& m,
  1016. const u32regex& e,
  1017. match_flag_type flags = match_default)
  1018. {
  1019. return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<std::integral_constant<int, 1> const*>(0));
  1020. }
  1021. inline bool u32regex_search(const std::string& s,
  1022. match_results<std::string::const_iterator>& m,
  1023. const u32regex& e,
  1024. match_flag_type flags = match_default)
  1025. {
  1026. return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<std::integral_constant<int, 1> const*>(0));
  1027. }
  1028. #ifndef BOOST_NO_STD_WSTRING
  1029. inline bool u32regex_search(const std::wstring& s,
  1030. match_results<std::wstring::const_iterator>& m,
  1031. const u32regex& e,
  1032. match_flag_type flags = match_default)
  1033. {
  1034. return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
  1035. }
  1036. #endif
  1037. inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
  1038. match_results<const UChar*>& m,
  1039. const u32regex& e,
  1040. match_flag_type flags = match_default)
  1041. {
  1042. return BOOST_REGEX_DETAIL_NS::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<std::integral_constant<int, 2> const*>(0));
  1043. }
  1044. template <class BidiIterator>
  1045. inline bool u32regex_search(BidiIterator first, BidiIterator last,
  1046. const u32regex& e,
  1047. match_flag_type flags = match_default)
  1048. {
  1049. match_results<BidiIterator> m;
  1050. return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0));
  1051. }
  1052. inline bool u32regex_search(const UChar* p,
  1053. const u32regex& e,
  1054. match_flag_type flags = match_default)
  1055. {
  1056. match_results<const UChar*> m;
  1057. return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<std::integral_constant<int, 2> const*>(0));
  1058. }
  1059. #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
  1060. inline bool u32regex_search(const wchar_t* p,
  1061. const u32regex& e,
  1062. match_flag_type flags = match_default)
  1063. {
  1064. match_results<const wchar_t*> m;
  1065. return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
  1066. }
  1067. #endif
  1068. inline bool u32regex_search(const char* p,
  1069. const u32regex& e,
  1070. match_flag_type flags = match_default)
  1071. {
  1072. match_results<const char*> m;
  1073. return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast<std::integral_constant<int, 1> const*>(0));
  1074. }
  1075. inline bool u32regex_search(const unsigned char* p,
  1076. const u32regex& e,
  1077. match_flag_type flags = match_default)
  1078. {
  1079. match_results<const unsigned char*> m;
  1080. return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast<std::integral_constant<int, 1> const*>(0));
  1081. }
  1082. inline bool u32regex_search(const std::string& s,
  1083. const u32regex& e,
  1084. match_flag_type flags = match_default)
  1085. {
  1086. match_results<std::string::const_iterator> m;
  1087. return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<std::integral_constant<int, 1> const*>(0));
  1088. }
  1089. #ifndef BOOST_NO_STD_WSTRING
  1090. inline bool u32regex_search(const std::wstring& s,
  1091. const u32regex& e,
  1092. match_flag_type flags = match_default)
  1093. {
  1094. match_results<std::wstring::const_iterator> m;
  1095. return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<std::integral_constant<int, sizeof(wchar_t)> const*>(0));
  1096. }
  1097. #endif
  1098. inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
  1099. const u32regex& e,
  1100. match_flag_type flags = match_default)
  1101. {
  1102. match_results<const UChar*> m;
  1103. return BOOST_REGEX_DETAIL_NS::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast<std::integral_constant<int, 2> const*>(0));
  1104. }
  1105. //
  1106. // overloads for regex_replace with utf-8 and utf-16 data types:
  1107. //
  1108. namespace BOOST_REGEX_DETAIL_NS{
  1109. template <class I>
  1110. inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
  1111. make_utf32_seq(I i, I j, std::integral_constant<int, 1> const*)
  1112. {
  1113. 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));
  1114. }
  1115. template <class I>
  1116. inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
  1117. make_utf32_seq(I i, I j, std::integral_constant<int, 2> const*)
  1118. {
  1119. 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));
  1120. }
  1121. template <class I>
  1122. inline std::pair< I, I >
  1123. make_utf32_seq(I i, I j, std::integral_constant<int, 4> const*)
  1124. {
  1125. return std::pair< I, I >(i, j);
  1126. }
  1127. template <class charT>
  1128. inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
  1129. make_utf32_seq(const charT* p, std::integral_constant<int, 1> const*)
  1130. {
  1131. std::size_t len = std::strlen((const char*)p);
  1132. 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));
  1133. }
  1134. template <class charT>
  1135. inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
  1136. make_utf32_seq(const charT* p, std::integral_constant<int, 2> const*)
  1137. {
  1138. std::size_t len = u_strlen((const UChar*)p);
  1139. 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));
  1140. }
  1141. template <class charT>
  1142. inline std::pair< const charT*, const charT* >
  1143. make_utf32_seq(const charT* p, std::integral_constant<int, 4> const*)
  1144. {
  1145. return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
  1146. }
  1147. template <class OutputIterator>
  1148. inline OutputIterator make_utf32_out(OutputIterator o, std::integral_constant<int, 4> const*)
  1149. {
  1150. return o;
  1151. }
  1152. template <class OutputIterator>
  1153. inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, std::integral_constant<int, 2> const*)
  1154. {
  1155. return o;
  1156. }
  1157. template <class OutputIterator>
  1158. inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, std::integral_constant<int, 1> const*)
  1159. {
  1160. return o;
  1161. }
  1162. template <class OutputIterator, class I1, class I2>
  1163. OutputIterator do_regex_replace(OutputIterator out,
  1164. std::pair<I1, I1> const& in,
  1165. const u32regex& e,
  1166. const std::pair<I2, I2>& fmt,
  1167. match_flag_type flags
  1168. )
  1169. {
  1170. // unfortunately we have to copy the format string in order to pass in onward:
  1171. std::vector<UChar32> f;
  1172. f.assign(fmt.first, fmt.second);
  1173. regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
  1174. regex_iterator<I1, UChar32, icu_regex_traits> j;
  1175. if(i == j)
  1176. {
  1177. if(!(flags & regex_constants::format_no_copy))
  1178. out = std::copy(in.first, in.second, out);
  1179. }
  1180. else
  1181. {
  1182. I1 last_m = in.first;
  1183. while(i != j)
  1184. {
  1185. if(!(flags & regex_constants::format_no_copy))
  1186. out = std::copy(i->prefix().first, i->prefix().second, out);
  1187. if(!f.empty())
  1188. out = ::boost::BOOST_REGEX_DETAIL_NS::regex_format_imp(out, *i, &*f.begin(), &*f.begin() + f.size(), flags, e.get_traits());
  1189. else
  1190. 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());
  1191. last_m = (*i)[0].second;
  1192. if(flags & regex_constants::format_first_only)
  1193. break;
  1194. ++i;
  1195. }
  1196. if(!(flags & regex_constants::format_no_copy))
  1197. out = std::copy(last_m, in.second, out);
  1198. }
  1199. return out;
  1200. }
  1201. template <class BaseIterator>
  1202. inline const BaseIterator& extract_output_base(const BaseIterator& b)
  1203. {
  1204. return b;
  1205. }
  1206. template <class BaseIterator>
  1207. inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
  1208. {
  1209. return b.base();
  1210. }
  1211. template <class BaseIterator>
  1212. inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
  1213. {
  1214. return b.base();
  1215. }
  1216. } // BOOST_REGEX_DETAIL_NS
  1217. template <class OutputIterator, class BidirectionalIterator, class charT>
  1218. inline OutputIterator u32regex_replace(OutputIterator out,
  1219. BidirectionalIterator first,
  1220. BidirectionalIterator last,
  1221. const u32regex& e,
  1222. const charT* fmt,
  1223. match_flag_type flags = match_default)
  1224. {
  1225. return BOOST_REGEX_DETAIL_NS::extract_output_base
  1226. (
  1227. BOOST_REGEX_DETAIL_NS::do_regex_replace(
  1228. BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
  1229. BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
  1230. e,
  1231. BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt, static_cast<std::integral_constant<int, sizeof(*fmt)> const*>(0)),
  1232. flags)
  1233. );
  1234. }
  1235. template <class OutputIterator, class Iterator, class charT>
  1236. inline OutputIterator u32regex_replace(OutputIterator out,
  1237. Iterator first,
  1238. Iterator last,
  1239. const u32regex& e,
  1240. const std::basic_string<charT>& fmt,
  1241. match_flag_type flags = match_default)
  1242. {
  1243. return BOOST_REGEX_DETAIL_NS::extract_output_base
  1244. (
  1245. BOOST_REGEX_DETAIL_NS::do_regex_replace(
  1246. BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
  1247. BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
  1248. e,
  1249. BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<std::integral_constant<int, sizeof(charT)> const*>(0)),
  1250. flags)
  1251. );
  1252. }
  1253. template <class OutputIterator, class Iterator>
  1254. inline OutputIterator u32regex_replace(OutputIterator out,
  1255. Iterator first,
  1256. Iterator last,
  1257. const u32regex& e,
  1258. const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
  1259. match_flag_type flags = match_default)
  1260. {
  1261. return BOOST_REGEX_DETAIL_NS::extract_output_base
  1262. (
  1263. BOOST_REGEX_DETAIL_NS::do_regex_replace(
  1264. BOOST_REGEX_DETAIL_NS::make_utf32_out(out, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
  1265. BOOST_REGEX_DETAIL_NS::make_utf32_seq(first, last, static_cast<std::integral_constant<int, sizeof(*first)> const*>(0)),
  1266. e,
  1267. BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<std::integral_constant<int, 2> const*>(0)),
  1268. flags)
  1269. );
  1270. }
  1271. template <class charT>
  1272. std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
  1273. const u32regex& e,
  1274. const charT* fmt,
  1275. match_flag_type flags = match_default)
  1276. {
  1277. std::basic_string<charT> result;
  1278. BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
  1279. u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
  1280. return result;
  1281. }
  1282. template <class charT>
  1283. std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
  1284. const u32regex& e,
  1285. const std::basic_string<charT>& fmt,
  1286. match_flag_type flags = match_default)
  1287. {
  1288. std::basic_string<charT> result;
  1289. BOOST_REGEX_DETAIL_NS::string_out_iterator<std::basic_string<charT> > i(result);
  1290. u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
  1291. return result;
  1292. }
  1293. namespace BOOST_REGEX_DETAIL_NS{
  1294. class unicode_string_out_iterator
  1295. {
  1296. U_NAMESPACE_QUALIFIER UnicodeString* out;
  1297. public:
  1298. unicode_string_out_iterator(U_NAMESPACE_QUALIFIER UnicodeString& s) : out(&s) {}
  1299. unicode_string_out_iterator& operator++() { return *this; }
  1300. unicode_string_out_iterator& operator++(int) { return *this; }
  1301. unicode_string_out_iterator& operator*() { return *this; }
  1302. unicode_string_out_iterator& operator=(UChar v)
  1303. {
  1304. *out += v;
  1305. return *this;
  1306. }
  1307. typedef std::ptrdiff_t difference_type;
  1308. typedef UChar value_type;
  1309. typedef value_type* pointer;
  1310. typedef value_type& reference;
  1311. typedef std::output_iterator_tag iterator_category;
  1312. };
  1313. }
  1314. inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
  1315. const u32regex& e,
  1316. const UChar* fmt,
  1317. match_flag_type flags = match_default)
  1318. {
  1319. U_NAMESPACE_QUALIFIER UnicodeString result;
  1320. BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
  1321. u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
  1322. return result;
  1323. }
  1324. inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
  1325. const u32regex& e,
  1326. const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
  1327. match_flag_type flags = match_default)
  1328. {
  1329. U_NAMESPACE_QUALIFIER UnicodeString result;
  1330. BOOST_REGEX_DETAIL_NS::unicode_string_out_iterator i(result);
  1331. BOOST_REGEX_DETAIL_NS::do_regex_replace(
  1332. BOOST_REGEX_DETAIL_NS::make_utf32_out(i, static_cast<std::integral_constant<int, 2> const*>(0)),
  1333. BOOST_REGEX_DETAIL_NS::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<std::integral_constant<int, 2> const*>(0)),
  1334. e,
  1335. BOOST_REGEX_DETAIL_NS::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<std::integral_constant<int, 2> const*>(0)),
  1336. flags);
  1337. return result;
  1338. }
  1339. } // namespace boost.
  1340. #ifdef BOOST_REGEX_MSVC
  1341. #pragma warning (pop)
  1342. #endif
  1343. #include <boost/regex/v5/u32regex_iterator.hpp>
  1344. #include <boost/regex/v5/u32regex_token_iterator.hpp>
  1345. #endif