replace.hpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. // Boost string_algo library replace.hpp header file ---------------------------//
  2. // Copyright Pavol Droba 2002-2006.
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // See http://www.boost.org/ for updates, documentation, and revision history.
  8. #ifndef BOOST_STRING_REPLACE_HPP
  9. #define BOOST_STRING_REPLACE_HPP
  10. #include <boost/algorithm/string/config.hpp>
  11. #include <boost/range/iterator_range_core.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. #include <boost/range/iterator.hpp>
  15. #include <boost/range/const_iterator.hpp>
  16. #include <boost/algorithm/string/find_format.hpp>
  17. #include <boost/algorithm/string/finder.hpp>
  18. #include <boost/algorithm/string/formatter.hpp>
  19. #include <boost/algorithm/string/compare.hpp>
  20. /*! \file
  21. Defines various replace algorithms. Each algorithm replaces
  22. part(s) of the input according to set of searching and replace criteria.
  23. */
  24. namespace boost {
  25. namespace algorithm {
  26. // replace_range --------------------------------------------------------------------//
  27. //! Replace range algorithm
  28. /*!
  29. Replace the given range in the input string.
  30. The result is a modified copy of the input. It is returned as a sequence
  31. or copied to the output iterator.
  32. \param Output An output iterator to which the result will be copied
  33. \param Input An input string
  34. \param SearchRange A range in the input to be substituted
  35. \param Format A substitute string
  36. \return An output iterator pointing just after the last inserted character or
  37. a modified copy of the input
  38. \note The second variant of this function provides the strong exception-safety guarantee
  39. */
  40. template<
  41. typename OutputIteratorT,
  42. typename Range1T,
  43. typename Range2T>
  44. inline OutputIteratorT replace_range_copy(
  45. OutputIteratorT Output,
  46. const Range1T& Input,
  47. const iterator_range<
  48. BOOST_STRING_TYPENAME
  49. range_const_iterator<Range1T>::type>& SearchRange,
  50. const Range2T& Format)
  51. {
  52. return ::boost::algorithm::find_format_copy(
  53. Output,
  54. Input,
  55. ::boost::algorithm::range_finder(SearchRange),
  56. ::boost::algorithm::const_formatter(Format));
  57. }
  58. //! Replace range algorithm
  59. /*!
  60. \overload
  61. */
  62. template<typename SequenceT, typename RangeT>
  63. inline SequenceT replace_range_copy(
  64. const SequenceT& Input,
  65. const iterator_range<
  66. BOOST_STRING_TYPENAME
  67. range_const_iterator<SequenceT>::type>& SearchRange,
  68. const RangeT& Format)
  69. {
  70. return ::boost::algorithm::find_format_copy(
  71. Input,
  72. ::boost::algorithm::range_finder(SearchRange),
  73. ::boost::algorithm::const_formatter(Format));
  74. }
  75. //! Replace range algorithm
  76. /*!
  77. Replace the given range in the input string.
  78. The input sequence is modified in-place.
  79. \param Input An input string
  80. \param SearchRange A range in the input to be substituted
  81. \param Format A substitute string
  82. */
  83. template<typename SequenceT, typename RangeT>
  84. inline void replace_range(
  85. SequenceT& Input,
  86. const iterator_range<
  87. BOOST_STRING_TYPENAME
  88. range_iterator<SequenceT>::type>& SearchRange,
  89. const RangeT& Format)
  90. {
  91. ::boost::algorithm::find_format(
  92. Input,
  93. ::boost::algorithm::range_finder(SearchRange),
  94. ::boost::algorithm::const_formatter(Format));
  95. }
  96. // replace_first --------------------------------------------------------------------//
  97. //! Replace first algorithm
  98. /*!
  99. Replace the first match of the search substring in the input
  100. with the format string.
  101. The result is a modified copy of the input. It is returned as a sequence
  102. or copied to the output iterator.
  103. \param Output An output iterator to which the result will be copied
  104. \param Input An input string
  105. \param Search A substring to be searched for
  106. \param Format A substitute string
  107. \return An output iterator pointing just after the last inserted character or
  108. a modified copy of the input
  109. \note The second variant of this function provides the strong exception-safety guarantee
  110. */
  111. template<
  112. typename OutputIteratorT,
  113. typename Range1T,
  114. typename Range2T,
  115. typename Range3T>
  116. inline OutputIteratorT replace_first_copy(
  117. OutputIteratorT Output,
  118. const Range1T& Input,
  119. const Range2T& Search,
  120. const Range3T& Format)
  121. {
  122. return ::boost::algorithm::find_format_copy(
  123. Output,
  124. Input,
  125. ::boost::algorithm::first_finder(Search),
  126. ::boost::algorithm::const_formatter(Format) );
  127. }
  128. //! Replace first algorithm
  129. /*!
  130. \overload
  131. */
  132. template<typename SequenceT, typename Range1T, typename Range2T>
  133. inline SequenceT replace_first_copy(
  134. const SequenceT& Input,
  135. const Range1T& Search,
  136. const Range2T& Format )
  137. {
  138. return ::boost::algorithm::find_format_copy(
  139. Input,
  140. ::boost::algorithm::first_finder(Search),
  141. ::boost::algorithm::const_formatter(Format) );
  142. }
  143. //! Replace first algorithm
  144. /*!
  145. replace the first match of the search substring in the input
  146. with the format string. The input sequence is modified in-place.
  147. \param Input An input string
  148. \param Search A substring to be searched for
  149. \param Format A substitute string
  150. */
  151. template<typename SequenceT, typename Range1T, typename Range2T>
  152. inline void replace_first(
  153. SequenceT& Input,
  154. const Range1T& Search,
  155. const Range2T& Format )
  156. {
  157. ::boost::algorithm::find_format(
  158. Input,
  159. ::boost::algorithm::first_finder(Search),
  160. ::boost::algorithm::const_formatter(Format) );
  161. }
  162. // replace_first ( case insensitive ) ---------------------------------------------//
  163. //! Replace first algorithm ( case insensitive )
  164. /*!
  165. Replace the first match of the search substring in the input
  166. with the format string.
  167. The result is a modified copy of the input. It is returned as a sequence
  168. or copied to the output iterator.
  169. Searching is case insensitive.
  170. \param Output An output iterator to which the result will be copied
  171. \param Input An input string
  172. \param Search A substring to be searched for
  173. \param Format A substitute string
  174. \param Loc A locale used for case insensitive comparison
  175. \return An output iterator pointing just after the last inserted character or
  176. a modified copy of the input
  177. \note The second variant of this function provides the strong exception-safety guarantee
  178. */
  179. template<
  180. typename OutputIteratorT,
  181. typename Range1T,
  182. typename Range2T,
  183. typename Range3T>
  184. inline OutputIteratorT ireplace_first_copy(
  185. OutputIteratorT Output,
  186. const Range1T& Input,
  187. const Range2T& Search,
  188. const Range3T& Format,
  189. const std::locale& Loc=std::locale() )
  190. {
  191. return ::boost::algorithm::find_format_copy(
  192. Output,
  193. Input,
  194. ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
  195. ::boost::algorithm::const_formatter(Format) );
  196. }
  197. //! Replace first algorithm ( case insensitive )
  198. /*!
  199. \overload
  200. */
  201. template<typename SequenceT, typename Range2T, typename Range1T>
  202. inline SequenceT ireplace_first_copy(
  203. const SequenceT& Input,
  204. const Range2T& Search,
  205. const Range1T& Format,
  206. const std::locale& Loc=std::locale() )
  207. {
  208. return ::boost::algorithm::find_format_copy(
  209. Input,
  210. ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
  211. ::boost::algorithm::const_formatter(Format) );
  212. }
  213. //! Replace first algorithm ( case insensitive )
  214. /*!
  215. Replace the first match of the search substring in the input
  216. with the format string. Input sequence is modified in-place.
  217. Searching is case insensitive.
  218. \param Input An input string
  219. \param Search A substring to be searched for
  220. \param Format A substitute string
  221. \param Loc A locale used for case insensitive comparison
  222. */
  223. template<typename SequenceT, typename Range1T, typename Range2T>
  224. inline void ireplace_first(
  225. SequenceT& Input,
  226. const Range1T& Search,
  227. const Range2T& Format,
  228. const std::locale& Loc=std::locale() )
  229. {
  230. ::boost::algorithm::find_format(
  231. Input,
  232. ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
  233. ::boost::algorithm::const_formatter(Format) );
  234. }
  235. // replace_last --------------------------------------------------------------------//
  236. //! Replace last algorithm
  237. /*!
  238. Replace the last match of the search string in the input
  239. with the format string.
  240. The result is a modified copy of the input. It is returned as a sequence
  241. or copied to the output iterator.
  242. \param Output An output iterator to which the result will be copied
  243. \param Input An input string
  244. \param Search A substring to be searched for
  245. \param Format A substitute string
  246. \return An output iterator pointing just after the last inserted character or
  247. a modified copy of the input
  248. \note The second variant of this function provides the strong exception-safety guarantee
  249. */
  250. template<
  251. typename OutputIteratorT,
  252. typename Range1T,
  253. typename Range2T,
  254. typename Range3T>
  255. inline OutputIteratorT replace_last_copy(
  256. OutputIteratorT Output,
  257. const Range1T& Input,
  258. const Range2T& Search,
  259. const Range3T& Format )
  260. {
  261. return ::boost::algorithm::find_format_copy(
  262. Output,
  263. Input,
  264. ::boost::algorithm::last_finder(Search),
  265. ::boost::algorithm::const_formatter(Format) );
  266. }
  267. //! Replace last algorithm
  268. /*!
  269. \overload
  270. */
  271. template<typename SequenceT, typename Range1T, typename Range2T>
  272. inline SequenceT replace_last_copy(
  273. const SequenceT& Input,
  274. const Range1T& Search,
  275. const Range2T& Format )
  276. {
  277. return ::boost::algorithm::find_format_copy(
  278. Input,
  279. ::boost::algorithm::last_finder(Search),
  280. ::boost::algorithm::const_formatter(Format) );
  281. }
  282. //! Replace last algorithm
  283. /*!
  284. Replace the last match of the search string in the input
  285. with the format string. Input sequence is modified in-place.
  286. \param Input An input string
  287. \param Search A substring to be searched for
  288. \param Format A substitute string
  289. */
  290. template<typename SequenceT, typename Range1T, typename Range2T>
  291. inline void replace_last(
  292. SequenceT& Input,
  293. const Range1T& Search,
  294. const Range2T& Format )
  295. {
  296. ::boost::algorithm::find_format(
  297. Input,
  298. ::boost::algorithm::last_finder(Search),
  299. ::boost::algorithm::const_formatter(Format) );
  300. }
  301. // replace_last ( case insensitive ) -----------------------------------------------//
  302. //! Replace last algorithm ( case insensitive )
  303. /*!
  304. Replace the last match of the search string in the input
  305. with the format string.
  306. The result is a modified copy of the input. It is returned as a sequence
  307. or copied to the output iterator.
  308. Searching is case insensitive.
  309. \param Output An output iterator to which the result will be copied
  310. \param Input An input string
  311. \param Search A substring to be searched for
  312. \param Format A substitute string
  313. \param Loc A locale used for case insensitive comparison
  314. \return An output iterator pointing just after the last inserted character or
  315. a modified copy of the input
  316. \note The second variant of this function provides the strong exception-safety guarantee
  317. */
  318. template<
  319. typename OutputIteratorT,
  320. typename Range1T,
  321. typename Range2T,
  322. typename Range3T>
  323. inline OutputIteratorT ireplace_last_copy(
  324. OutputIteratorT Output,
  325. const Range1T& Input,
  326. const Range2T& Search,
  327. const Range3T& Format,
  328. const std::locale& Loc=std::locale() )
  329. {
  330. return ::boost::algorithm::find_format_copy(
  331. Output,
  332. Input,
  333. ::boost::algorithm::last_finder(Search, is_iequal(Loc)),
  334. ::boost::algorithm::const_formatter(Format) );
  335. }
  336. //! Replace last algorithm ( case insensitive )
  337. /*!
  338. \overload
  339. */
  340. template<typename SequenceT, typename Range1T, typename Range2T>
  341. inline SequenceT ireplace_last_copy(
  342. const SequenceT& Input,
  343. const Range1T& Search,
  344. const Range2T& Format,
  345. const std::locale& Loc=std::locale() )
  346. {
  347. return ::boost::algorithm::find_format_copy(
  348. Input,
  349. ::boost::algorithm::last_finder(Search, is_iequal(Loc)),
  350. ::boost::algorithm::const_formatter(Format) );
  351. }
  352. //! Replace last algorithm ( case insensitive )
  353. /*!
  354. Replace the last match of the search string in the input
  355. with the format string.The input sequence is modified in-place.
  356. Searching is case insensitive.
  357. \param Input An input string
  358. \param Search A substring to be searched for
  359. \param Format A substitute string
  360. \param Loc A locale used for case insensitive comparison
  361. */
  362. template<typename SequenceT, typename Range1T, typename Range2T>
  363. inline void ireplace_last(
  364. SequenceT& Input,
  365. const Range1T& Search,
  366. const Range2T& Format,
  367. const std::locale& Loc=std::locale() )
  368. {
  369. ::boost::algorithm::find_format(
  370. Input,
  371. ::boost::algorithm::last_finder(Search, is_iequal(Loc)),
  372. ::boost::algorithm::const_formatter(Format) );
  373. }
  374. // replace_nth --------------------------------------------------------------------//
  375. //! Replace nth algorithm
  376. /*!
  377. Replace an Nth (zero-indexed) match of the search string in the input
  378. with the format string.
  379. The result is a modified copy of the input. It is returned as a sequence
  380. or copied to the output iterator.
  381. \param Output An output iterator to which the result will be copied
  382. \param Input An input string
  383. \param Search A substring to be searched for
  384. \param Nth An index of the match to be replaced. The index is 0-based.
  385. For negative N, matches are counted from the end of string.
  386. \param Format A substitute string
  387. \return An output iterator pointing just after the last inserted character or
  388. a modified copy of the input
  389. \note The second variant of this function provides the strong exception-safety guarantee
  390. */
  391. template<
  392. typename OutputIteratorT,
  393. typename Range1T,
  394. typename Range2T,
  395. typename Range3T>
  396. inline OutputIteratorT replace_nth_copy(
  397. OutputIteratorT Output,
  398. const Range1T& Input,
  399. const Range2T& Search,
  400. int Nth,
  401. const Range3T& Format )
  402. {
  403. return ::boost::algorithm::find_format_copy(
  404. Output,
  405. Input,
  406. ::boost::algorithm::nth_finder(Search, Nth),
  407. ::boost::algorithm::const_formatter(Format) );
  408. }
  409. //! Replace nth algorithm
  410. /*!
  411. \overload
  412. */
  413. template<typename SequenceT, typename Range1T, typename Range2T>
  414. inline SequenceT replace_nth_copy(
  415. const SequenceT& Input,
  416. const Range1T& Search,
  417. int Nth,
  418. const Range2T& Format )
  419. {
  420. return ::boost::algorithm::find_format_copy(
  421. Input,
  422. ::boost::algorithm::nth_finder(Search, Nth),
  423. ::boost::algorithm::const_formatter(Format) );
  424. }
  425. //! Replace nth algorithm
  426. /*!
  427. Replace an Nth (zero-indexed) match of the search string in the input
  428. with the format string. Input sequence is modified in-place.
  429. \param Input An input string
  430. \param Search A substring to be searched for
  431. \param Nth An index of the match to be replaced. The index is 0-based.
  432. For negative N, matches are counted from the end of string.
  433. \param Format A substitute string
  434. */
  435. template<typename SequenceT, typename Range1T, typename Range2T>
  436. inline void replace_nth(
  437. SequenceT& Input,
  438. const Range1T& Search,
  439. int Nth,
  440. const Range2T& Format )
  441. {
  442. ::boost::algorithm::find_format(
  443. Input,
  444. ::boost::algorithm::nth_finder(Search, Nth),
  445. ::boost::algorithm::const_formatter(Format) );
  446. }
  447. // replace_nth ( case insensitive ) -----------------------------------------------//
  448. //! Replace nth algorithm ( case insensitive )
  449. /*!
  450. Replace an Nth (zero-indexed) match of the search string in the input
  451. with the format string.
  452. The result is a modified copy of the input. It is returned as a sequence
  453. or copied to the output iterator.
  454. Searching is case insensitive.
  455. \param Output An output iterator to which the result will be copied
  456. \param Input An input string
  457. \param Search A substring to be searched for
  458. \param Nth An index of the match to be replaced. The index is 0-based.
  459. For negative N, matches are counted from the end of string.
  460. \param Format A substitute string
  461. \param Loc A locale used for case insensitive comparison
  462. \return An output iterator pointing just after the last inserted character or
  463. a modified copy of the input
  464. \note The second variant of this function provides the strong exception-safety guarantee
  465. */
  466. template<
  467. typename OutputIteratorT,
  468. typename Range1T,
  469. typename Range2T,
  470. typename Range3T>
  471. inline OutputIteratorT ireplace_nth_copy(
  472. OutputIteratorT Output,
  473. const Range1T& Input,
  474. const Range2T& Search,
  475. int Nth,
  476. const Range3T& Format,
  477. const std::locale& Loc=std::locale() )
  478. {
  479. return ::boost::algorithm::find_format_copy(
  480. Output,
  481. Input,
  482. ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc) ),
  483. ::boost::algorithm::const_formatter(Format) );
  484. }
  485. //! Replace nth algorithm ( case insensitive )
  486. /*!
  487. \overload
  488. */
  489. template<typename SequenceT, typename Range1T, typename Range2T>
  490. inline SequenceT ireplace_nth_copy(
  491. const SequenceT& Input,
  492. const Range1T& Search,
  493. int Nth,
  494. const Range2T& Format,
  495. const std::locale& Loc=std::locale() )
  496. {
  497. return ::boost::algorithm::find_format_copy(
  498. Input,
  499. ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)),
  500. ::boost::algorithm::const_formatter(Format) );
  501. }
  502. //! Replace nth algorithm ( case insensitive )
  503. /*!
  504. Replace an Nth (zero-indexed) match of the search string in the input
  505. with the format string. Input sequence is modified in-place.
  506. Searching is case insensitive.
  507. \param Input An input string
  508. \param Search A substring to be searched for
  509. \param Nth An index of the match to be replaced. The index is 0-based.
  510. For negative N, matches are counted from the end of string.
  511. \param Format A substitute string
  512. \param Loc A locale used for case insensitive comparison
  513. */
  514. template<typename SequenceT, typename Range1T, typename Range2T>
  515. inline void ireplace_nth(
  516. SequenceT& Input,
  517. const Range1T& Search,
  518. int Nth,
  519. const Range2T& Format,
  520. const std::locale& Loc=std::locale() )
  521. {
  522. ::boost::algorithm::find_format(
  523. Input,
  524. ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)),
  525. ::boost::algorithm::const_formatter(Format) );
  526. }
  527. // replace_all --------------------------------------------------------------------//
  528. //! Replace all algorithm
  529. /*!
  530. Replace all occurrences of the search string in the input
  531. with the format string.
  532. The result is a modified copy of the input. It is returned as a sequence
  533. or copied to the output iterator.
  534. \param Output An output iterator to which the result will be copied
  535. \param Input An input string
  536. \param Search A substring to be searched for
  537. \param Format A substitute string
  538. \return An output iterator pointing just after the last inserted character or
  539. a modified copy of the input
  540. \note The second variant of this function provides the strong exception-safety guarantee
  541. */
  542. template<
  543. typename OutputIteratorT,
  544. typename Range1T,
  545. typename Range2T,
  546. typename Range3T>
  547. inline OutputIteratorT replace_all_copy(
  548. OutputIteratorT Output,
  549. const Range1T& Input,
  550. const Range2T& Search,
  551. const Range3T& Format )
  552. {
  553. return ::boost::algorithm::find_format_all_copy(
  554. Output,
  555. Input,
  556. ::boost::algorithm::first_finder(Search),
  557. ::boost::algorithm::const_formatter(Format) );
  558. }
  559. //! Replace all algorithm
  560. /*!
  561. \overload
  562. */
  563. template<typename SequenceT, typename Range1T, typename Range2T>
  564. inline SequenceT replace_all_copy(
  565. const SequenceT& Input,
  566. const Range1T& Search,
  567. const Range2T& Format )
  568. {
  569. return ::boost::algorithm::find_format_all_copy(
  570. Input,
  571. ::boost::algorithm::first_finder(Search),
  572. ::boost::algorithm::const_formatter(Format) );
  573. }
  574. //! Replace all algorithm
  575. /*!
  576. Replace all occurrences of the search string in the input
  577. with the format string. The input sequence is modified in-place.
  578. \param Input An input string
  579. \param Search A substring to be searched for
  580. \param Format A substitute string
  581. */
  582. template<typename SequenceT, typename Range1T, typename Range2T>
  583. inline void replace_all(
  584. SequenceT& Input,
  585. const Range1T& Search,
  586. const Range2T& Format )
  587. {
  588. ::boost::algorithm::find_format_all(
  589. Input,
  590. ::boost::algorithm::first_finder(Search),
  591. ::boost::algorithm::const_formatter(Format) );
  592. }
  593. // replace_all ( case insensitive ) -----------------------------------------------//
  594. //! Replace all algorithm ( case insensitive )
  595. /*!
  596. Replace all occurrences of the search string in the input
  597. with the format string.
  598. The result is a modified copy of the input. It is returned as a sequence
  599. or copied to the output iterator.
  600. Searching is case insensitive.
  601. \param Output An output iterator to which the result will be copied
  602. \param Input An input string
  603. \param Search A substring to be searched for
  604. \param Format A substitute string
  605. \param Loc A locale used for case insensitive comparison
  606. \return An output iterator pointing just after the last inserted character or
  607. a modified copy of the input
  608. \note The second variant of this function provides the strong exception-safety guarantee
  609. */
  610. template<
  611. typename OutputIteratorT,
  612. typename Range1T,
  613. typename Range2T,
  614. typename Range3T>
  615. inline OutputIteratorT ireplace_all_copy(
  616. OutputIteratorT Output,
  617. const Range1T& Input,
  618. const Range2T& Search,
  619. const Range3T& Format,
  620. const std::locale& Loc=std::locale() )
  621. {
  622. return ::boost::algorithm::find_format_all_copy(
  623. Output,
  624. Input,
  625. ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
  626. ::boost::algorithm::const_formatter(Format) );
  627. }
  628. //! Replace all algorithm ( case insensitive )
  629. /*!
  630. \overload
  631. */
  632. template<typename SequenceT, typename Range1T, typename Range2T>
  633. inline SequenceT ireplace_all_copy(
  634. const SequenceT& Input,
  635. const Range1T& Search,
  636. const Range2T& Format,
  637. const std::locale& Loc=std::locale() )
  638. {
  639. return ::boost::algorithm::find_format_all_copy(
  640. Input,
  641. ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
  642. ::boost::algorithm::const_formatter(Format) );
  643. }
  644. //! Replace all algorithm ( case insensitive )
  645. /*!
  646. Replace all occurrences of the search string in the input
  647. with the format string.The input sequence is modified in-place.
  648. Searching is case insensitive.
  649. \param Input An input string
  650. \param Search A substring to be searched for
  651. \param Format A substitute string
  652. \param Loc A locale used for case insensitive comparison
  653. */
  654. template<typename SequenceT, typename Range1T, typename Range2T>
  655. inline void ireplace_all(
  656. SequenceT& Input,
  657. const Range1T& Search,
  658. const Range2T& Format,
  659. const std::locale& Loc=std::locale() )
  660. {
  661. ::boost::algorithm::find_format_all(
  662. Input,
  663. ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
  664. ::boost::algorithm::const_formatter(Format) );
  665. }
  666. // replace_head --------------------------------------------------------------------//
  667. //! Replace head algorithm
  668. /*!
  669. Replace the head of the input with the given format string.
  670. The head is a prefix of a string of given size.
  671. If the sequence is shorter then required, whole string if
  672. considered to be the head.
  673. The result is a modified copy of the input. It is returned as a sequence
  674. or copied to the output iterator.
  675. \param Output An output iterator to which the result will be copied
  676. \param Input An input string
  677. \param N Length of the head.
  678. For N>=0, at most N characters are extracted.
  679. For N<0, size(Input)-|N| characters are extracted.
  680. \param Format A substitute string
  681. \return An output iterator pointing just after the last inserted character or
  682. a modified copy of the input
  683. \note The second variant of this function provides the strong exception-safety guarantee
  684. */
  685. template<
  686. typename OutputIteratorT,
  687. typename Range1T,
  688. typename Range2T>
  689. inline OutputIteratorT replace_head_copy(
  690. OutputIteratorT Output,
  691. const Range1T& Input,
  692. int N,
  693. const Range2T& Format )
  694. {
  695. return ::boost::algorithm::find_format_copy(
  696. Output,
  697. Input,
  698. ::boost::algorithm::head_finder(N),
  699. ::boost::algorithm::const_formatter(Format) );
  700. }
  701. //! Replace head algorithm
  702. /*!
  703. \overload
  704. */
  705. template<typename SequenceT, typename RangeT>
  706. inline SequenceT replace_head_copy(
  707. const SequenceT& Input,
  708. int N,
  709. const RangeT& Format )
  710. {
  711. return ::boost::algorithm::find_format_copy(
  712. Input,
  713. ::boost::algorithm::head_finder(N),
  714. ::boost::algorithm::const_formatter(Format) );
  715. }
  716. //! Replace head algorithm
  717. /*!
  718. Replace the head of the input with the given format string.
  719. The head is a prefix of a string of given size.
  720. If the sequence is shorter then required, the whole string is
  721. considered to be the head. The input sequence is modified in-place.
  722. \param Input An input string
  723. \param N Length of the head.
  724. For N>=0, at most N characters are extracted.
  725. For N<0, size(Input)-|N| characters are extracted.
  726. \param Format A substitute string
  727. */
  728. template<typename SequenceT, typename RangeT>
  729. inline void replace_head(
  730. SequenceT& Input,
  731. int N,
  732. const RangeT& Format )
  733. {
  734. ::boost::algorithm::find_format(
  735. Input,
  736. ::boost::algorithm::head_finder(N),
  737. ::boost::algorithm::const_formatter(Format) );
  738. }
  739. // replace_tail --------------------------------------------------------------------//
  740. //! Replace tail algorithm
  741. /*!
  742. Replace the tail of the input with the given format string.
  743. The tail is a suffix of a string of given size.
  744. If the sequence is shorter then required, whole string is
  745. considered to be the tail.
  746. The result is a modified copy of the input. It is returned as a sequence
  747. or copied to the output iterator.
  748. \param Output An output iterator to which the result will be copied
  749. \param Input An input string
  750. \param N Length of the tail.
  751. For N>=0, at most N characters are extracted.
  752. For N<0, size(Input)-|N| characters are extracted.
  753. \param Format A substitute string
  754. \return An output iterator pointing just after the last inserted character or
  755. a modified copy of the input
  756. \note The second variant of this function provides the strong exception-safety guarantee
  757. */
  758. template<
  759. typename OutputIteratorT,
  760. typename Range1T,
  761. typename Range2T>
  762. inline OutputIteratorT replace_tail_copy(
  763. OutputIteratorT Output,
  764. const Range1T& Input,
  765. int N,
  766. const Range2T& Format )
  767. {
  768. return ::boost::algorithm::find_format_copy(
  769. Output,
  770. Input,
  771. ::boost::algorithm::tail_finder(N),
  772. ::boost::algorithm::const_formatter(Format) );
  773. }
  774. //! Replace tail algorithm
  775. /*!
  776. \overload
  777. */
  778. template<typename SequenceT, typename RangeT>
  779. inline SequenceT replace_tail_copy(
  780. const SequenceT& Input,
  781. int N,
  782. const RangeT& Format )
  783. {
  784. return ::boost::algorithm::find_format_copy(
  785. Input,
  786. ::boost::algorithm::tail_finder(N),
  787. ::boost::algorithm::const_formatter(Format) );
  788. }
  789. //! Replace tail algorithm
  790. /*!
  791. Replace the tail of the input with the given format sequence.
  792. The tail is a suffix of a string of given size.
  793. If the sequence is shorter then required, the whole string is
  794. considered to be the tail. The input sequence is modified in-place.
  795. \param Input An input string
  796. \param N Length of the tail.
  797. For N>=0, at most N characters are extracted.
  798. For N<0, size(Input)-|N| characters are extracted.
  799. \param Format A substitute string
  800. */
  801. template<typename SequenceT, typename RangeT>
  802. inline void replace_tail(
  803. SequenceT& Input,
  804. int N,
  805. const RangeT& Format )
  806. {
  807. ::boost::algorithm::find_format(
  808. Input,
  809. ::boost::algorithm::tail_finder(N),
  810. ::boost::algorithm::const_formatter(Format) );
  811. }
  812. } // namespace algorithm
  813. // pull names to the boost namespace
  814. using algorithm::replace_range_copy;
  815. using algorithm::replace_range;
  816. using algorithm::replace_first_copy;
  817. using algorithm::replace_first;
  818. using algorithm::ireplace_first_copy;
  819. using algorithm::ireplace_first;
  820. using algorithm::replace_last_copy;
  821. using algorithm::replace_last;
  822. using algorithm::ireplace_last_copy;
  823. using algorithm::ireplace_last;
  824. using algorithm::replace_nth_copy;
  825. using algorithm::replace_nth;
  826. using algorithm::ireplace_nth_copy;
  827. using algorithm::ireplace_nth;
  828. using algorithm::replace_all_copy;
  829. using algorithm::replace_all;
  830. using algorithm::ireplace_all_copy;
  831. using algorithm::ireplace_all;
  832. using algorithm::replace_head_copy;
  833. using algorithm::replace_head;
  834. using algorithm::replace_tail_copy;
  835. using algorithm::replace_tail;
  836. } // namespace boost
  837. #endif // BOOST_REPLACE_HPP