2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								<?xml version="1.0" encoding="utf-8"?>  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< !DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
							 
						 
					
						
							
								
									
										
										
										
											2006-08-16 07:10:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-11-25 18:38:02 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-08-16 07:10:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								<!--  Copyright (c) 2002 - 2006 Pavol Droba.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     Subject to the Boost Software License, Version 1.0. 
							 
						 
					
						
							
								
									
										
											 
										
											
												Merged revisions 43211,43214-43219,43222-43225,43227-43238,43242,43244-43245,43249-43250,43257-43259,43261,43263,43265,43267-43268,43270-43271,43273,43275-43279,43284-43289,43291,43295,43297-43298,43304-43305,43307,43313,43315,43324,43326-43327,43331,43333,43339-43343,43345,43348,43350,43352-43353,43355-43356,43358,43360,43366-43367,43369-43370,43372-43376,43378-43389,43394,43396-43398,43400-43401,43403-43404,43406-43408,43413-43415,43417-43418,43420,43422-43423 via svnmerge from 
https://svn.boost.org/svn/boost/trunk
........
  r43417 | danieljames | 2008-02-26 22:04:55 +0000 (Tue, 26 Feb 2008) | 2 lines
  
  Fix a link to Boost.Bimap.
........
  r43418 | danieljames | 2008-02-26 22:07:25 +0000 (Tue, 26 Feb 2008) | 2 lines
  
  Change another link that's no longer in the repository to link to the website.
........
  r43422 | danieljames | 2008-02-27 18:51:14 +0000 (Wed, 27 Feb 2008) | 1 line
  
  Fix broken copyright urls. Fixes #1573.
........
  r43423 | danieljames | 2008-02-27 19:22:01 +0000 (Wed, 27 Feb 2008) | 1 line
  
  Fix incorrect links to copyright of the form 'http:#www.boost.org
