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