replace.hpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  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. \return A reference to the modified input
  362. */
  363. template<typename SequenceT, typename Range1T, typename Range2T>
  364. inline void ireplace_last(
  365. SequenceT& Input,
  366. const Range1T& Search,
  367. const Range2T& Format,
  368. const std::locale& Loc=std::locale() )
  369. {
  370. ::boost::algorithm::find_format(
  371. Input,
  372. ::boost::algorithm::last_finder(Search, is_iequal(Loc)),
  373. ::boost::algorithm::const_formatter(Format) );
  374. }
  375. // replace_nth --------------------------------------------------------------------//
  376. //! Replace nth algorithm
  377. /*!
  378. Replace an Nth (zero-indexed) match of the search string in the input
  379. with the format string.
  380. The result is a modified copy of the input. It is returned as a sequence
  381. or copied to the output iterator.
  382. \param Output An output iterator to which the result will be copied
  383. \param Input An input string
  384. \param Search A substring to be searched for
  385. \param Nth An index of the match to be replaced. The index is 0-based.
  386. For negative N, matches are counted from the end of string.
  387. \param Format A substitute string
  388. \return An output iterator pointing just after the last inserted character or
  389. a modified copy of the input
  390. \note The second variant of this function provides the strong exception-safety guarantee
  391. */
  392. template<
  393. typename OutputIteratorT,
  394. typename Range1T,
  395. typename Range2T,
  396. typename Range3T>
  397. inline OutputIteratorT replace_nth_copy(
  398. OutputIteratorT Output,
  399. const Range1T& Input,
  400. const Range2T& Search,
  401. int Nth,
  402. const Range3T& Format )
  403. {
  404. return ::boost::algorithm::find_format_copy(
  405. Output,
  406. Input,
  407. ::boost::algorithm::nth_finder(Search, Nth),
  408. ::boost::algorithm::const_formatter(Format) );
  409. }
  410. //! Replace nth algorithm
  411. /*!
  412. \overload
  413. */
  414. template<typename SequenceT, typename Range1T, typename Range2T>
  415. inline SequenceT replace_nth_copy(
  416. const SequenceT& Input,
  417. const Range1T& Search,
  418. int Nth,
  419. const Range2T& Format )
  420. {
  421. return ::boost::algorithm::find_format_copy(
  422. Input,
  423. ::boost::algorithm::nth_finder(Search, Nth),
  424. ::boost::algorithm::const_formatter(Format) );
  425. }
  426. //! Replace nth algorithm
  427. /*!
  428. Replace an Nth (zero-indexed) match of the search string in the input
  429. with the format string. Input sequence is modified in-place.
  430. \param Input An input string
  431. \param Search A substring to be searched for
  432. \param Nth An index of the match to be replaced. The index is 0-based.
  433. For negative N, matches are counted from the end of string.
  434. \param Format A substitute string
  435. */
  436. template<typename SequenceT, typename Range1T, typename Range2T>
  437. inline void replace_nth(
  438. SequenceT& Input,
  439. const Range1T& Search,
  440. int Nth,
  441. const Range2T& Format )
  442. {
  443. ::boost::algorithm::find_format(
  444. Input,
  445. ::boost::algorithm::nth_finder(Search, Nth),
  446. ::boost::algorithm::const_formatter(Format) );
  447. }
  448. // replace_nth ( case insensitive ) -----------------------------------------------//
  449. //! Replace nth algorithm ( case insensitive )
  450. /*!
  451. Replace an Nth (zero-indexed) match of the search string in the input
  452. with the format string.
  453. The result is a modified copy of the input. It is returned as a sequence
  454. or copied to the output iterator.
  455. Searching is case insensitive.
  456. \param Output An output iterator to which the result will be copied
  457. \param Input An input string
  458. \param Search A substring to be searched for
  459. \param Nth An index of the match to be replaced. The index is 0-based.
  460. For negative N, matches are counted from the end of string.
  461. \param Format A substitute string
  462. \param Loc A locale used for case insensitive comparison
  463. \return An output iterator pointing just after the last inserted character or
  464. a modified copy of the input
  465. \note The second variant of this function provides the strong exception-safety guarantee
  466. */
  467. template<
  468. typename OutputIteratorT,
  469. typename Range1T,
  470. typename Range2T,
  471. typename Range3T>
  472. inline OutputIteratorT ireplace_nth_copy(
  473. OutputIteratorT Output,
  474. const Range1T& Input,
  475. const Range2T& Search,
  476. int Nth,
  477. const Range3T& Format,
  478. const std::locale& Loc=std::locale() )
  479. {
  480. return ::boost::algorithm::find_format_copy(
  481. Output,
  482. Input,
  483. ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc) ),
  484. ::boost::algorithm::const_formatter(Format) );
  485. }
  486. //! Replace nth algorithm ( case insensitive )
  487. /*!
  488. \overload
  489. */
  490. template<typename SequenceT, typename Range1T, typename Range2T>
  491. inline SequenceT ireplace_nth_copy(
  492. const SequenceT& Input,
  493. const Range1T& Search,
  494. int Nth,
  495. const Range2T& Format,
  496. const std::locale& Loc=std::locale() )
  497. {
  498. return ::boost::algorithm::find_format_copy(
  499. Input,
  500. ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)),
  501. ::boost::algorithm::const_formatter(Format) );
  502. }
  503. //! Replace nth algorithm ( case insensitive )
  504. /*!
  505. Replace an Nth (zero-indexed) match of the search string in the input
  506. with the format string. Input sequence is modified in-place.
  507. Searching is case insensitive.
  508. \param Input An input string
  509. \param Search A substring to be searched for
  510. \param Nth An index of the match to be replaced. The index is 0-based.
  511. For negative N, matches are counted from the end of string.
  512. \param Format A substitute string
  513. \param Loc A locale used for case insensitive comparison
  514. */
  515. template<typename SequenceT, typename Range1T, typename Range2T>
  516. inline void ireplace_nth(
  517. SequenceT& Input,
  518. const Range1T& Search,
  519. int Nth,
  520. const Range2T& Format,
  521. const std::locale& Loc=std::locale() )
  522. {
  523. ::boost::algorithm::find_format(
  524. Input,
  525. ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)),
  526. ::boost::algorithm::const_formatter(Format) );
  527. }
  528. // replace_all --------------------------------------------------------------------//
  529. //! Replace all algorithm
  530. /*!
  531. Replace all occurrences of the search string in the input
  532. with the format string.
  533. The result is a modified copy of the input. It is returned as a sequence
  534. or copied to the output iterator.
  535. \param Output An output iterator to which the result will be copied
  536. \param Input An input string
  537. \param Search A substring to be searched for
  538. \param Format A substitute string
  539. \return An output iterator pointing just after the last inserted character or
  540. a modified copy of the input
  541. \note The second variant of this function provides the strong exception-safety guarantee
  542. */
  543. template<
  544. typename OutputIteratorT,
  545. typename Range1T,
  546. typename Range2T,
  547. typename Range3T>
  548. inline OutputIteratorT replace_all_copy(
  549. OutputIteratorT Output,
  550. const Range1T& Input,
  551. const Range2T& Search,
  552. const Range3T& Format )
  553. {
  554. return ::boost::algorithm::find_format_all_copy(
  555. Output,
  556. Input,
  557. ::boost::algorithm::first_finder(Search),
  558. ::boost::algorithm::const_formatter(Format) );
  559. }
  560. //! Replace all algorithm
  561. /*!
  562. \overload
  563. */
  564. template<typename SequenceT, typename Range1T, typename Range2T>
  565. inline SequenceT replace_all_copy(
  566. const SequenceT& Input,
  567. const Range1T& Search,
  568. const Range2T& Format )
  569. {
  570. return ::boost::algorithm::find_format_all_copy(
  571. Input,
  572. ::boost::algorithm::first_finder(Search),
  573. ::boost::algorithm::const_formatter(Format) );
  574. }
  575. //! Replace all algorithm
  576. /*!
  577. Replace all occurrences of the search string in the input
  578. with the format string. The input sequence is modified in-place.
  579. \param Input An input string
  580. \param Search A substring to be searched for
  581. \param Format A substitute string
  582. \return A reference to the modified input
  583. */
  584. template<typename SequenceT, typename Range1T, typename Range2T>
  585. inline void replace_all(
  586. SequenceT& Input,
  587. const Range1T& Search,
  588. const Range2T& Format )
  589. {
  590. ::boost::algorithm::find_format_all(
  591. Input,
  592. ::boost::algorithm::first_finder(Search),
  593. ::boost::algorithm::const_formatter(Format) );
  594. }
  595. // replace_all ( case insensitive ) -----------------------------------------------//
  596. //! Replace all algorithm ( case insensitive )
  597. /*!
  598. Replace all occurrences of the search string in the input
  599. with the format string.
  600. The result is a modified copy of the input. It is returned as a sequence
  601. or copied to the output iterator.
  602. Searching is case insensitive.
  603. \param Output An output iterator to which the result will be copied
  604. \param Input An input string
  605. \param Search A substring to be searched for
  606. \param Format A substitute string
  607. \param Loc A locale used for case insensitive comparison
  608. \return An output iterator pointing just after the last inserted character or
  609. a modified copy of the input
  610. \note The second variant of this function provides the strong exception-safety guarantee
  611. */
  612. template<
  613. typename OutputIteratorT,
  614. typename Range1T,
  615. typename Range2T,
  616. typename Range3T>
  617. inline OutputIteratorT ireplace_all_copy(
  618. OutputIteratorT Output,
  619. const Range1T& Input,
  620. const Range2T& Search,
  621. const Range3T& Format,
  622. const std::locale& Loc=std::locale() )
  623. {
  624. return ::boost::algorithm::find_format_all_copy(
  625. Output,
  626. Input,
  627. ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
  628. ::boost::algorithm::const_formatter(Format) );
  629. }
  630. //! Replace all algorithm ( case insensitive )
  631. /*!
  632. \overload
  633. */
  634. template<typename SequenceT, typename Range1T, typename Range2T>
  635. inline SequenceT ireplace_all_copy(
  636. const SequenceT& Input,
  637. const Range1T& Search,
  638. const Range2T& Format,
  639. const std::locale& Loc=std::locale() )
  640. {
  641. return ::boost::algorithm::find_format_all_copy(
  642. Input,
  643. ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
  644. ::boost::algorithm::const_formatter(Format) );
  645. }
  646. //! Replace all algorithm ( case insensitive )
  647. /*!
  648. Replace all occurrences of the search string in the input
  649. with the format string.The input sequence is modified in-place.
  650. Searching is case insensitive.
  651. \param Input An input string
  652. \param Search A substring to be searched for
  653. \param Format A substitute string
  654. \param Loc A locale used for case insensitive comparison
  655. */
  656. template<typename SequenceT, typename Range1T, typename Range2T>
  657. inline void ireplace_all(
  658. SequenceT& Input,
  659. const Range1T& Search,
  660. const Range2T& Format,
  661. const std::locale& Loc=std::locale() )
  662. {
  663. ::boost::algorithm::find_format_all(
  664. Input,
  665. ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
  666. ::boost::algorithm::const_formatter(Format) );
  667. }
  668. // replace_head --------------------------------------------------------------------//
  669. //! Replace head algorithm
  670. /*!
  671. Replace the head of the input with the given format string.
  672. The head is a prefix of a string of given size.
  673. If the sequence is shorter then required, whole string if
  674. considered to be the head.
  675. The result is a modified copy of the input. It is returned as a sequence
  676. or copied to the output iterator.
  677. \param Output An output iterator to which the result will be copied
  678. \param Input An input string
  679. \param N Length of the head.
  680. For N>=0, at most N characters are extracted.
  681. For N<0, size(Input)-|N| characters are extracted.
  682. \param Format A substitute string
  683. \return An output iterator pointing just after the last inserted character or
  684. a modified copy of the input
  685. \note The second variant of this function provides the strong exception-safety guarantee
  686. */
  687. template<
  688. typename OutputIteratorT,
  689. typename Range1T,
  690. typename Range2T>
  691. inline OutputIteratorT replace_head_copy(
  692. OutputIteratorT Output,
  693. const Range1T& Input,
  694. int N,
  695. const Range2T& Format )
  696. {
  697. return ::boost::algorithm::find_format_copy(
  698. Output,
  699. Input,
  700. ::boost::algorithm::head_finder(N),
  701. ::boost::algorithm::const_formatter(Format) );
  702. }
  703. //! Replace head algorithm
  704. /*!
  705. \overload
  706. */
  707. template<typename SequenceT, typename RangeT>
  708. inline SequenceT replace_head_copy(
  709. const SequenceT& Input,
  710. int N,
  711. const RangeT& Format )
  712. {
  713. return ::boost::algorithm::find_format_copy(
  714. Input,
  715. ::boost::algorithm::head_finder(N),
  716. ::boost::algorithm::const_formatter(Format) );
  717. }
  718. //! Replace head algorithm
  719. /*!
  720. Replace the head of the input with the given format string.
  721. The head is a prefix of a string of given size.
  722. If the sequence is shorter then required, the whole string is
  723. considered to be the head. The input sequence is modified in-place.
  724. \param Input An input string
  725. \param N Length of the head.
  726. For N>=0, at most N characters are extracted.
  727. For N<0, size(Input)-|N| characters are extracted.
  728. \param Format A substitute string
  729. */
  730. template<typename SequenceT, typename RangeT>
  731. inline void replace_head(
  732. SequenceT& Input,
  733. int N,
  734. const RangeT& Format )
  735. {
  736. ::boost::algorithm::find_format(
  737. Input,
  738. ::boost::algorithm::head_finder(N),
  739. ::boost::algorithm::const_formatter(Format) );
  740. }
  741. // replace_tail --------------------------------------------------------------------//
  742. //! Replace tail algorithm
  743. /*!
  744. Replace the tail of the input with the given format string.
  745. The tail is a suffix of a string of given size.
  746. If the sequence is shorter then required, whole string is
  747. considered to be the tail.
  748. The result is a modified copy of the input. It is returned as a sequence
  749. or copied to the output iterator.
  750. \param Output An output iterator to which the result will be copied
  751. \param Input An input string
  752. \param N Length of the tail.
  753. For N>=0, at most N characters are extracted.
  754. For N<0, size(Input)-|N| characters are extracted.
  755. \param Format A substitute string
  756. \return An output iterator pointing just after the last inserted character or
  757. a modified copy of the input
  758. \note The second variant of this function provides the strong exception-safety guarantee
  759. */
  760. template<
  761. typename OutputIteratorT,
  762. typename Range1T,
  763. typename Range2T>
  764. inline OutputIteratorT replace_tail_copy(
  765. OutputIteratorT Output,
  766. const Range1T& Input,
  767. int N,
  768. const Range2T& Format )
  769. {
  770. return ::boost::algorithm::find_format_copy(
  771. Output,
  772. Input,
  773. ::boost::algorithm::tail_finder(N),
  774. ::boost::algorithm::const_formatter(Format) );
  775. }
  776. //! Replace tail algorithm
  777. /*!
  778. \overload
  779. */
  780. template<typename SequenceT, typename RangeT>
  781. inline SequenceT replace_tail_copy(
  782. const SequenceT& Input,
  783. int N,
  784. const RangeT& Format )
  785. {
  786. return ::boost::algorithm::find_format_copy(
  787. Input,
  788. ::boost::algorithm::tail_finder(N),
  789. ::boost::algorithm::const_formatter(Format) );
  790. }
  791. //! Replace tail algorithm
  792. /*!
  793. Replace the tail of the input with the given format sequence.
  794. The tail is a suffix of a string of given size.
  795. If the sequence is shorter then required, the whole string is
  796. considered to be the tail. The input sequence is modified in-place.
  797. \param Input An input string
  798. \param N Length of the tail.
  799. For N>=0, at most N characters are extracted.
  800. For N<0, size(Input)-|N| characters are extracted.
  801. \param Format A substitute string
  802. */
  803. template<typename SequenceT, typename RangeT>
  804. inline void replace_tail(
  805. SequenceT& Input,
  806. int N,
  807. const RangeT& Format )
  808. {
  809. ::boost::algorithm::find_format(
  810. Input,
  811. ::boost::algorithm::tail_finder(N),
  812. ::boost::algorithm::const_formatter(Format) );
  813. }
  814. } // namespace algorithm
  815. // pull names to the boost namespace
  816. using algorithm::replace_range_copy;
  817. using algorithm::replace_range;
  818. using algorithm::replace_first_copy;
  819. using algorithm::replace_first;
  820. using algorithm::ireplace_first_copy;
  821. using algorithm::ireplace_first;
  822. using algorithm::replace_last_copy;
  823. using algorithm::replace_last;
  824. using algorithm::ireplace_last_copy;
  825. using algorithm::ireplace_last;
  826. using algorithm::replace_nth_copy;
  827. using algorithm::replace_nth;
  828. using algorithm::ireplace_nth_copy;
  829. using algorithm::ireplace_nth;
  830. using algorithm::replace_all_copy;
  831. using algorithm::replace_all;
  832. using algorithm::ireplace_all_copy;
  833. using algorithm::ireplace_all;
  834. using algorithm::replace_head_copy;
  835. using algorithm::replace_head;
  836. using algorithm::replace_tail_copy;
  837. using algorithm::replace_tail;
  838. } // namespace boost
  839. #endif // BOOST_REPLACE_HPP