........
[SVN r43425]
											 
										 
										
											2008-02-27 20:00:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     (See accompanying file LICENSE_1_0.txt or  http://www.boost.org/LICENSE_1_0.txt)
							 
						 
					
						
							
								
									
										
										
										
											2006-08-16 07:10:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-->
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-11-25 18:38:02 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								<section  id= "string_algo.usage"  last-revision= "$Date$" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <title > Usage</title> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <using-namespace  name= "boost" /> 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    <using-namespace  name= "boost::algorithm" /> 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <title > First Example</title> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Using the algorithms is straightforward. Let us have a look at the first example:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <programlisting > 
							 
						 
					
						
							
								
									
										
										
										
											2004-08-03 17:09:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    #include < boost/algorithm/string.hpp> 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    using namespace std;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    using namespace boost;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    string str1(" hello world! ");
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    to_upper(str1);  // str1 == " HELLO WORLD! "
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    trim(str1);      // str1 == "HELLO WORLD!"
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    string str2=
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       to_lower_copy(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          ireplace_first_copy(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								             str1,"hello","goodbye")); // str2 == "goodbye world!"
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </programlisting> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            This example converts str1 to upper case and trims spaces from the start and the end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            of the string. str2 is then created as a copy of str1 with "hello" replaced with "goodbye".
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            This example demonstrates several important concepts used in the library:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <itemizedlist > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            <listitem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                <para > <emphasis  role= "bold" > Container parameters:</emphasis> 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    Unlike in the STL algorithms, parameters are not specified only in the form
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    of iterators. The STL convention allows for great flexibility,
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    but it has several limitations. It is not possible to <emphasis > stack</emphasis>  algorithms together, 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    because a container is passed in two parameters. Therefore it is not possible to use 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    a return value from another algorithm. It is considerably easier to write
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    <code > to_lower(str1)</code> , than <code > to_lower(str1.begin(), str1.end())</code> .
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                <para > 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-15 21:05:00 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    The magic of <ulink  url= "../../libs/range/index.html" > Boost.Range</ulink>  
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    provides a uniform way of handling different string types. 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    If there is a need to pass a pair of iterators, 
							 
						 
					
						
							
								
									
										
										
										
											2010-10-30 17:34:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    <ulink  url= "../../libs/range/doc/html/range/reference/utilities/iterator_range.html" > <code > boost::iterator_range</code> </ulink> 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    can be used to package iterators into a structure with a compatible interface.
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            </listitem> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            <listitem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                <para > <emphasis  role= "bold" > Copy vs. Mutable:</emphasis> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    Many algorithms in the library are performing a transformation of the input. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    The transformation can be done in-place, mutating the input sequence, or a copy 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    of the transformed input can be created, leaving the input intact. None of 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    these possibilities is superior to the other one and both have different 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    advantages and disadvantages. For this reason, both are provided with the library. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            </listitem> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            <listitem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                <para > <emphasis  role= "bold" > Algorithm stacking:</emphasis> 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    Copy versions return a transformed input as a result, thus allow a simple chaining of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    transformations within one expression (i.e. one can write <code > trim_copy(to_upper_copy(s))</code> ). 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 22:17:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    Mutable versions have <code > void</code>  return, to avoid misuse.
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            </listitem> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            <listitem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                <para > <emphasis  role= "bold" > Naming:</emphasis> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    Naming follows the conventions from the Standard C++ Library. If there is a 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    copy and a mutable version of the same algorithm, the mutable version has no suffix 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    and the copy version has the suffix <emphasis > _copy</emphasis> . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    Some algorithms have the prefix <emphasis > i</emphasis>  
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    (e.g. <functionname > ifind_first()</functionname> ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    This prefix identifies that the algorithm works in a case-insensitive manner.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            </listitem> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </itemizedlist> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            To use the library, include the <headername > boost/algorithm/string.hpp</headername>  header. 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            If the regex related functions are needed, include the 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            <headername > boost/algorithm/string_regex.hpp</headername>  header.
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    </section> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <title > Case conversion</title> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            STL has a nice way of converting character case. Unfortunately, it works only
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            for a single character and we want to convert a string, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <programlisting > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    string str1("HeLlO WoRld!");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    to_upper(str1); // str1=="HELLO WORLD!"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </programlisting> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            <functionname > to_upper()</functionname>  and <functionname > to_lower()</functionname>  convert the case of 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            characters in a string using a specified locale.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            For more information see the reference for <headername > boost/algorithm/string/case_conv.hpp</headername> .
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    </section> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <title > Predicates and Classification</title> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            A part of the library deals with string related predicates. Consider this example:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <programlisting > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bool is_executable( string&  filename )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            iends_with(filename, ".exe") ||
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            iends_with(filename, ".com");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    string str1("command.com");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    cout 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < <  str1
							 
						 
					
						
							
								
									
										
										
										
											2012-08-16 05:16:42 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        < <  (is_executable(str1)? "is": "is not") 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        < <  "an executable" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < <  endl; // prints "command.com is an executable"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    //..
							 
						 
					
						
							
								
									
										
										
										
											2012-05-23 16:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    char text1[]="hello";
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    cout 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < <  text1 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-23 16:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        < <  (all( text1, is_lower() )? " is": " is not")
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        < <  " written in the lower case" 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-23 16:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        < <  endl; // prints "hello is written in the lower case"
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </programlisting> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            The predicates determine whether if a substring is contained in the input string
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            under various conditions. The conditions are: a string starts with the substring, 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            ends with the substring, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            simply contains the substring or if both strings are equal. See the reference for 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            <headername > boost/algorithm/string/predicate.hpp</headername>  for more details. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-23 16:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        <para >   
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Note that if we had used "hello world" as the input to the test, it would have
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            output "hello world is not written in the lower case" because the space in the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            input string is not a lower case letter.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        <para >   
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            In addition the algorithm <functionname > all()</functionname>  checks
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            all elements of a container to satisfy a condition specified by a predicate. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            This predicate can be any unary predicate, but the library provides a bunch of 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            useful string-related predicates and combinators ready for use.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            These are located in the <headername > boost/algorithm/string/classification.hpp</headername>  header.
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Classification predicates can be combined using logical combinators to form
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            a more complex expressions. For example: <code > is_from_range('a','z') || is_digit()</code> 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    </section> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <title > Trimming</title> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2012-05-23 16:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            When parsing the input from a user, strings often have unwanted leading or trailing 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            characters. To get rid of them, we need trim functions:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <programlisting > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    string str1="     hello world!     ";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    string str2=trim_left_copy(str1);   // str2 == "hello world!     "
							 
						 
					
						
							
								
									
										
										
										
											2010-07-10 20:29:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    string str3=trim_right_copy(str1);  // str3 == "     hello world!"
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    trim(str1);                         // str1 == "hello world!"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    string phone="00423333444";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // remove leading 0 from the phone number
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    trim_left_if(phone,is_any_of("0")); // phone == "423333444"
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </programlisting> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            It is possible to trim the spaces on the right, on the left or on both sides of a string.
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            And for those cases when there is a need to remove something else than blank space, there
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            are <emphasis > _if</emphasis>  variants. Using these, a user can specify a functor which will 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            select the <emphasis > space</emphasis>  to be removed. It is possible to use classification 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            predicates like <functionname > is_digit()</functionname>  mentioned in the previous paragraph.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            See the reference for the <headername > boost/algorithm/string/trim.hpp</headername> .
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    </section> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <title > Find algorithms</title> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            The library contains a set of find algorithms. Here is an example:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <programlisting > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    char text[]="hello dolly!";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    iterator_range< char*>  result=find_last(text,"ll");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    transform( result.begin(), result.end(), result.begin(), bind2nd(plus< char> (), 1) );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // text = "hello dommy!"            
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    to_upper(result); // text == "hello doMMy!"
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // iterator_range is convertible to bool
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if(find_first(text, "dolly"))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        cout < <  "Dolly is there" < <  endl;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </programlisting> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            We have used <functionname > find_last()</functionname>  to search the <code > text</code>  for "ll".
							 
						 
					
						
							
								
									
										
										
										
											2010-10-30 17:34:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            The result is given in the <ulink  url= "../../libs/range/doc/html/range/reference/utilities/iterator_range.html" > <code > boost::iterator_range</code> </ulink> . 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            This range delimits the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            part of the input which satisfies the find criteria. In our example it is the last occurrence of "ll".
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            As we can see, input of the <functionname > find_last()</functionname>  algorithm can be also 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            char[] because this type is supported by 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-08 03:23:02 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            <ulink  url= "../../libs/range/index.html" > Boost.Range</ulink> .
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            The following lines transform the result. Notice that 
							 
						 
					
						
							
								
									
										
										
										
											2010-10-30 17:34:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            <ulink  url= "../../libs/range/doc/html/range/reference/utilities/iterator_range.html" > <code > boost::iterator_range</code> </ulink>  has familiar 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            <code > begin()</code>  and <code > end()</code>  methods, so it can be used like any other STL container.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Also it is convertible to bool therefore it is easy to use find algorithms for a simple containment checking.
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Find algorithms are located in <headername > boost/algorithm/string/find.hpp</headername> .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    </section> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <title > Replace Algorithms</title> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Find algorithms can be used for searching for a specific part of string. Replace goes one step
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            further. After a matching part is found, it is substituted with something else. The substitution is computed
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            from the original, using some transformation. 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <programlisting > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    string str1="Hello  Dolly,   Hello World!"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    replace_first(str1, "Dolly", "Jane");      // str1 == "Hello  Jane,   Hello World!"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    replace_last(str1, "Hello", "Goodbye");    // str1 == "Hello  Jane,   Goodbye World!"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    erase_all(str1, " ");                      // str1 == "HelloJane,GoodbyeWorld!"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    erase_head(str1, 6);                       // str1 == "Jane,GoodbyeWorld!"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </programlisting> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            For the complete list of replace and erase functions see the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            <link  linkend= "string_algo.reference" > reference</link> .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            There is a lot of predefined function for common usage, however, the library allows you to 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            define a custom <code > replace()</code>  that suits a specific need. There is a generic <functionname > find_format()</functionname>  
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            function which takes two parameters.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            The first one is a <link  linkend= "string_algo.finder_concept" > Finder</link>  object, the second one is 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            a <link  linkend= "string_algo.formatter_concept" > Formatter</link>  object. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            The Finder object is a functor which performs the searching for the replacement part. The Formatter object
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            takes the result of the Finder (usually a reference to the found substring) and creates a 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            substitute for it. Replace algorithm puts these two together and makes the desired substitution. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Check <headername > boost/algorithm/string/replace.hpp</headername> , <headername > boost/algorithm/string/erase.hpp</headername>  and
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            <headername > boost/algorithm/string/find_format.hpp</headername>  for reference.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    </section> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <title > Find Iterator</title> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            An extension to find algorithms it the Find Iterator. Instead of searching for just a one part of a string, 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 22:17:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            the find iterator allows us to iterate over the substrings matching the specified criteria.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            This facility is using the <link  linkend= "string_algo.finder_concept" > Finder</link>  to incrementally
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            search the string. 
							 
						 
					
						
							
								
									
										
										
										
											2010-10-30 17:34:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Dereferencing a find iterator yields an <ulink  url= "../../libs/range/doc/html/range/reference/utilities/iterator_range.html" > <code > boost::iterator_range</code> </ulink>  
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            object, that delimits the current match.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            There are two iterators provided <classname > find_iterator</classname>  and 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            <classname > split_iterator</classname> . The former iterates over substrings that are found using the specified
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Finder. The latter iterates over the gaps between these substrings.
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <programlisting > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    string str1("abc-*-ABC-*-aBc");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Find all 'abc' substrings (ignoring the case)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Create a find_iterator
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    typedef find_iterator< string::iterator>  string_find_iterator;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for(string_find_iterator It=
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            make_find_iterator(str1, first_finder("abc", is_iequal()));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        It!=string_find_iterator();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ++It)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {
							 
						 
					
						
							
								
									
										
										
										
											2005-04-15 21:05:00 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        cout < <  copy_range< std::string> (*It) < <  endl;
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Output will be:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // abc
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // ABC
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // aBC
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    typedef split_iterator< string::iterator>  string_split_iterator;
							 
						 
					
						
							
								
									
										
										
										
											2007-01-30 07:59:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    for(string_split_iterator It=
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        make_split_iterator(str1, first_finder("-*-", is_iequal()));
							 
						 
					
						
							
								
									
										
										
										
											2007-01-30 07:59:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        It!=string_split_iterator();
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ++It)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    {
							 
						 
					
						
							
								
									
										
										
										
											2005-04-15 21:05:00 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        cout < <  copy_range< std::string> (*It) < <  endl;
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Output will be:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // abc
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // ABC
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // aBC
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </programlisting> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-15 21:47:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Note that the find iterators have only one template parameter. It is the base iterator type.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            The Finder is specified at runtime. This allows us to typedef a find iterator for
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            common string types and reuse it. Additionally make_*_iterator functions help
							 
						 
					
						
							
								
									
										
										
										
											2005-05-14 19:11:09 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            to construct a find iterator for a particular range.
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            See the reference in <headername > boost/algorithm/string/find_iterator.hpp</headername> .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    </section> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <title > Split</title> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Split algorithms are an extension to the find iterator for one common usage scenario.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            These algorithms use a find iterator and store all matches into the provided
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            container. This container must be able to hold copies (e.g. <code > std::string</code> ) or 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            references (e.g. <code > iterator_range</code> ) of the extracted substrings.
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Two algorithms are provided. <functionname > find_all()</functionname>  finds all copies
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            of a string in the input. <functionname > split()</functionname>  splits the input into parts.
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <programlisting > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    string str1("hello abc-*-ABC-*-aBc goodbye");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    typedef vector<  iterator_range< string::iterator>  >  find_vector_type;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    find_vector_type FindVec; // #1: Search for separators
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ifind_all( FindVec, str1, "abc" ); // FindVec == { [abc],[ABC],[aBc] }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-07-16 09:06:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    typedef vector<  string >  split_vector_type;
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    split_vector_type SplitVec; // #2: Search for tokens
							 
						 
					
						
							
								
									
										
										
										
											2010-07-10 20:29:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    split( SplitVec, str1, is_any_of("-*"), token_compress_on ); // SplitVec == { "hello abc","ABC","aBc goodbye" }
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </programlisting> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            <code > [hello]</code>  designates an <code > iterator_range</code>  delimiting this substring.                       
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            First example show how to construct a container to hold references to all extracted
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            substrings. Algorithm <functionname > ifind_all()</functionname>  puts into FindVec references
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            to all substrings that are in case-insensitive manner equal to "abc".
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Second example uses <functionname > split()</functionname>  to split string str1 into parts
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            separated by characters '-' or '*'. These parts are then put into the SplitVec.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            It is possible to specify if adjacent separators are concatenated or not.
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        <para > 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 21:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            More information can be found in the reference: <headername > boost/algorithm/string/split.hpp</headername> .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        </para> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   </section> 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-04 22:12:19 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								</section>