icu.hpp 60 KB

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