[go: up one dir, main page]

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
17using namespace std;
18using namespace boost;
19
20int 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( Input&: str1, Search: 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( Input&: 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( Input&: str1, N: 3 );
38 cout << "head(3) of the str1: " << string( head.begin(), head.end() ) << endl;
39
40 // get the tail
41 head=find_tail( Input&: str2, N: 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(Input&: text,Search: "ll");
47
48 // transform the range ( add 1 )
49 transform( first: crange.begin(), last: crange.end(), result: crange.begin(), unary_op: bind2nd( fn: plus<char>(), x: 1 ) );
50 // uppercase the range
51 to_upper( Input&: crange );
52
53 cout << text << endl;
54
55 cout << endl;
56
57 return 0;
58}
59

source code of boost/libs/algorithm/string/example/find_example.cpp