regex_format.hpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /*
  2. *
  3. * Copyright (c) 1998-2002
  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_format.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Provides formatting output routines for search and replace
  16. * operations. Note this is an internal header file included
  17. * by regex.hpp, do not include on its own.
  18. */
  19. #ifndef BOOST_REGEX_FORMAT_HPP
  20. #define BOOST_REGEX_FORMAT_HPP
  21. namespace boost{
  22. #ifdef BOOST_MSVC
  23. #pragma warning(push)
  24. #pragma warning(disable: 4103)
  25. #endif
  26. #ifdef BOOST_HAS_ABI_HEADERS
  27. # include BOOST_ABI_PREFIX
  28. #endif
  29. #ifdef BOOST_MSVC
  30. #pragma warning(pop)
  31. #endif
  32. //
  33. // Forward declaration:
  34. //
  35. template <class BidiIterator, class Allocator = BOOST_DEDUCED_TYPENAME std::vector<sub_match<BidiIterator> >::allocator_type >
  36. class match_results;
  37. namespace re_detail{
  38. //
  39. // struct trivial_format_traits:
  40. // defines minimum localisation support for formatting
  41. // in the case that the actual regex traits is unavailable.
  42. //
  43. template <class charT>
  44. struct trivial_format_traits
  45. {
  46. typedef charT char_type;
  47. static std::ptrdiff_t length(const charT* p)
  48. {
  49. return global_length(p);
  50. }
  51. static charT tolower(charT c)
  52. {
  53. return ::boost::re_detail::global_lower(c);
  54. }
  55. static charT toupper(charT c)
  56. {
  57. return ::boost::re_detail::global_upper(c);
  58. }
  59. static int value(const charT c, int radix)
  60. {
  61. int result = global_value(c);
  62. return result >= radix ? -1 : result;
  63. }
  64. int toi(const charT*& p1, const charT* p2, int radix)const
  65. {
  66. return global_toi(p1, p2, radix, *this);
  67. }
  68. };
  69. template <class OutputIterator, class Results, class traits>
  70. class basic_regex_formatter
  71. {
  72. public:
  73. typedef typename traits::char_type char_type;
  74. basic_regex_formatter(OutputIterator o, const Results& r, const traits& t)
  75. : m_traits(t), m_results(r), m_out(o), m_state(output_copy), m_restore_state(output_copy), m_have_conditional(false) {}
  76. OutputIterator format(const char_type* p1, const char_type* p2, match_flag_type f);
  77. OutputIterator format(const char_type* p1, match_flag_type f)
  78. {
  79. return format(p1, p1 + m_traits.length(p1), f);
  80. }
  81. private:
  82. typedef typename Results::value_type sub_match_type;
  83. enum output_state
  84. {
  85. output_copy,
  86. output_next_lower,
  87. output_next_upper,
  88. output_lower,
  89. output_upper,
  90. output_none
  91. };
  92. void put(char_type c);
  93. void put(const sub_match_type& sub);
  94. void format_all();
  95. void format_perl();
  96. void format_escape();
  97. void format_conditional();
  98. void format_until_scope_end();
  99. bool handle_perl_verb(bool have_brace);
  100. const traits& m_traits; // the traits class for localised formatting operations
  101. const Results& m_results; // the match_results being used.
  102. OutputIterator m_out; // where to send output.
  103. const char_type* m_position; // format string, current position
  104. const char_type* m_end; // format string end
  105. match_flag_type m_flags; // format flags to use
  106. output_state m_state; // what to do with the next character
  107. output_state m_restore_state; // what state to restore to.
  108. bool m_have_conditional; // we are parsing a conditional
  109. private:
  110. basic_regex_formatter(const basic_regex_formatter&);
  111. basic_regex_formatter& operator=(const basic_regex_formatter&);
  112. };
  113. template <class OutputIterator, class Results, class traits>
  114. OutputIterator basic_regex_formatter<OutputIterator, Results, traits>::format(const char_type* p1, const char_type* p2, match_flag_type f)
  115. {
  116. m_position = p1;
  117. m_end = p2;
  118. m_flags = f;
  119. format_all();
  120. return m_out;
  121. }
  122. template <class OutputIterator, class Results, class traits>
  123. void basic_regex_formatter<OutputIterator, Results, traits>::format_all()
  124. {
  125. // over and over:
  126. while(m_position != m_end)
  127. {
  128. switch(*m_position)
  129. {
  130. case '&':
  131. if(m_flags & ::boost::regex_constants::format_sed)
  132. {
  133. ++m_position;
  134. put(m_results[0]);
  135. break;
  136. }
  137. put(*m_position++);
  138. break;
  139. case '\\':
  140. format_escape();
  141. break;
  142. case '(':
  143. if(m_flags & boost::regex_constants::format_all)
  144. {
  145. ++m_position;
  146. bool have_conditional = m_have_conditional;
  147. m_have_conditional = false;
  148. format_until_scope_end();
  149. m_have_conditional = have_conditional;
  150. if(m_position == m_end)
  151. return;
  152. BOOST_ASSERT(*m_position == static_cast<char_type>(')'));
  153. ++m_position; // skip the closing ')'
  154. break;
  155. }
  156. put(*m_position);
  157. ++m_position;
  158. break;
  159. case ')':
  160. if(m_flags & boost::regex_constants::format_all)
  161. {
  162. return;
  163. }
  164. put(*m_position);
  165. ++m_position;
  166. break;
  167. case ':':
  168. if((m_flags & boost::regex_constants::format_all) && m_have_conditional)
  169. {
  170. return;
  171. }
  172. put(*m_position);
  173. ++m_position;
  174. break;
  175. case '?':
  176. if(m_flags & boost::regex_constants::format_all)
  177. {
  178. ++m_position;
  179. format_conditional();
  180. break;
  181. }
  182. put(*m_position);
  183. ++m_position;
  184. break;
  185. case '$':
  186. if((m_flags & format_sed) == 0)
  187. {
  188. format_perl();
  189. break;
  190. }
  191. // fall through, not a special character:
  192. default:
  193. put(*m_position);
  194. ++m_position;
  195. break;
  196. }
  197. }
  198. }
  199. template <class OutputIterator, class Results, class traits>
  200. void basic_regex_formatter<OutputIterator, Results, traits>::format_perl()
  201. {
  202. //
  203. // On entry *m_position points to a '$' character
  204. // output the information that goes with it:
  205. //
  206. BOOST_ASSERT(*m_position == '$');
  207. //
  208. // see if this is a trailing '$':
  209. //
  210. if(++m_position == m_end)
  211. {
  212. --m_position;
  213. put(*m_position);
  214. ++m_position;
  215. return;
  216. }
  217. //
  218. // OK find out what kind it is:
  219. //
  220. bool have_brace = false;
  221. const char_type* save_position = m_position;
  222. switch(*m_position)
  223. {
  224. case '&':
  225. ++m_position;
  226. put(this->m_results[0]);
  227. break;
  228. case '`':
  229. ++m_position;
  230. put(this->m_results.prefix());
  231. break;
  232. case '\'':
  233. ++m_position;
  234. put(this->m_results.suffix());
  235. break;
  236. case '$':
  237. put(*m_position++);
  238. break;
  239. case '+':
  240. if((++m_position != m_end) && (*m_position == '{'))
  241. {
  242. const char_type* base = ++m_position;
  243. while((m_position != m_end) && (*m_position != '}')) ++m_position;
  244. if(m_position != m_end)
  245. {
  246. // Named sub-expression:
  247. put(this->m_results.named_subexpression(base, m_position));
  248. ++m_position;
  249. break;
  250. }
  251. else
  252. {
  253. m_position = --base;
  254. }
  255. }
  256. put((this->m_results)[this->m_results.size() > 1 ? this->m_results.size() - 1 : 1]);
  257. break;
  258. case '{':
  259. have_brace = true;
  260. ++m_position;
  261. // fall through....
  262. default:
  263. // see if we have a number:
  264. {
  265. std::ptrdiff_t len = ::boost::re_detail::distance(m_position, m_end);
  266. //len = (std::min)(static_cast<std::ptrdiff_t>(2), len);
  267. int v = m_traits.toi(m_position, m_position + len, 10);
  268. if((v < 0) || (have_brace && ((m_position == m_end) || (*m_position != '}'))))
  269. {
  270. // Look for a Perl-5.10 verb:
  271. if(!handle_perl_verb(have_brace))
  272. {
  273. // leave the $ as is, and carry on:
  274. m_position = --save_position;
  275. put(*m_position);
  276. ++m_position;
  277. }
  278. break;
  279. }
  280. // otherwise output sub v:
  281. put(this->m_results[v]);
  282. if(have_brace)
  283. ++m_position;
  284. }
  285. }
  286. }
  287. template <class OutputIterator, class Results, class traits>
  288. bool basic_regex_formatter<OutputIterator, Results, traits>::handle_perl_verb(bool have_brace)
  289. {
  290. //
  291. // We may have a capitalised string containing a Perl action:
  292. //
  293. static const char_type MATCH[] = { 'M', 'A', 'T', 'C', 'H' };
  294. static const char_type PREMATCH[] = { 'P', 'R', 'E', 'M', 'A', 'T', 'C', 'H' };
  295. static const char_type POSTMATCH[] = { 'P', 'O', 'S', 'T', 'M', 'A', 'T', 'C', 'H' };
  296. static const char_type LAST_PAREN_MATCH[] = { 'L', 'A', 'S', 'T', '_', 'P', 'A', 'R', 'E', 'N', '_', 'M', 'A', 'T', 'C', 'H' };
  297. static const char_type LAST_SUBMATCH_RESULT[] = { 'L', 'A', 'S', 'T', '_', 'S', 'U', 'B', 'M', 'A', 'T', 'C', 'H', '_', 'R', 'E', 'S', 'U', 'L', 'T' };
  298. static const char_type LAST_SUBMATCH_RESULT_ALT[] = { '^', 'N' };
  299. if(have_brace && (*m_position == '^'))
  300. ++m_position;
  301. int max_len = m_end - m_position;
  302. if((max_len >= 5) && std::equal(m_position, m_position + 5, MATCH))
  303. {
  304. m_position += 5;
  305. if(have_brace)
  306. {
  307. if(*m_position == '}')
  308. ++m_position;
  309. else
  310. {
  311. m_position -= 5;
  312. return false;
  313. }
  314. }
  315. put(this->m_results[0]);
  316. return true;
  317. }
  318. if((max_len >= 8) && std::equal(m_position, m_position + 8, PREMATCH))
  319. {
  320. m_position += 8;
  321. if(have_brace)
  322. {
  323. if(*m_position == '}')
  324. ++m_position;
  325. else
  326. {
  327. m_position -= 8;
  328. return false;
  329. }
  330. }
  331. put(this->m_results.prefix());
  332. return true;
  333. }
  334. if((max_len >= 9) && std::equal(m_position, m_position + 9, POSTMATCH))
  335. {
  336. m_position += 9;
  337. if(have_brace)
  338. {
  339. if(*m_position == '}')
  340. ++m_position;
  341. else
  342. {
  343. m_position -= 9;
  344. return false;
  345. }
  346. }
  347. put(this->m_results.suffix());
  348. return true;
  349. }
  350. if((max_len >= 16) && std::equal(m_position, m_position + 16, LAST_PAREN_MATCH))
  351. {
  352. m_position += 16;
  353. if(have_brace)
  354. {
  355. if(*m_position == '}')
  356. ++m_position;
  357. else
  358. {
  359. m_position -= 16;
  360. return false;
  361. }
  362. }
  363. put((this->m_results)[this->m_results.size() > 1 ? this->m_results.size() - 1 : 1]);
  364. return true;
  365. }
  366. if((max_len >= 20) && std::equal(m_position, m_position + 20, LAST_SUBMATCH_RESULT))
  367. {
  368. m_position += 20;
  369. if(have_brace)
  370. {
  371. if(*m_position == '}')
  372. ++m_position;
  373. else
  374. {
  375. m_position -= 20;
  376. return false;
  377. }
  378. }
  379. put(this->m_results.get_last_closed_paren());
  380. return true;
  381. }
  382. if((max_len >= 2) && std::equal(m_position, m_position + 2, LAST_SUBMATCH_RESULT_ALT))
  383. {
  384. m_position += 2;
  385. if(have_brace)
  386. {
  387. if(*m_position == '}')
  388. ++m_position;
  389. else
  390. {
  391. m_position -= 2;
  392. return false;
  393. }
  394. }
  395. put(this->m_results.get_last_closed_paren());
  396. return true;
  397. }
  398. return false;
  399. }
  400. template <class OutputIterator, class Results, class traits>
  401. void basic_regex_formatter<OutputIterator, Results, traits>::format_escape()
  402. {
  403. // skip the escape and check for trailing escape:
  404. if(++m_position == m_end)
  405. {
  406. put(static_cast<char_type>('\\'));
  407. return;
  408. }
  409. // now switch on the escape type:
  410. switch(*m_position)
  411. {
  412. case 'a':
  413. put(static_cast<char_type>('\a'));
  414. ++m_position;
  415. break;
  416. case 'f':
  417. put(static_cast<char_type>('\f'));
  418. ++m_position;
  419. break;
  420. case 'n':
  421. put(static_cast<char_type>('\n'));
  422. ++m_position;
  423. break;
  424. case 'r':
  425. put(static_cast<char_type>('\r'));
  426. ++m_position;
  427. break;
  428. case 't':
  429. put(static_cast<char_type>('\t'));
  430. ++m_position;
  431. break;
  432. case 'v':
  433. put(static_cast<char_type>('\v'));
  434. ++m_position;
  435. break;
  436. case 'x':
  437. if(++m_position == m_end)
  438. {
  439. put(static_cast<char_type>('x'));
  440. return;
  441. }
  442. // maybe have \x{ddd}
  443. if(*m_position == static_cast<char_type>('{'))
  444. {
  445. ++m_position;
  446. int val = m_traits.toi(m_position, m_end, 16);
  447. if(val < 0)
  448. {
  449. // invalid value treat everything as literals:
  450. put(static_cast<char_type>('x'));
  451. put(static_cast<char_type>('{'));
  452. return;
  453. }
  454. if(*m_position != static_cast<char_type>('}'))
  455. {
  456. while(*m_position != static_cast<char_type>('\\'))
  457. --m_position;
  458. ++m_position;
  459. put(*m_position++);
  460. return;
  461. }
  462. ++m_position;
  463. put(static_cast<char_type>(val));
  464. return;
  465. }
  466. else
  467. {
  468. std::ptrdiff_t len = ::boost::re_detail::distance(m_position, m_end);
  469. len = (std::min)(static_cast<std::ptrdiff_t>(2), len);
  470. int val = m_traits.toi(m_position, m_position + len, 16);
  471. if(val < 0)
  472. {
  473. --m_position;
  474. put(*m_position++);
  475. return;
  476. }
  477. put(static_cast<char_type>(val));
  478. }
  479. break;
  480. case 'c':
  481. if(++m_position == m_end)
  482. {
  483. --m_position;
  484. put(*m_position++);
  485. return;
  486. }
  487. put(static_cast<char_type>(*m_position++ % 32));
  488. break;
  489. case 'e':
  490. put(static_cast<char_type>(27));
  491. ++m_position;
  492. break;
  493. default:
  494. // see if we have a perl specific escape:
  495. if((m_flags & boost::regex_constants::format_sed) == 0)
  496. {
  497. bool breakout = false;
  498. switch(*m_position)
  499. {
  500. case 'l':
  501. ++m_position;
  502. m_restore_state = m_state;
  503. m_state = output_next_lower;
  504. breakout = true;
  505. break;
  506. case 'L':
  507. ++m_position;
  508. m_state = output_lower;
  509. breakout = true;
  510. break;
  511. case 'u':
  512. ++m_position;
  513. m_restore_state = m_state;
  514. m_state = output_next_upper;
  515. breakout = true;
  516. break;
  517. case 'U':
  518. ++m_position;
  519. m_state = output_upper;
  520. breakout = true;
  521. break;
  522. case 'E':
  523. ++m_position;
  524. m_state = output_copy;
  525. breakout = true;
  526. break;
  527. }
  528. if(breakout)
  529. break;
  530. }
  531. // see if we have a \n sed style backreference:
  532. int v = m_traits.toi(m_position, m_position+1, 10);
  533. if((v > 0) || ((v == 0) && (m_flags & ::boost::regex_constants::format_sed)))
  534. {
  535. put(m_results[v]);
  536. break;
  537. }
  538. else if(v == 0)
  539. {
  540. // octal ecape sequence:
  541. --m_position;
  542. std::ptrdiff_t len = ::boost::re_detail::distance(m_position, m_end);
  543. len = (std::min)(static_cast<std::ptrdiff_t>(4), len);
  544. v = m_traits.toi(m_position, m_position + len, 8);
  545. BOOST_ASSERT(v >= 0);
  546. put(static_cast<char_type>(v));
  547. break;
  548. }
  549. // Otherwise output the character "as is":
  550. put(*m_position++);
  551. break;
  552. }
  553. }
  554. template <class OutputIterator, class Results, class traits>
  555. void basic_regex_formatter<OutputIterator, Results, traits>::format_conditional()
  556. {
  557. if(m_position == m_end)
  558. {
  559. // oops trailing '?':
  560. put(static_cast<char_type>('?'));
  561. return;
  562. }
  563. int v;
  564. if(*m_position == '{')
  565. {
  566. const char_type* base = m_position;
  567. ++m_position;
  568. v = m_traits.toi(m_position, m_end, 10);
  569. if(v < 0)
  570. {
  571. // Try a named subexpression:
  572. while((m_position != m_end) && (*m_position != '}'))
  573. ++m_position;
  574. v = m_results.named_subexpression_index(base + 1, m_position);
  575. }
  576. if((v < 0) || (*m_position != '}'))
  577. {
  578. m_position = base;
  579. // oops trailing '?':
  580. put(static_cast<char_type>('?'));
  581. return;
  582. }
  583. // Skip trailing '}':
  584. ++m_position;
  585. }
  586. else
  587. {
  588. std::ptrdiff_t len = ::boost::re_detail::distance(m_position, m_end);
  589. len = (std::min)(static_cast<std::ptrdiff_t>(2), len);
  590. v = m_traits.toi(m_position, m_position + len, 10);
  591. }
  592. if(v < 0)
  593. {
  594. // oops not a number:
  595. put(static_cast<char_type>('?'));
  596. return;
  597. }
  598. // output varies depending upon whether sub-expression v matched or not:
  599. if(m_results[v].matched)
  600. {
  601. m_have_conditional = true;
  602. format_all();
  603. m_have_conditional = false;
  604. if((m_position != m_end) && (*m_position == static_cast<char_type>(':')))
  605. {
  606. // skip the ':':
  607. ++m_position;
  608. // save output state, then turn it off:
  609. output_state saved_state = m_state;
  610. m_state = output_none;
  611. // format the rest of this scope:
  612. format_until_scope_end();
  613. // restore output state:
  614. m_state = saved_state;
  615. }
  616. }
  617. else
  618. {
  619. // save output state, then turn it off:
  620. output_state saved_state = m_state;
  621. m_state = output_none;
  622. // format until ':' or ')':
  623. m_have_conditional = true;
  624. format_all();
  625. m_have_conditional = false;
  626. // restore state:
  627. m_state = saved_state;
  628. if((m_position != m_end) && (*m_position == static_cast<char_type>(':')))
  629. {
  630. // skip the ':':
  631. ++m_position;
  632. // format the rest of this scope:
  633. format_until_scope_end();
  634. }
  635. }
  636. }
  637. template <class OutputIterator, class Results, class traits>
  638. void basic_regex_formatter<OutputIterator, Results, traits>::format_until_scope_end()
  639. {
  640. do
  641. {
  642. format_all();
  643. if((m_position == m_end) || (*m_position == static_cast<char_type>(')')))
  644. return;
  645. put(*m_position++);
  646. }while(m_position != m_end);
  647. }
  648. template <class OutputIterator, class Results, class traits>
  649. void basic_regex_formatter<OutputIterator, Results, traits>::put(char_type c)
  650. {
  651. // write a single character to output
  652. // according to which case translation mode we are in:
  653. switch(this->m_state)
  654. {
  655. case output_none:
  656. return;
  657. case output_next_lower:
  658. c = m_traits.tolower(c);
  659. this->m_state = m_restore_state;
  660. break;
  661. case output_next_upper:
  662. c = m_traits.toupper(c);
  663. this->m_state = m_restore_state;
  664. break;
  665. case output_lower:
  666. c = m_traits.tolower(c);
  667. break;
  668. case output_upper:
  669. c = m_traits.toupper(c);
  670. break;
  671. default:
  672. break;
  673. }
  674. *m_out = c;
  675. ++m_out;
  676. }
  677. template <class OutputIterator, class Results, class traits>
  678. void basic_regex_formatter<OutputIterator, Results, traits>::put(const sub_match_type& sub)
  679. {
  680. typedef typename sub_match_type::iterator iterator_type;
  681. iterator_type i = sub.first;
  682. while(i != sub.second)
  683. {
  684. put(*i);
  685. ++i;
  686. }
  687. }
  688. template <class S>
  689. class string_out_iterator
  690. #ifndef BOOST_NO_STD_ITERATOR
  691. : public std::iterator<std::output_iterator_tag, typename S::value_type>
  692. #endif
  693. {
  694. S* out;
  695. public:
  696. string_out_iterator(S& s) : out(&s) {}
  697. string_out_iterator& operator++() { return *this; }
  698. string_out_iterator& operator++(int) { return *this; }
  699. string_out_iterator& operator*() { return *this; }
  700. string_out_iterator& operator=(typename S::value_type v)
  701. {
  702. out->append(1, v);
  703. return *this;
  704. }
  705. #ifdef BOOST_NO_STD_ITERATOR
  706. typedef std::ptrdiff_t difference_type;
  707. typedef typename S::value_type value_type;
  708. typedef value_type* pointer;
  709. typedef value_type& reference;
  710. typedef std::output_iterator_tag iterator_category;
  711. #endif
  712. };
  713. template <class OutputIterator, class Iterator, class Alloc, class charT, class traits>
  714. OutputIterator regex_format_imp(OutputIterator out,
  715. const match_results<Iterator, Alloc>& m,
  716. const charT* p1, const charT* p2,
  717. match_flag_type flags,
  718. const traits& t
  719. )
  720. {
  721. if(flags & regex_constants::format_literal)
  722. {
  723. return re_detail::copy(p1, p2, out);
  724. }
  725. re_detail::basic_regex_formatter<
  726. OutputIterator,
  727. match_results<Iterator, Alloc>,
  728. traits > f(out, m, t);
  729. return f.format(p1, p2, flags);
  730. }
  731. } // namespace re_detail
  732. template <class OutputIterator, class Iterator, class charT>
  733. OutputIterator regex_format(OutputIterator out,
  734. const match_results<Iterator>& m,
  735. const charT* fmt,
  736. match_flag_type flags = format_all
  737. )
  738. {
  739. re_detail::trivial_format_traits<charT> traits;
  740. return re_detail::regex_format_imp(out, m, fmt, fmt + traits.length(fmt), flags, traits);
  741. }
  742. template <class OutputIterator, class Iterator, class charT>
  743. OutputIterator regex_format(OutputIterator out,
  744. const match_results<Iterator>& m,
  745. const std::basic_string<charT>& fmt,
  746. match_flag_type flags = format_all
  747. )
  748. {
  749. re_detail::trivial_format_traits<charT> traits;
  750. return re_detail::regex_format_imp(out, m, fmt.data(), fmt.data() + fmt.size(), flags, traits);
  751. }
  752. template <class Iterator, class charT>
  753. std::basic_string<charT> regex_format(const match_results<Iterator>& m,
  754. const charT* fmt,
  755. match_flag_type flags = format_all)
  756. {
  757. std::basic_string<charT> result;
  758. re_detail::string_out_iterator<std::basic_string<charT> > i(result);
  759. re_detail::trivial_format_traits<charT> traits;
  760. re_detail::regex_format_imp(i, m, fmt, fmt + traits.length(fmt), flags, traits);
  761. return result;
  762. }
  763. template <class Iterator, class charT>
  764. std::basic_string<charT> regex_format(const match_results<Iterator>& m,
  765. const std::basic_string<charT>& fmt,
  766. match_flag_type flags = format_all)
  767. {
  768. std::basic_string<charT> result;
  769. re_detail::string_out_iterator<std::basic_string<charT> > i(result);
  770. re_detail::trivial_format_traits<charT> traits;
  771. re_detail::regex_format_imp(i, m, fmt.data(), fmt.data() + fmt.size(), flags, traits);
  772. return result;
  773. }
  774. #ifdef BOOST_MSVC
  775. #pragma warning(push)
  776. #pragma warning(disable: 4103)
  777. #endif
  778. #ifdef BOOST_HAS_ABI_HEADERS
  779. # include BOOST_ABI_SUFFIX
  780. #endif
  781. #ifdef BOOST_MSVC
  782. #pragma warning(pop)
  783. #endif
  784. } // namespace boost
  785. #endif // BOOST_REGEX_FORMAT_HPP