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