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