]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/string/example/predicate_example.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / algorithm / string / example / predicate_example.cpp
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 <functional>
13 #include <boost/algorithm/string/predicate.hpp>
14 #include <boost/algorithm/string/classification.hpp>
15
16 using namespace std;
17 using namespace boost;
18
19 int main()
20 {
21 cout << "* Predicate Example *" << endl << endl;
22
23 string str1("123xxx321");
24 string str2("abc");
25
26 // Check if str1 starts with '123'
27 cout << "str1 starts with \"123\": " <<
28 (starts_with( str1, string("123") )?"true":"false") << endl;
29
30 // Check if str1 ends with '123'
31 cout << "str1 ends with \"123\": " <<
32 (ends_with( str1, string("123") )?"true":"false") << endl;
33
34 // Check if str1 contains 'xxx'
35 cout << "str1 contains \"xxx\": " <<
36 (contains( str1, string("xxx") )?"true":"false") << endl;
37
38
39 // Check if str2 equals to 'abc'
40 cout << "str2 equals \"abc\": " <<
41 (equals( str2, string("abc") )?"true":"false") << endl;
42
43
44 // Classification functors and all predicate
45 if ( all(";.,", is_punct() ) )
46 {
47 cout << "\";.,\" are all punctuation characters" << endl;
48 }
49
50 // Classification predicates can be combined
51 if ( all("abcxxx", is_any_of("xabc") && !is_space() ) )
52 {
53 cout << "true" << endl;
54 }
55
56 cout << endl;
57
58 return 0;
59 }