regex_traits_defaults.hpp 38 KB

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