1 // Boost string_algo library example file ---------------------------------//
2
3 // Copyright Pavol Droba 2002-2003. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 // See http://www.boost.org for updates, documentation, and revision history.
9
10 #include <string>
11 #include <iostream>
12 #include <algorithm>
13 #include <functional>
14 #include <boost/algorithm/string/case_conv.hpp>
15 #include <boost/algorithm/string/find.hpp>
16
17 using namespace std;
18 using namespace boost;
19
main()20 int main()
21 {
22 cout << "* Find Example *" << endl << endl;
23
24 string str1("abc___cde___efg");
25 string str2("abc");
26
27 // find "cde" substring
28 iterator_range<string::iterator> range=find_first( str1, string("cde") );
29
30 // convert a substring to upper case
31 // note that iterator range can be directly passed to the algorithm
32 to_upper( range );
33
34 cout << "str1 with upper-cased part matching cde: " << str1 << endl;
35
36 // get a head of the string
37 iterator_range<string::iterator> head=find_head( str1, 3 );
38 cout << "head(3) of the str1: " << string( head.begin(), head.end() ) << endl;
39
40 // get the tail
41 head=find_tail( str2, 5 );
42 cout << "tail(5) of the str2: " << string( head.begin(), head.end() ) << endl;
43
44 // char processing
45 char text[]="hello dolly!";
46 iterator_range<char*> crange=find_last(text,"ll");
47
48 // transform the range ( add 1 )
49 transform( crange.begin(), crange.end(), crange.begin(), bind2nd( plus<char>(), 1 ) );
50 // uppercase the range
51 to_upper( crange );
52
53 cout << text << endl;
54
55 cout << endl;
56
57 return 0;
58 }
59