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