• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  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 <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 #include <boost/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 
32 namespace boost {
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>
replace_range_copy(OutputIteratorT Output,const Range1T & Input,const iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> & SearchRange,const Range2T & Format)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 ::boost::algorithm::find_format_copy(
65                 Output,
66                 Input,
67                 ::boost::algorithm::range_finder(SearchRange),
68                 ::boost::algorithm::const_formatter(Format));
69         }
70 
71         //! Replace range algorithm
72         /*!
73             \overload
74         */
75         template<typename SequenceT, typename RangeT>
replace_range_copy(const SequenceT & Input,const iterator_range<BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type> & SearchRange,const RangeT & Format)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 ::boost::algorithm::find_format_copy(
84                 Input,
85                 ::boost::algorithm::range_finder(SearchRange),
86                 ::boost::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>
replace_range(SequenceT & Input,const iterator_range<BOOST_STRING_TYPENAME range_iterator<SequenceT>::type> & SearchRange,const RangeT & Format)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             ::boost::algorithm::find_format(
107                 Input,
108                 ::boost::algorithm::range_finder(SearchRange),
109                 ::boost::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>
replace_first_copy(OutputIteratorT Output,const Range1T & Input,const Range2T & Search,const Range3T & Format)135         inline OutputIteratorT replace_first_copy(
136             OutputIteratorT Output,
137             const Range1T& Input,
138             const Range2T& Search,
139             const Range3T& Format)
140         {
141             return ::boost::algorithm::find_format_copy(
142                 Output,
143                 Input,
144                 ::boost::algorithm::first_finder(Search),
145                 ::boost::algorithm::const_formatter(Format) );
146         }
147 
148         //! Replace first algorithm
149         /*!
150             \overload
151         */
152         template<typename SequenceT, typename Range1T, typename Range2T>
replace_first_copy(const SequenceT & Input,const Range1T & Search,const Range2T & Format)153         inline SequenceT replace_first_copy(
154             const SequenceT& Input,
155             const Range1T& Search,
156             const Range2T& Format )
157         {
158             return ::boost::algorithm::find_format_copy(
159                 Input,
160                 ::boost::algorithm::first_finder(Search),
161                 ::boost::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>
replace_first(SequenceT & Input,const Range1T & Search,const Range2T & Format)174         inline void replace_first(
175             SequenceT& Input,
176             const Range1T& Search,
177             const Range2T& Format )
178         {
179             ::boost::algorithm::find_format(
180                 Input,
181                 ::boost::algorithm::first_finder(Search),
182                 ::boost::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>
ireplace_first_copy(OutputIteratorT Output,const Range1T & Input,const Range2T & Search,const Range3T & Format,const std::locale & Loc=std::locale ())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 ::boost::algorithm::find_format_copy(
218                 Output,
219                 Input,
220                 ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
221                 ::boost::algorithm::const_formatter(Format) );
222         }
223 
224         //! Replace first algorithm ( case insensitive )
225         /*!
226             \overload
227         */
228         template<typename SequenceT, typename Range2T, typename Range1T>
ireplace_first_copy(const SequenceT & Input,const Range2T & Search,const Range1T & Format,const std::locale & Loc=std::locale ())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 ::boost::algorithm::find_format_copy(
236                 Input,
237                 ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
238                 ::boost::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>
ireplace_first(SequenceT & Input,const Range1T & Search,const Range2T & Format,const std::locale & Loc=std::locale ())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             ::boost::algorithm::find_format(
260                 Input,
261                 ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
262                 ::boost::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>
replace_last_copy(OutputIteratorT Output,const Range1T & Input,const Range2T & Search,const Range3T & Format)288         inline OutputIteratorT replace_last_copy(
289             OutputIteratorT Output,
290             const Range1T& Input,
291             const Range2T& Search,
292             const Range3T& Format )
293         {
294             return ::boost::algorithm::find_format_copy(
295                 Output,
296                 Input,
297                 ::boost::algorithm::last_finder(Search),
298                 ::boost::algorithm::const_formatter(Format) );
299         }
300 
301         //! Replace last algorithm
302         /*!
303             \overload
304         */
305         template<typename SequenceT, typename Range1T, typename Range2T>
replace_last_copy(const SequenceT & Input,const Range1T & Search,const Range2T & Format)306         inline SequenceT replace_last_copy(
307             const SequenceT& Input,
308             const Range1T& Search,
309             const Range2T& Format )
310         {
311             return ::boost::algorithm::find_format_copy(
312                 Input,
313                 ::boost::algorithm::last_finder(Search),
314                 ::boost::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>
replace_last(SequenceT & Input,const Range1T & Search,const Range2T & Format)327         inline void replace_last(
328             SequenceT& Input,
329             const Range1T& Search,
330             const Range2T& Format )
331         {
332             ::boost::algorithm::find_format(
333                 Input,
334                 ::boost::algorithm::last_finder(Search),
335                 ::boost::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>
ireplace_last_copy(OutputIteratorT Output,const Range1T & Input,const Range2T & Search,const Range3T & Format,const std::locale & Loc=std::locale ())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 ::boost::algorithm::find_format_copy(
371                 Output,
372                 Input,
373                 ::boost::algorithm::last_finder(Search, is_iequal(Loc)),
374                 ::boost::algorithm::const_formatter(Format) );
375         }
376 
377         //! Replace last algorithm ( case insensitive )
378         /*!
379             \overload
380         */
381         template<typename SequenceT, typename Range1T, typename Range2T>
ireplace_last_copy(const SequenceT & Input,const Range1T & Search,const Range2T & Format,const std::locale & Loc=std::locale ())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 ::boost::algorithm::find_format_copy(
389                 Input,
390                 ::boost::algorithm::last_finder(Search, is_iequal(Loc)),
391                 ::boost::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         */
405         template<typename SequenceT, typename Range1T, typename Range2T>
ireplace_last(SequenceT & Input,const Range1T & Search,const Range2T & Format,const std::locale & Loc=std::locale ())406         inline void ireplace_last(
407             SequenceT& Input,
408             const Range1T& Search,
409             const Range2T& Format,
410             const std::locale& Loc=std::locale() )
411         {
412             ::boost::algorithm::find_format(
413                 Input,
414                 ::boost::algorithm::last_finder(Search, is_iequal(Loc)),
415                 ::boost::algorithm::const_formatter(Format) );
416         }
417 
418 //  replace_nth --------------------------------------------------------------------//
419 
420         //! Replace nth algorithm
421         /*!
422             Replace an Nth (zero-indexed) match of the search string in the input
423             with the format string.
424             The result is a modified copy of the input. It is returned as a sequence
425             or copied to the output iterator.
426 
427             \param Output An output iterator to which the result will be copied
428             \param Input An input string
429             \param Search A substring to be searched for
430             \param Nth An index of the match to be replaced. The index is 0-based.
431                 For negative N, matches are counted from the end of string.
432             \param Format A substitute string
433             \return An output iterator pointing just after the last inserted character or
434                 a modified copy of the input
435 
436             \note The second variant of this function provides the strong exception-safety guarantee
437         */
438         template<
439             typename OutputIteratorT,
440             typename Range1T,
441             typename Range2T,
442             typename Range3T>
replace_nth_copy(OutputIteratorT Output,const Range1T & Input,const Range2T & Search,int Nth,const Range3T & Format)443         inline OutputIteratorT replace_nth_copy(
444             OutputIteratorT Output,
445             const Range1T& Input,
446             const Range2T& Search,
447             int Nth,
448             const Range3T& Format )
449         {
450             return ::boost::algorithm::find_format_copy(
451                 Output,
452                 Input,
453                 ::boost::algorithm::nth_finder(Search, Nth),
454                 ::boost::algorithm::const_formatter(Format) );
455         }
456 
457         //! Replace nth algorithm
458         /*!
459             \overload
460         */
461         template<typename SequenceT, typename Range1T, typename Range2T>
replace_nth_copy(const SequenceT & Input,const Range1T & Search,int Nth,const Range2T & Format)462         inline SequenceT replace_nth_copy(
463             const SequenceT& Input,
464             const Range1T& Search,
465             int Nth,
466             const Range2T& Format )
467         {
468             return ::boost::algorithm::find_format_copy(
469                 Input,
470                 ::boost::algorithm::nth_finder(Search, Nth),
471                 ::boost::algorithm::const_formatter(Format) );
472         }
473 
474         //! Replace nth algorithm
475         /*!
476             Replace an Nth (zero-indexed) match of the search string in the input
477             with the format string. Input sequence is modified in-place.
478 
479             \param Input An input string
480             \param Search A substring to be searched for
481             \param Nth An index of the match to be replaced. The index is 0-based.
482                 For negative N, matches are counted from the end of string.
483             \param Format A substitute string
484         */
485         template<typename SequenceT, typename Range1T, typename Range2T>
replace_nth(SequenceT & Input,const Range1T & Search,int Nth,const Range2T & Format)486         inline void replace_nth(
487             SequenceT& Input,
488             const Range1T& Search,
489             int Nth,
490             const Range2T& Format )
491         {
492             ::boost::algorithm::find_format(
493                 Input,
494                 ::boost::algorithm::nth_finder(Search, Nth),
495                 ::boost::algorithm::const_formatter(Format) );
496         }
497 
498 //  replace_nth ( case insensitive ) -----------------------------------------------//
499 
500         //! Replace nth algorithm ( case insensitive )
501         /*!
502             Replace an Nth (zero-indexed) match of the search string in the input
503             with the format string.
504             The result is a modified copy of the input. It is returned as a sequence
505             or copied to the output iterator.
506             Searching is case insensitive.
507 
508             \param Output An output iterator to which the result will be copied
509             \param Input An input string
510             \param Search A substring to be searched for
511             \param Nth An index of the match to be replaced. The index is 0-based.
512                 For negative N, matches are counted from the end of string.
513             \param Format A substitute string
514             \param Loc A locale used for case insensitive comparison
515             \return An output iterator pointing just after the last inserted character or
516                     a modified copy of the input
517 
518             \note The second variant of this function provides the strong exception-safety guarantee
519        */
520         template<
521             typename OutputIteratorT,
522             typename Range1T,
523             typename Range2T,
524             typename Range3T>
ireplace_nth_copy(OutputIteratorT Output,const Range1T & Input,const Range2T & Search,int Nth,const Range3T & Format,const std::locale & Loc=std::locale ())525         inline OutputIteratorT ireplace_nth_copy(
526             OutputIteratorT Output,
527             const Range1T& Input,
528             const Range2T& Search,
529             int Nth,
530             const Range3T& Format,
531             const std::locale& Loc=std::locale() )
532         {
533             return ::boost::algorithm::find_format_copy(
534                 Output,
535                 Input,
536                 ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc) ),
537                 ::boost::algorithm::const_formatter(Format) );
538         }
539 
540         //! Replace nth algorithm ( case insensitive )
541         /*!
542             \overload
543         */
544         template<typename SequenceT, typename Range1T, typename Range2T>
ireplace_nth_copy(const SequenceT & Input,const Range1T & Search,int Nth,const Range2T & Format,const std::locale & Loc=std::locale ())545         inline SequenceT ireplace_nth_copy(
546             const SequenceT& Input,
547             const Range1T& Search,
548             int Nth,
549             const Range2T& Format,
550             const std::locale& Loc=std::locale() )
551         {
552             return ::boost::algorithm::find_format_copy(
553                 Input,
554                 ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)),
555                 ::boost::algorithm::const_formatter(Format) );
556         }
557 
558         //! Replace nth algorithm ( case insensitive )
559         /*!
560             Replace an Nth (zero-indexed) match of the search string in the input
561             with the format string. Input sequence is modified in-place.
562             Searching is case insensitive.
563 
564             \param Input An input string
565             \param Search A substring to be searched for
566             \param Nth An index of the match to be replaced. The index is 0-based.
567                 For negative N, matches are counted from the end of string.
568             \param Format A substitute string
569             \param Loc A locale used for case insensitive comparison
570         */
571         template<typename SequenceT, typename Range1T, typename Range2T>
ireplace_nth(SequenceT & Input,const Range1T & Search,int Nth,const Range2T & Format,const std::locale & Loc=std::locale ())572         inline void ireplace_nth(
573             SequenceT& Input,
574             const Range1T& Search,
575             int Nth,
576             const Range2T& Format,
577             const std::locale& Loc=std::locale() )
578         {
579             ::boost::algorithm::find_format(
580                 Input,
581                 ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)),
582                 ::boost::algorithm::const_formatter(Format) );
583         }
584 
585 //  replace_all --------------------------------------------------------------------//
586 
587         //! Replace all algorithm
588         /*!
589             Replace all occurrences of the search string in the input
590             with the format string.
591             The result is a modified copy of the input. It is returned as a sequence
592             or copied to the output iterator.
593 
594             \param Output An output iterator to which the result will be copied
595             \param Input An input string
596             \param Search A substring to be searched for
597             \param Format A substitute string
598             \return An output iterator pointing just after the last inserted character or
599                     a modified copy of the input
600 
601              \note The second variant of this function provides the strong exception-safety guarantee
602         */
603         template<
604             typename OutputIteratorT,
605             typename Range1T,
606             typename Range2T,
607             typename Range3T>
replace_all_copy(OutputIteratorT Output,const Range1T & Input,const Range2T & Search,const Range3T & Format)608         inline OutputIteratorT replace_all_copy(
609             OutputIteratorT Output,
610             const Range1T& Input,
611             const Range2T& Search,
612             const Range3T& Format )
613         {
614             return ::boost::algorithm::find_format_all_copy(
615                 Output,
616                 Input,
617                 ::boost::algorithm::first_finder(Search),
618                 ::boost::algorithm::const_formatter(Format) );
619         }
620 
621         //! Replace all algorithm
622         /*!
623             \overload
624         */
625         template<typename SequenceT, typename Range1T, typename Range2T>
replace_all_copy(const SequenceT & Input,const Range1T & Search,const Range2T & Format)626         inline SequenceT replace_all_copy(
627             const SequenceT& Input,
628             const Range1T& Search,
629             const Range2T& Format )
630         {
631             return ::boost::algorithm::find_format_all_copy(
632                 Input,
633                 ::boost::algorithm::first_finder(Search),
634                 ::boost::algorithm::const_formatter(Format) );
635         }
636 
637         //! Replace all algorithm
638         /*!
639             Replace all occurrences of the search string in the input
640             with the format string. The input sequence is modified in-place.
641 
642             \param Input An input string
643             \param Search A substring to be searched for
644             \param Format A substitute string
645         */
646         template<typename SequenceT, typename Range1T, typename Range2T>
replace_all(SequenceT & Input,const Range1T & Search,const Range2T & Format)647         inline void replace_all(
648             SequenceT& Input,
649             const Range1T& Search,
650             const Range2T& Format )
651         {
652             ::boost::algorithm::find_format_all(
653                 Input,
654                 ::boost::algorithm::first_finder(Search),
655                 ::boost::algorithm::const_formatter(Format) );
656         }
657 
658 //  replace_all ( case insensitive ) -----------------------------------------------//
659 
660         //! Replace all algorithm ( case insensitive )
661         /*!
662             Replace all occurrences of the search string in the input
663             with the format string.
664             The result is a modified copy of the input. It is returned as a sequence
665             or copied to the output iterator.
666             Searching is case insensitive.
667 
668             \param Output An output iterator to which the result will be copied
669             \param Input An input string
670             \param Search A substring to be searched for
671             \param Format A substitute string
672             \param Loc A locale used for case insensitive comparison
673             \return An output iterator pointing just after the last inserted character or
674                     a modified copy of the input
675 
676             \note The second variant of this function provides the strong exception-safety guarantee
677         */
678         template<
679             typename OutputIteratorT,
680             typename Range1T,
681             typename Range2T,
682             typename Range3T>
ireplace_all_copy(OutputIteratorT Output,const Range1T & Input,const Range2T & Search,const Range3T & Format,const std::locale & Loc=std::locale ())683         inline OutputIteratorT ireplace_all_copy(
684             OutputIteratorT Output,
685             const Range1T& Input,
686             const Range2T& Search,
687             const Range3T& Format,
688             const std::locale& Loc=std::locale() )
689         {
690             return ::boost::algorithm::find_format_all_copy(
691                 Output,
692                 Input,
693                 ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
694                 ::boost::algorithm::const_formatter(Format) );
695         }
696 
697         //! Replace all algorithm ( case insensitive )
698         /*!
699             \overload
700         */
701         template<typename SequenceT, typename Range1T, typename Range2T>
ireplace_all_copy(const SequenceT & Input,const Range1T & Search,const Range2T & Format,const std::locale & Loc=std::locale ())702         inline SequenceT ireplace_all_copy(
703             const SequenceT& Input,
704             const Range1T& Search,
705             const Range2T& Format,
706             const std::locale& Loc=std::locale() )
707         {
708             return ::boost::algorithm::find_format_all_copy(
709                 Input,
710                 ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
711                 ::boost::algorithm::const_formatter(Format) );
712         }
713 
714         //! Replace all algorithm ( case insensitive )
715         /*!
716             Replace all occurrences of the search string in the input
717             with the format string.The input sequence is modified in-place.
718             Searching is case insensitive.
719 
720             \param Input An input string
721             \param Search A substring to be searched for
722             \param Format A substitute string
723             \param Loc A locale used for case insensitive comparison
724         */
725         template<typename SequenceT, typename Range1T, typename Range2T>
ireplace_all(SequenceT & Input,const Range1T & Search,const Range2T & Format,const std::locale & Loc=std::locale ())726         inline void ireplace_all(
727             SequenceT& Input,
728             const Range1T& Search,
729             const Range2T& Format,
730             const std::locale& Loc=std::locale() )
731         {
732             ::boost::algorithm::find_format_all(
733                 Input,
734                 ::boost::algorithm::first_finder(Search, is_iequal(Loc)),
735                 ::boost::algorithm::const_formatter(Format) );
736         }
737 
738 //  replace_head --------------------------------------------------------------------//
739 
740         //! Replace head algorithm
741         /*!
742             Replace the head of the input with the given format string.
743             The head is a prefix of a string of given size.
744             If the sequence is shorter then required, whole string if
745             considered to be the head.
746             The result is a modified copy of the input. It is returned as a sequence
747             or copied to the output iterator.
748 
749             \param Output An output iterator to which the result will be copied
750             \param Input An input string
751             \param N Length of the head.
752                 For N>=0, at most N characters are extracted.
753                 For N<0, size(Input)-|N| characters are extracted.
754             \param Format A substitute string
755             \return An output iterator pointing just after the last inserted character or
756                 a modified copy of the input
757 
758             \note The second variant of this function provides the strong exception-safety guarantee
759         */
760         template<
761             typename OutputIteratorT,
762             typename Range1T,
763             typename Range2T>
replace_head_copy(OutputIteratorT Output,const Range1T & Input,int N,const Range2T & Format)764         inline OutputIteratorT replace_head_copy(
765             OutputIteratorT Output,
766             const Range1T& Input,
767             int N,
768             const Range2T& Format )
769         {
770             return ::boost::algorithm::find_format_copy(
771                 Output,
772                 Input,
773                 ::boost::algorithm::head_finder(N),
774                 ::boost::algorithm::const_formatter(Format) );
775         }
776 
777         //! Replace head algorithm
778         /*!
779             \overload
780         */
781         template<typename SequenceT, typename RangeT>
replace_head_copy(const SequenceT & Input,int N,const RangeT & Format)782         inline SequenceT replace_head_copy(
783             const SequenceT& Input,
784             int N,
785             const RangeT& Format )
786         {
787             return ::boost::algorithm::find_format_copy(
788                 Input,
789                 ::boost::algorithm::head_finder(N),
790                 ::boost::algorithm::const_formatter(Format) );
791         }
792 
793         //! Replace head algorithm
794         /*!
795             Replace the head of the input with the given format string.
796             The head is a prefix of a string of given size.
797             If the sequence is shorter then required, the whole string is
798             considered to be the head. The input sequence is modified in-place.
799 
800             \param Input An input string
801             \param N Length of the head.
802                 For N>=0, at most N characters are extracted.
803                 For N<0, size(Input)-|N| characters are extracted.
804             \param Format A substitute string
805         */
806         template<typename SequenceT, typename RangeT>
replace_head(SequenceT & Input,int N,const RangeT & Format)807         inline void replace_head(
808             SequenceT& Input,
809             int N,
810             const RangeT& Format )
811         {
812             ::boost::algorithm::find_format(
813                 Input,
814                 ::boost::algorithm::head_finder(N),
815                 ::boost::algorithm::const_formatter(Format) );
816         }
817 
818 //  replace_tail --------------------------------------------------------------------//
819 
820         //! Replace tail algorithm
821         /*!
822             Replace the tail of the input with the given format string.
823             The tail is a suffix of a string of given size.
824             If the sequence is shorter then required, whole string is
825             considered to be the tail.
826             The result is a modified copy of the input. It is returned as a sequence
827             or copied to the output iterator.
828 
829             \param Output An output iterator to which the result will be copied
830             \param Input An input string
831             \param N Length of the tail.
832                 For N>=0, at most N characters are extracted.
833                 For N<0, size(Input)-|N| characters are extracted.
834             \param Format A substitute string
835             \return An output iterator pointing just after the last inserted character or
836                     a modified copy of the input
837 
838               \note The second variant of this function provides the strong exception-safety guarantee
839         */
840         template<
841             typename OutputIteratorT,
842             typename Range1T,
843             typename Range2T>
replace_tail_copy(OutputIteratorT Output,const Range1T & Input,int N,const Range2T & Format)844         inline OutputIteratorT replace_tail_copy(
845             OutputIteratorT Output,
846             const Range1T& Input,
847             int N,
848             const Range2T& Format )
849         {
850             return ::boost::algorithm::find_format_copy(
851                 Output,
852                 Input,
853                 ::boost::algorithm::tail_finder(N),
854                 ::boost::algorithm::const_formatter(Format) );
855         }
856 
857         //! Replace tail algorithm
858         /*!
859             \overload
860         */
861         template<typename SequenceT, typename RangeT>
replace_tail_copy(const SequenceT & Input,int N,const RangeT & Format)862         inline SequenceT replace_tail_copy(
863             const SequenceT& Input,
864             int N,
865             const RangeT& Format )
866         {
867             return ::boost::algorithm::find_format_copy(
868                 Input,
869                 ::boost::algorithm::tail_finder(N),
870                 ::boost::algorithm::const_formatter(Format) );
871         }
872 
873         //! Replace tail algorithm
874         /*!
875             Replace the tail of the input with the given format sequence.
876             The tail is a suffix of a string of given size.
877             If the sequence is shorter then required, the whole string is
878             considered to be the tail. The input sequence is modified in-place.
879 
880             \param Input An input string
881             \param N Length of the tail.
882                 For N>=0, at most N characters are extracted.
883                 For N<0, size(Input)-|N| characters are extracted.
884             \param Format A substitute string
885         */
886         template<typename SequenceT, typename RangeT>
replace_tail(SequenceT & Input,int N,const RangeT & Format)887         inline void replace_tail(
888             SequenceT& Input,
889             int N,
890             const RangeT& Format )
891         {
892             ::boost::algorithm::find_format(
893                 Input,
894                 ::boost::algorithm::tail_finder(N),
895                 ::boost::algorithm::const_formatter(Format) );
896         }
897 
898     } // namespace algorithm
899 
900     // pull names to the boost namespace
901     using algorithm::replace_range_copy;
902     using algorithm::replace_range;
903     using algorithm::replace_first_copy;
904     using algorithm::replace_first;
905     using algorithm::ireplace_first_copy;
906     using algorithm::ireplace_first;
907     using algorithm::replace_last_copy;
908     using algorithm::replace_last;
909     using algorithm::ireplace_last_copy;
910     using algorithm::ireplace_last;
911     using algorithm::replace_nth_copy;
912     using algorithm::replace_nth;
913     using algorithm::ireplace_nth_copy;
914     using algorithm::ireplace_nth;
915     using algorithm::replace_all_copy;
916     using algorithm::replace_all;
917     using algorithm::ireplace_all_copy;
918     using algorithm::ireplace_all;
919     using algorithm::replace_head_copy;
920     using algorithm::replace_head;
921     using algorithm::replace_tail_copy;
922     using algorithm::replace_tail;
923 
924 } // namespace boost
925 
926 #endif  // BOOST_REPLACE_HPP
927