erase.hpp 31 KB

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