regex_traits_defaults.hpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  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 regex_traits_defaults.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Declares API's for access to regex_traits default properties.
  16. */
  17. #ifndef BOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED
  18. #define BOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED
  19. #include <boost/regex/config.hpp>
  20. #include <boost/regex/v5/syntax_type.hpp>
  21. #include <boost/regex/v5/error_type.hpp>
  22. #include <boost/regex/v5/regex_workaround.hpp>
  23. #include <type_traits>
  24. #include <cstdint>
  25. #include <cctype>
  26. #include <locale>
  27. #include <cwctype>
  28. #include <limits>
  29. namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
  30. //
  31. // helpers to suppress warnings:
  32. //
  33. template <class charT>
  34. inline bool is_extended(charT c)
  35. {
  36. typedef typename std::make_unsigned<charT>::type unsigned_type;
  37. return (sizeof(charT) > 1) && (static_cast<unsigned_type>(c) >= 256u);
  38. }
  39. inline bool is_extended(char)
  40. { return false; }
  41. inline const char* get_default_syntax(regex_constants::syntax_type n)
  42. {
  43. // if the user hasn't supplied a message catalog, then this supplies
  44. // default "messages" for us to load in the range 1-100.
  45. const char* messages[] = {
  46. "",
  47. "(",
  48. ")",
  49. "$",
  50. "^",
  51. ".",
  52. "*",
  53. "+",
  54. "?",
  55. "[",
  56. "]",
  57. "|",
  58. "\\",
  59. "#",
  60. "-",
  61. "{",
  62. "}",
  63. "0123456789",
  64. "b",
  65. "B",
  66. "<",
  67. ">",
  68. "",
  69. "",
  70. "A`",
  71. "z'",
  72. "\n",
  73. ",",
  74. "a",
  75. "f",
  76. "n",
  77. "r",
  78. "t",
  79. "v",
  80. "x",
  81. "c",
  82. ":",
  83. "=",
  84. "e",
  85. "",
  86. "",
  87. "",
  88. "",
  89. "",
  90. "",
  91. "",
  92. "",
  93. "E",
  94. "Q",
  95. "X",
  96. "C",
  97. "Z",
  98. "G",
  99. "!",
  100. "p",
  101. "P",
  102. "N",
  103. "gk",
  104. "K",
  105. "R",
  106. };
  107. return ((n >= (sizeof(messages) / sizeof(messages[1]))) ? "" : messages[n]);
  108. }
  109. inline const char* get_default_error_string(regex_constants::error_type n)
  110. {
  111. static const char* const s_default_error_messages[] = {
  112. "Success", /* REG_NOERROR 0 error_ok */
  113. "No match", /* REG_NOMATCH 1 error_no_match */
  114. "Invalid regular expression.", /* REG_BADPAT 2 error_bad_pattern */
  115. "Invalid collation character.", /* REG_ECOLLATE 3 error_collate */
  116. "Invalid character class name, collating name, or character range.", /* REG_ECTYPE 4 error_ctype */
  117. "Invalid or unterminated escape sequence.", /* REG_EESCAPE 5 error_escape */
  118. "Invalid back reference: specified capturing group does not exist.", /* REG_ESUBREG 6 error_backref */
  119. "Unmatched [ or [^ in character class declaration.", /* REG_EBRACK 7 error_brack */
  120. "Unmatched marking parenthesis ( or \\(.", /* REG_EPAREN 8 error_paren */
  121. "Unmatched quantified repeat operator { or \\{.", /* REG_EBRACE 9 error_brace */
  122. "Invalid content of repeat range.", /* REG_BADBR 10 error_badbrace */
  123. "Invalid range end in character class", /* REG_ERANGE 11 error_range */
  124. "Out of memory.", /* REG_ESPACE 12 error_space NOT USED */
  125. "Invalid preceding regular expression prior to repetition operator.", /* REG_BADRPT 13 error_badrepeat */
  126. "Premature end of regular expression", /* REG_EEND 14 error_end NOT USED */
  127. "Regular expression is too large.", /* REG_ESIZE 15 error_size NOT USED */
  128. "Unmatched ) or \\)", /* REG_ERPAREN 16 error_right_paren NOT USED */
  129. "Empty regular expression.", /* REG_EMPTY 17 error_empty */
  130. "The complexity of matching the regular expression exceeded predefined bounds. "
  131. "Try refactoring the regular expression to make each choice made by the state machine unambiguous. "
  132. "This exception is thrown to prevent \"eternal\" matches that take an "
  133. "indefinite period time to locate.", /* REG_ECOMPLEXITY 18 error_complexity */
  134. "Ran out of stack space trying to match the regular expression.", /* REG_ESTACK 19 error_stack */
  135. "Invalid or unterminated Perl (?...) sequence.", /* REG_E_PERL 20 error_perl */
  136. "Unknown error.", /* REG_E_UNKNOWN 21 error_unknown */
  137. };
  138. return (n > ::boost::regex_constants::error_unknown) ? s_default_error_messages[::boost::regex_constants::error_unknown] : s_default_error_messages[n];
  139. }
  140. inline regex_constants::syntax_type get_default_syntax_type(char c)
  141. {
  142. //
  143. // char_syntax determines how the compiler treats a given character
  144. // in a regular expression.
  145. //
  146. static regex_constants::syntax_type char_syntax[] = {
  147. regex_constants::syntax_char, /**/
  148. regex_constants::syntax_char, /**/
  149. regex_constants::syntax_char, /**/
  150. regex_constants::syntax_char, /**/
  151. regex_constants::syntax_char, /**/
  152. regex_constants::syntax_char, /**/
  153. regex_constants::syntax_char, /**/
  154. regex_constants::syntax_char, /**/
  155. regex_constants::syntax_char, /**/
  156. regex_constants::syntax_char, /**/
  157. regex_constants::syntax_newline, /**/
  158. regex_constants::syntax_char, /**/
  159. regex_constants::syntax_char, /**/
  160. regex_constants::syntax_char, /**/
  161. regex_constants::syntax_char, /**/
  162. regex_constants::syntax_char, /**/
  163. regex_constants::syntax_char, /**/
  164. regex_constants::syntax_char, /**/
  165. regex_constants::syntax_char, /**/
  166. regex_constants::syntax_char, /**/
  167. regex_constants::syntax_char, /**/
  168. regex_constants::syntax_char, /**/
  169. regex_constants::syntax_char, /**/
  170. regex_constants::syntax_char, /**/
  171. regex_constants::syntax_char, /**/
  172. regex_constants::syntax_char, /**/
  173. regex_constants::syntax_char, /**/
  174. regex_constants::syntax_char, /**/
  175. regex_constants::syntax_char, /**/
  176. regex_constants::syntax_char, /**/
  177. regex_constants::syntax_char, /**/
  178. regex_constants::syntax_char, /**/
  179. regex_constants::syntax_char, /* */ // 32
  180. regex_constants::syntax_not, /*!*/
  181. regex_constants::syntax_char, /*"*/
  182. regex_constants::syntax_hash, /*#*/
  183. regex_constants::syntax_dollar, /*$*/
  184. regex_constants::syntax_char, /*%*/
  185. regex_constants::syntax_char, /*&*/
  186. regex_constants::escape_type_end_buffer, /*'*/
  187. regex_constants::syntax_open_mark, /*(*/
  188. regex_constants::syntax_close_mark, /*)*/
  189. regex_constants::syntax_star, /***/
  190. regex_constants::syntax_plus, /*+*/
  191. regex_constants::syntax_comma, /*,*/
  192. regex_constants::syntax_dash, /*-*/
  193. regex_constants::syntax_dot, /*.*/
  194. regex_constants::syntax_char, /*/*/
  195. regex_constants::syntax_digit, /*0*/
  196. regex_constants::syntax_digit, /*1*/
  197. regex_constants::syntax_digit, /*2*/
  198. regex_constants::syntax_digit, /*3*/
  199. regex_constants::syntax_digit, /*4*/
  200. regex_constants::syntax_digit, /*5*/
  201. regex_constants::syntax_digit, /*6*/
  202. regex_constants::syntax_digit, /*7*/
  203. regex_constants::syntax_digit, /*8*/
  204. regex_constants::syntax_digit, /*9*/
  205. regex_constants::syntax_colon, /*:*/
  206. regex_constants::syntax_char, /*;*/
  207. regex_constants::escape_type_left_word, /*<*/
  208. regex_constants::syntax_equal, /*=*/
  209. regex_constants::escape_type_right_word, /*>*/
  210. regex_constants::syntax_question, /*?*/
  211. regex_constants::syntax_char, /*@*/
  212. regex_constants::syntax_char, /*A*/
  213. regex_constants::syntax_char, /*B*/
  214. regex_constants::syntax_char, /*C*/
  215. regex_constants::syntax_char, /*D*/
  216. regex_constants::syntax_char, /*E*/
  217. regex_constants::syntax_char, /*F*/
  218. regex_constants::syntax_char, /*G*/
  219. regex_constants::syntax_char, /*H*/
  220. regex_constants::syntax_char, /*I*/
  221. regex_constants::syntax_char, /*J*/
  222. regex_constants::syntax_char, /*K*/
  223. regex_constants::syntax_char, /*L*/
  224. regex_constants::syntax_char, /*M*/
  225. regex_constants::syntax_char, /*N*/
  226. regex_constants::syntax_char, /*O*/
  227. regex_constants::syntax_char, /*P*/
  228. regex_constants::syntax_char, /*Q*/
  229. regex_constants::syntax_char, /*R*/
  230. regex_constants::syntax_char, /*S*/
  231. regex_constants::syntax_char, /*T*/
  232. regex_constants::syntax_char, /*U*/
  233. regex_constants::syntax_char, /*V*/
  234. regex_constants::syntax_char, /*W*/
  235. regex_constants::syntax_char, /*X*/
  236. regex_constants::syntax_char, /*Y*/
  237. regex_constants::syntax_char, /*Z*/
  238. regex_constants::syntax_open_set, /*[*/
  239. regex_constants::syntax_escape, /*\*/
  240. regex_constants::syntax_close_set, /*]*/
  241. regex_constants::syntax_caret, /*^*/
  242. regex_constants::syntax_char, /*_*/
  243. regex_constants::syntax_char, /*`*/
  244. regex_constants::syntax_char, /*a*/
  245. regex_constants::syntax_char, /*b*/
  246. regex_constants::syntax_char, /*c*/
  247. regex_constants::syntax_char, /*d*/
  248. regex_constants::syntax_char, /*e*/
  249. regex_constants::syntax_char, /*f*/
  250. regex_constants::syntax_char, /*g*/
  251. regex_constants::syntax_char, /*h*/
  252. regex_constants::syntax_char, /*i*/
  253. regex_constants::syntax_char, /*j*/
  254. regex_constants::syntax_char, /*k*/
  255. regex_constants::syntax_char, /*l*/
  256. regex_constants::syntax_char, /*m*/
  257. regex_constants::syntax_char, /*n*/
  258. regex_constants::syntax_char, /*o*/
  259. regex_constants::syntax_char, /*p*/
  260. regex_constants::syntax_char, /*q*/
  261. regex_constants::syntax_char, /*r*/
  262. regex_constants::syntax_char, /*s*/
  263. regex_constants::syntax_char, /*t*/
  264. regex_constants::syntax_char, /*u*/
  265. regex_constants::syntax_char, /*v*/
  266. regex_constants::syntax_char, /*w*/
  267. regex_constants::syntax_char, /*x*/
  268. regex_constants::syntax_char, /*y*/
  269. regex_constants::syntax_char, /*z*/
  270. regex_constants::syntax_open_brace, /*{*/
  271. regex_constants::syntax_or, /*|*/
  272. regex_constants::syntax_close_brace, /*}*/
  273. regex_constants::syntax_char, /*~*/
  274. regex_constants::syntax_char, /**/
  275. regex_constants::syntax_char, /**/
  276. regex_constants::syntax_char, /**/
  277. regex_constants::syntax_char, /**/
  278. regex_constants::syntax_char, /**/
  279. regex_constants::syntax_char, /**/
  280. regex_constants::syntax_char, /**/
  281. regex_constants::syntax_char, /**/
  282. regex_constants::syntax_char, /**/
  283. regex_constants::syntax_char, /**/
  284. regex_constants::syntax_char, /**/
  285. regex_constants::syntax_char, /**/
  286. regex_constants::syntax_char, /**/
  287. regex_constants::syntax_char, /**/
  288. regex_constants::syntax_char, /**/
  289. regex_constants::syntax_char, /**/
  290. regex_constants::syntax_char, /**/
  291. regex_constants::syntax_char, /**/
  292. regex_constants::syntax_char, /**/
  293. regex_constants::syntax_char, /**/
  294. regex_constants::syntax_char, /**/
  295. regex_constants::syntax_char, /**/
  296. regex_constants::syntax_char, /**/
  297. regex_constants::syntax_char, /**/
  298. regex_constants::syntax_char, /**/
  299. regex_constants::syntax_char, /**/
  300. regex_constants::syntax_char, /**/
  301. regex_constants::syntax_char, /**/
  302. regex_constants::syntax_char, /**/
  303. regex_constants::syntax_char, /**/
  304. regex_constants::syntax_char, /**/
  305. regex_constants::syntax_char, /**/
  306. regex_constants::syntax_char, /**/
  307. regex_constants::syntax_char, /**/
  308. regex_constants::syntax_char, /**/
  309. regex_constants::syntax_char, /**/
  310. regex_constants::syntax_char, /**/
  311. regex_constants::syntax_char, /**/
  312. regex_constants::syntax_char, /**/
  313. regex_constants::syntax_char, /**/
  314. regex_constants::syntax_char, /**/
  315. regex_constants::syntax_char, /**/
  316. regex_constants::syntax_char, /**/
  317. regex_constants::syntax_char, /**/
  318. regex_constants::syntax_char, /**/
  319. regex_constants::syntax_char, /**/
  320. regex_constants::syntax_char, /**/
  321. regex_constants::syntax_char, /**/
  322. regex_constants::syntax_char, /**/
  323. regex_constants::syntax_char, /**/
  324. regex_constants::syntax_char, /**/
  325. regex_constants::syntax_char, /**/
  326. regex_constants::syntax_char, /**/
  327. regex_constants::syntax_char, /**/
  328. regex_constants::syntax_char, /**/
  329. regex_constants::syntax_char, /**/
  330. };
  331. return char_syntax[(unsigned char)c];
  332. }
  333. inline regex_constants::escape_syntax_type get_default_escape_syntax_type(char c)
  334. {
  335. //
  336. // char_syntax determines how the compiler treats a given character
  337. // in a regular expression.
  338. //
  339. static regex_constants::escape_syntax_type char_syntax[] = {
  340. regex_constants::escape_type_identity, /**/
  341. regex_constants::escape_type_identity, /**/
  342. regex_constants::escape_type_identity, /**/
  343. regex_constants::escape_type_identity, /**/
  344. regex_constants::escape_type_identity, /**/
  345. regex_constants::escape_type_identity, /**/
  346. regex_constants::escape_type_identity, /**/
  347. regex_constants::escape_type_identity, /**/
  348. regex_constants::escape_type_identity, /**/
  349. regex_constants::escape_type_identity, /**/
  350. regex_constants::escape_type_identity, /**/
  351. regex_constants::escape_type_identity, /**/
  352. regex_constants::escape_type_identity, /**/
  353. regex_constants::escape_type_identity, /**/
  354. regex_constants::escape_type_identity, /**/
  355. regex_constants::escape_type_identity, /**/
  356. regex_constants::escape_type_identity, /**/
  357. regex_constants::escape_type_identity, /**/
  358. regex_constants::escape_type_identity, /**/
  359. regex_constants::escape_type_identity, /**/
  360. regex_constants::escape_type_identity, /**/
  361. regex_constants::escape_type_identity, /**/
  362. regex_constants::escape_type_identity, /**/
  363. regex_constants::escape_type_identity, /**/
  364. regex_constants::escape_type_identity, /**/
  365. regex_constants::escape_type_identity, /**/
  366. regex_constants::escape_type_identity, /**/
  367. regex_constants::escape_type_identity, /**/
  368. regex_constants::escape_type_identity, /**/
  369. regex_constants::escape_type_identity, /**/
  370. regex_constants::escape_type_identity, /**/
  371. regex_constants::escape_type_identity, /**/
  372. regex_constants::escape_type_identity, /* */ // 32
  373. regex_constants::escape_type_identity, /*!*/
  374. regex_constants::escape_type_identity, /*"*/
  375. regex_constants::escape_type_identity, /*#*/
  376. regex_constants::escape_type_identity, /*$*/
  377. regex_constants::escape_type_identity, /*%*/
  378. regex_constants::escape_type_identity, /*&*/
  379. regex_constants::escape_type_end_buffer, /*'*/
  380. regex_constants::syntax_open_mark, /*(*/
  381. regex_constants::syntax_close_mark, /*)*/
  382. regex_constants::escape_type_identity, /***/
  383. regex_constants::syntax_plus, /*+*/
  384. regex_constants::escape_type_identity, /*,*/
  385. regex_constants::escape_type_identity, /*-*/
  386. regex_constants::escape_type_identity, /*.*/
  387. regex_constants::escape_type_identity, /*/*/
  388. regex_constants::escape_type_decimal, /*0*/
  389. regex_constants::escape_type_backref, /*1*/
  390. regex_constants::escape_type_backref, /*2*/
  391. regex_constants::escape_type_backref, /*3*/
  392. regex_constants::escape_type_backref, /*4*/
  393. regex_constants::escape_type_backref, /*5*/
  394. regex_constants::escape_type_backref, /*6*/
  395. regex_constants::escape_type_backref, /*7*/
  396. regex_constants::escape_type_backref, /*8*/
  397. regex_constants::escape_type_backref, /*9*/
  398. regex_constants::escape_type_identity, /*:*/
  399. regex_constants::escape_type_identity, /*;*/
  400. regex_constants::escape_type_left_word, /*<*/
  401. regex_constants::escape_type_identity, /*=*/
  402. regex_constants::escape_type_right_word, /*>*/
  403. regex_constants::syntax_question, /*?*/
  404. regex_constants::escape_type_identity, /*@*/
  405. regex_constants::escape_type_start_buffer, /*A*/
  406. regex_constants::escape_type_not_word_assert, /*B*/
  407. regex_constants::escape_type_C, /*C*/
  408. regex_constants::escape_type_not_class, /*D*/
  409. regex_constants::escape_type_E, /*E*/
  410. regex_constants::escape_type_not_class, /*F*/
  411. regex_constants::escape_type_G, /*G*/
  412. regex_constants::escape_type_not_class, /*H*/
  413. regex_constants::escape_type_not_class, /*I*/
  414. regex_constants::escape_type_not_class, /*J*/
  415. regex_constants::escape_type_reset_start_mark, /*K*/
  416. regex_constants::escape_type_not_class, /*L*/
  417. regex_constants::escape_type_not_class, /*M*/
  418. regex_constants::escape_type_named_char, /*N*/
  419. regex_constants::escape_type_not_class, /*O*/
  420. regex_constants::escape_type_not_property, /*P*/
  421. regex_constants::escape_type_Q, /*Q*/
  422. regex_constants::escape_type_line_ending, /*R*/
  423. regex_constants::escape_type_not_class, /*S*/
  424. regex_constants::escape_type_not_class, /*T*/
  425. regex_constants::escape_type_not_class, /*U*/
  426. regex_constants::escape_type_not_class, /*V*/
  427. regex_constants::escape_type_not_class, /*W*/
  428. regex_constants::escape_type_X, /*X*/
  429. regex_constants::escape_type_not_class, /*Y*/
  430. regex_constants::escape_type_Z, /*Z*/
  431. regex_constants::escape_type_identity, /*[*/
  432. regex_constants::escape_type_identity, /*\*/
  433. regex_constants::escape_type_identity, /*]*/
  434. regex_constants::escape_type_identity, /*^*/
  435. regex_constants::escape_type_identity, /*_*/
  436. regex_constants::escape_type_start_buffer, /*`*/
  437. regex_constants::escape_type_control_a, /*a*/
  438. regex_constants::escape_type_word_assert, /*b*/
  439. regex_constants::escape_type_ascii_control, /*c*/
  440. regex_constants::escape_type_class, /*d*/
  441. regex_constants::escape_type_e, /*e*/
  442. regex_constants::escape_type_control_f, /*f*/
  443. regex_constants::escape_type_extended_backref, /*g*/
  444. regex_constants::escape_type_class, /*h*/
  445. regex_constants::escape_type_class, /*i*/
  446. regex_constants::escape_type_class, /*j*/
  447. regex_constants::escape_type_extended_backref, /*k*/
  448. regex_constants::escape_type_class, /*l*/
  449. regex_constants::escape_type_class, /*m*/
  450. regex_constants::escape_type_control_n, /*n*/
  451. regex_constants::escape_type_class, /*o*/
  452. regex_constants::escape_type_property, /*p*/
  453. regex_constants::escape_type_class, /*q*/
  454. regex_constants::escape_type_control_r, /*r*/
  455. regex_constants::escape_type_class, /*s*/
  456. regex_constants::escape_type_control_t, /*t*/
  457. regex_constants::escape_type_class, /*u*/
  458. regex_constants::escape_type_control_v, /*v*/
  459. regex_constants::escape_type_class, /*w*/
  460. regex_constants::escape_type_hex, /*x*/
  461. regex_constants::escape_type_class, /*y*/
  462. regex_constants::escape_type_end_buffer, /*z*/
  463. regex_constants::syntax_open_brace, /*{*/
  464. regex_constants::syntax_or, /*|*/
  465. regex_constants::syntax_close_brace, /*}*/
  466. regex_constants::escape_type_identity, /*~*/
  467. regex_constants::escape_type_identity, /**/
  468. regex_constants::escape_type_identity, /**/
  469. regex_constants::escape_type_identity, /**/
  470. regex_constants::escape_type_identity, /**/
  471. regex_constants::escape_type_identity, /**/
  472. regex_constants::escape_type_identity, /**/
  473. regex_constants::escape_type_identity, /**/
  474. regex_constants::escape_type_identity, /**/
  475. regex_constants::escape_type_identity, /**/
  476. regex_constants::escape_type_identity, /**/
  477. regex_constants::escape_type_identity, /**/
  478. regex_constants::escape_type_identity, /**/
  479. regex_constants::escape_type_identity, /**/
  480. regex_constants::escape_type_identity, /**/
  481. regex_constants::escape_type_identity, /**/
  482. regex_constants::escape_type_identity, /**/
  483. regex_constants::escape_type_identity, /**/
  484. regex_constants::escape_type_identity, /**/
  485. regex_constants::escape_type_identity, /**/
  486. regex_constants::escape_type_identity, /**/
  487. regex_constants::escape_type_identity, /**/
  488. regex_constants::escape_type_identity, /**/
  489. regex_constants::escape_type_identity, /**/
  490. regex_constants::escape_type_identity, /**/
  491. regex_constants::escape_type_identity, /**/
  492. regex_constants::escape_type_identity, /**/
  493. regex_constants::escape_type_identity, /**/
  494. regex_constants::escape_type_identity, /**/
  495. regex_constants::escape_type_identity, /**/
  496. regex_constants::escape_type_identity, /**/
  497. regex_constants::escape_type_identity, /**/
  498. regex_constants::escape_type_identity, /**/
  499. regex_constants::escape_type_identity, /**/
  500. regex_constants::escape_type_identity, /**/
  501. regex_constants::escape_type_identity, /**/
  502. regex_constants::escape_type_identity, /**/
  503. regex_constants::escape_type_identity, /**/
  504. regex_constants::escape_type_identity, /**/
  505. regex_constants::escape_type_identity, /**/
  506. regex_constants::escape_type_identity, /**/
  507. regex_constants::escape_type_identity, /**/
  508. regex_constants::escape_type_identity, /**/
  509. regex_constants::escape_type_identity, /**/
  510. regex_constants::escape_type_identity, /**/
  511. regex_constants::escape_type_identity, /**/
  512. regex_constants::escape_type_identity, /**/
  513. regex_constants::escape_type_identity, /**/
  514. regex_constants::escape_type_identity, /**/
  515. regex_constants::escape_type_identity, /**/
  516. regex_constants::escape_type_identity, /**/
  517. regex_constants::escape_type_identity, /**/
  518. regex_constants::escape_type_identity, /**/
  519. regex_constants::escape_type_identity, /**/
  520. regex_constants::escape_type_identity, /**/
  521. regex_constants::escape_type_identity, /**/
  522. regex_constants::escape_type_identity, /**/
  523. };
  524. return char_syntax[(unsigned char)c];
  525. }
  526. // is charT c a combining character?
  527. inline bool is_combining_implementation(std::uint_least16_t c)
  528. {
  529. const std::uint_least16_t combining_ranges[] = { 0x0300, 0x0361,
  530. 0x0483, 0x0486,
  531. 0x0903, 0x0903,
  532. 0x093E, 0x0940,
  533. 0x0949, 0x094C,
  534. 0x0982, 0x0983,
  535. 0x09BE, 0x09C0,
  536. 0x09C7, 0x09CC,
  537. 0x09D7, 0x09D7,
  538. 0x0A3E, 0x0A40,
  539. 0x0A83, 0x0A83,
  540. 0x0ABE, 0x0AC0,
  541. 0x0AC9, 0x0ACC,
  542. 0x0B02, 0x0B03,
  543. 0x0B3E, 0x0B3E,
  544. 0x0B40, 0x0B40,
  545. 0x0B47, 0x0B4C,
  546. 0x0B57, 0x0B57,
  547. 0x0B83, 0x0B83,
  548. 0x0BBE, 0x0BBF,
  549. 0x0BC1, 0x0BCC,
  550. 0x0BD7, 0x0BD7,
  551. 0x0C01, 0x0C03,
  552. 0x0C41, 0x0C44,
  553. 0x0C82, 0x0C83,
  554. 0x0CBE, 0x0CBE,
  555. 0x0CC0, 0x0CC4,
  556. 0x0CC7, 0x0CCB,
  557. 0x0CD5, 0x0CD6,
  558. 0x0D02, 0x0D03,
  559. 0x0D3E, 0x0D40,
  560. 0x0D46, 0x0D4C,
  561. 0x0D57, 0x0D57,
  562. 0x0F7F, 0x0F7F,
  563. 0x20D0, 0x20E1,
  564. 0x3099, 0x309A,
  565. 0xFE20, 0xFE23,
  566. 0xffff, 0xffff, };
  567. const std::uint_least16_t* p = combining_ranges + 1;
  568. while (*p < c) p += 2;
  569. --p;
  570. if ((c >= *p) && (c <= *(p + 1)))
  571. return true;
  572. return false;
  573. }
  574. template <class charT>
  575. inline bool is_combining(charT c)
  576. {
  577. return (c <= static_cast<charT>(0)) ? false : ((c >= static_cast<charT>((std::numeric_limits<uint_least16_t>::max)())) ? false : is_combining_implementation(static_cast<unsigned short>(c)));
  578. }
  579. template <>
  580. inline bool is_combining<char>(char)
  581. {
  582. return false;
  583. }
  584. template <>
  585. inline bool is_combining<signed char>(signed char)
  586. {
  587. return false;
  588. }
  589. template <>
  590. inline bool is_combining<unsigned char>(unsigned char)
  591. {
  592. return false;
  593. }
  594. #ifdef _MSC_VER
  595. template<>
  596. inline bool is_combining<wchar_t>(wchar_t c)
  597. {
  598. return is_combining_implementation(static_cast<unsigned short>(c));
  599. }
  600. #elif !defined(__DECCXX) && !defined(__osf__) && !defined(__OSF__) && defined(WCHAR_MIN) && (WCHAR_MIN == 0) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
  601. #if defined(WCHAR_MAX) && (WCHAR_MAX <= USHRT_MAX)
  602. template<>
  603. inline bool is_combining<wchar_t>(wchar_t c)
  604. {
  605. return is_combining_implementation(static_cast<unsigned short>(c));
  606. }
  607. #else
  608. template<>
  609. inline bool is_combining<wchar_t>(wchar_t c)
  610. {
  611. return (c >= (std::numeric_limits<uint_least16_t>::max)()) ? false : is_combining_implementation(static_cast<unsigned short>(c));
  612. }
  613. #endif
  614. #endif
  615. //
  616. // is a charT c a line separator?
  617. //
  618. template <class charT>
  619. inline bool is_separator(charT c)
  620. {
  621. return BOOST_REGEX_MAKE_BOOL(
  622. (c == static_cast<charT>('\n'))
  623. || (c == static_cast<charT>('\r'))
  624. || (c == static_cast<charT>('\f'))
  625. || (static_cast<std::uint16_t>(c) == 0x2028u)
  626. || (static_cast<std::uint16_t>(c) == 0x2029u)
  627. || (static_cast<std::uint16_t>(c) == 0x85u));
  628. }
  629. template <>
  630. inline bool is_separator<char>(char c)
  631. {
  632. return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r') || (c == '\f'));
  633. }
  634. //
  635. // get a default collating element:
  636. //
  637. inline std::string lookup_default_collate_name(const std::string& name)
  638. {
  639. //
  640. // these are the POSIX collating names:
  641. //
  642. static const char* def_coll_names[] = {
  643. "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "alert", "backspace", "tab", "newline",
  644. "vertical-tab", "form-feed", "carriage-return", "SO", "SI", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK",
  645. "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "IS4", "IS3", "IS2", "IS1", "space", "exclamation-mark",
  646. "quotation-mark", "number-sign", "dollar-sign", "percent-sign", "ampersand", "apostrophe",
  647. "left-parenthesis", "right-parenthesis", "asterisk", "plus-sign", "comma", "hyphen",
  648. "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
  649. "colon", "semicolon", "less-than-sign", "equals-sign", "greater-than-sign",
  650. "question-mark", "commercial-at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
  651. "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "left-square-bracket", "backslash",
  652. "right-square-bracket", "circumflex", "underscore", "grave-accent", "a", "b", "c", "d", "e", "f",
  653. "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "left-curly-bracket",
  654. "vertical-line", "right-curly-bracket", "tilde", "DEL", "",
  655. };
  656. // these multi-character collating elements
  657. // should keep most Western-European locales
  658. // happy - we should really localise these a
  659. // little more - but this will have to do for
  660. // now:
  661. static const char* def_multi_coll[] = {
  662. "ae",
  663. "Ae",
  664. "AE",
  665. "ch",
  666. "Ch",
  667. "CH",
  668. "ll",
  669. "Ll",
  670. "LL",
  671. "ss",
  672. "Ss",
  673. "SS",
  674. "nj",
  675. "Nj",
  676. "NJ",
  677. "dz",
  678. "Dz",
  679. "DZ",
  680. "lj",
  681. "Lj",
  682. "LJ",
  683. "",
  684. };
  685. unsigned int i = 0;
  686. while (*def_coll_names[i])
  687. {
  688. if (def_coll_names[i] == name)
  689. {
  690. return std::string(1, char(i));
  691. }
  692. ++i;
  693. }
  694. i = 0;
  695. while (*def_multi_coll[i])
  696. {
  697. if (def_multi_coll[i] == name)
  698. {
  699. return def_multi_coll[i];
  700. }
  701. ++i;
  702. }
  703. return std::string();
  704. }
  705. //
  706. // get the state_id of a character classification, the individual
  707. // traits classes then transform that state_id into a bitmask:
  708. //
  709. template <class charT>
  710. struct character_pointer_range
  711. {
  712. const charT* p1;
  713. const charT* p2;
  714. bool operator < (const character_pointer_range& r)const
  715. {
  716. return std::lexicographical_compare(p1, p2, r.p1, r.p2);
  717. }
  718. bool operator == (const character_pointer_range& r)const
  719. {
  720. // Not only do we check that the ranges are of equal size before
  721. // calling std::equal, but there is no other algorithm available:
  722. // not even a non-standard MS one. So forward to unchecked_equal
  723. // in the MS case.
  724. #ifdef __cpp_lib_robust_nonmodifying_seq_ops
  725. return std::equal(p1, p2, r.p1, r.p2);
  726. #elif defined(BOOST_REGEX_MSVC)
  727. if (((p2 - p1) != (r.p2 - r.p1)))
  728. return false;
  729. const charT* with = r.p1;
  730. const charT* pos = p1;
  731. while (pos != p2)
  732. if (*pos++ != *with++) return false;
  733. return true;
  734. #else
  735. return ((p2 - p1) == (r.p2 - r.p1)) && std::equal(p1, p2, r.p1);
  736. #endif
  737. }
  738. };
  739. template <class charT>
  740. int get_default_class_id(const charT* p1, const charT* p2)
  741. {
  742. static const charT data[73] = {
  743. 'a', 'l', 'n', 'u', 'm',
  744. 'a', 'l', 'p', 'h', 'a',
  745. 'b', 'l', 'a', 'n', 'k',
  746. 'c', 'n', 't', 'r', 'l',
  747. 'd', 'i', 'g', 'i', 't',
  748. 'g', 'r', 'a', 'p', 'h',
  749. 'l', 'o', 'w', 'e', 'r',
  750. 'p', 'r', 'i', 'n', 't',
  751. 'p', 'u', 'n', 'c', 't',
  752. 's', 'p', 'a', 'c', 'e',
  753. 'u', 'n', 'i', 'c', 'o', 'd', 'e',
  754. 'u', 'p', 'p', 'e', 'r',
  755. 'v',
  756. 'w', 'o', 'r', 'd',
  757. 'x', 'd', 'i', 'g', 'i', 't',
  758. };
  759. static const character_pointer_range<charT> ranges[21] =
  760. {
  761. {data+0, data+5,}, // alnum
  762. {data+5, data+10,}, // alpha
  763. {data+10, data+15,}, // blank
  764. {data+15, data+20,}, // cntrl
  765. {data+20, data+21,}, // d
  766. {data+20, data+25,}, // digit
  767. {data+25, data+30,}, // graph
  768. {data+29, data+30,}, // h
  769. {data+30, data+31,}, // l
  770. {data+30, data+35,}, // lower
  771. {data+35, data+40,}, // print
  772. {data+40, data+45,}, // punct
  773. {data+45, data+46,}, // s
  774. {data+45, data+50,}, // space
  775. {data+57, data+58,}, // u
  776. {data+50, data+57,}, // unicode
  777. {data+57, data+62,}, // upper
  778. {data+62, data+63,}, // v
  779. {data+63, data+64,}, // w
  780. {data+63, data+67,}, // word
  781. {data+67, data+73,}, // xdigit
  782. };
  783. const character_pointer_range<charT>* ranges_begin = ranges;
  784. const character_pointer_range<charT>* ranges_end = ranges + (sizeof(ranges)/sizeof(ranges[0]));
  785. character_pointer_range<charT> t = { p1, p2, };
  786. const character_pointer_range<charT>* p = std::lower_bound(ranges_begin, ranges_end, t);
  787. if((p != ranges_end) && (t == *p))
  788. return static_cast<int>(p - ranges);
  789. return -1;
  790. }
  791. //
  792. // helper functions:
  793. //
  794. template <class charT>
  795. std::ptrdiff_t global_length(const charT* p)
  796. {
  797. std::ptrdiff_t n = 0;
  798. while(*p)
  799. {
  800. ++p;
  801. ++n;
  802. }
  803. return n;
  804. }
  805. template<>
  806. inline std::ptrdiff_t global_length<char>(const char* p)
  807. {
  808. return (std::strlen)(p);
  809. }
  810. #ifndef BOOST_NO_WREGEX
  811. template<>
  812. inline std::ptrdiff_t global_length<wchar_t>(const wchar_t* p)
  813. {
  814. return (std::ptrdiff_t)(std::wcslen)(p);
  815. }
  816. #endif
  817. template <class charT>
  818. inline charT global_lower(charT c)
  819. {
  820. return c;
  821. }
  822. template <class charT>
  823. inline charT global_upper(charT c)
  824. {
  825. return c;
  826. }
  827. inline char do_global_lower(char c)
  828. {
  829. return static_cast<char>((std::tolower)((unsigned char)c));
  830. }
  831. inline char do_global_upper(char c)
  832. {
  833. return static_cast<char>((std::toupper)((unsigned char)c));
  834. }
  835. #ifndef BOOST_NO_WREGEX
  836. inline wchar_t do_global_lower(wchar_t c)
  837. {
  838. return (std::towlower)(c);
  839. }
  840. inline wchar_t do_global_upper(wchar_t c)
  841. {
  842. return (std::towupper)(c);
  843. }
  844. #endif
  845. //
  846. // This sucks: declare template specialisations of global_lower/global_upper
  847. // that just forward to the non-template implementation functions. We do
  848. // this because there is one compiler (Compaq Tru64 C++) that doesn't seem
  849. // to differentiate between templates and non-template overloads....
  850. // what's more, the primary template, plus all overloads have to be
  851. // defined in the same translation unit (if one is inline they all must be)
  852. // otherwise the "local template instantiation" compiler option can pick
  853. // the wrong instantiation when linking:
  854. //
  855. template<> inline char global_lower<char>(char c) { return do_global_lower(c); }
  856. template<> inline char global_upper<char>(char c) { return do_global_upper(c); }
  857. #ifndef BOOST_NO_WREGEX
  858. template<> inline wchar_t global_lower<wchar_t>(wchar_t c) { return do_global_lower(c); }
  859. template<> inline wchar_t global_upper<wchar_t>(wchar_t c) { return do_global_upper(c); }
  860. #endif
  861. template <class charT>
  862. int global_value(charT c)
  863. {
  864. static const charT zero = '0';
  865. static const charT nine = '9';
  866. static const charT a = 'a';
  867. static const charT f = 'f';
  868. static const charT A = 'A';
  869. static const charT F = 'F';
  870. if(c > f) return -1;
  871. if(c >= a) return 10 + (c - a);
  872. if(c > F) return -1;
  873. if(c >= A) return 10 + (c - A);
  874. if(c > nine) return -1;
  875. if(c >= zero) return c - zero;
  876. return -1;
  877. }
  878. template <class charT, class traits>
  879. std::intmax_t global_toi(const charT*& p1, const charT* p2, int radix, const traits& t)
  880. {
  881. (void)t; // warning suppression
  882. std::intmax_t limit = (std::numeric_limits<std::intmax_t>::max)() / radix;
  883. std::intmax_t next_value = t.value(*p1, radix);
  884. if((p1 == p2) || (next_value < 0) || (next_value >= radix))
  885. return -1;
  886. std::intmax_t result = 0;
  887. while(p1 != p2)
  888. {
  889. next_value = t.value(*p1, radix);
  890. if((next_value < 0) || (next_value >= radix))
  891. break;
  892. result *= radix;
  893. result += next_value;
  894. ++p1;
  895. if (result > limit)
  896. return -1;
  897. }
  898. return result;
  899. }
  900. template <class charT>
  901. inline typename std::enable_if<(sizeof(charT) > 1), const charT*>::type get_escape_R_string()
  902. {
  903. #ifdef BOOST_REGEX_MSVC
  904. # pragma warning(push)
  905. # pragma warning(disable:4309 4245)
  906. #endif
  907. static const charT e1[] = { '(', '?', '-', 'x', ':', '(', '?', '>', '\x0D', '\x0A', '?',
  908. '|', '[', '\x0A', '\x0B', '\x0C', static_cast<charT>(0x85), static_cast<charT>(0x2028),
  909. static_cast<charT>(0x2029), ']', ')', ')', '\0' };
  910. static const charT e2[] = { '(', '?', '-', 'x', ':', '(', '?', '>', '\x0D', '\x0A', '?',
  911. '|', '[', '\x0A', '\x0B', '\x0C', static_cast<charT>(0x85), ']', ')', ')', '\0' };
  912. charT c = static_cast<charT>(0x2029u);
  913. bool b = (static_cast<unsigned>(c) == 0x2029u);
  914. return (b ? e1 : e2);
  915. #ifdef BOOST_REGEX_MSVC
  916. # pragma warning(pop)
  917. #endif
  918. }
  919. template <class charT>
  920. inline typename std::enable_if<(sizeof(charT) == 1), const charT*>::type get_escape_R_string()
  921. {
  922. #ifdef BOOST_REGEX_MSVC
  923. # pragma warning(push)
  924. # pragma warning(disable:4309 4245)
  925. #endif
  926. static const charT e2[] = {
  927. static_cast<charT>('('),
  928. static_cast<charT>('?'),
  929. static_cast<charT>('-'),
  930. static_cast<charT>('x'),
  931. static_cast<charT>(':'),
  932. static_cast<charT>('('),
  933. static_cast<charT>('?'),
  934. static_cast<charT>('>'),
  935. static_cast<charT>('\x0D'),
  936. static_cast<charT>('\x0A'),
  937. static_cast<charT>('?'),
  938. static_cast<charT>('|'),
  939. static_cast<charT>('['),
  940. static_cast<charT>('\x0A'),
  941. static_cast<charT>('\x0B'),
  942. static_cast<charT>('\x0C'),
  943. static_cast<charT>('\x85'),
  944. static_cast<charT>(']'),
  945. static_cast<charT>(')'),
  946. static_cast<charT>(')'),
  947. static_cast<charT>('\0')
  948. };
  949. return e2;
  950. #ifdef BOOST_REGEX_MSVC
  951. # pragma warning(pop)
  952. #endif
  953. }
  954. } // BOOST_REGEX_DETAIL_NS
  955. } // boost
  956. #endif