]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/string/example/predicate_example.cpp
1 // Boost string_algo library example file ---------------------------------//
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)
8 // See http://www.boost.org for updates, documentation, and revision history.
13 #include <boost/algorithm/string/predicate.hpp>
14 #include <boost/algorithm/string/classification.hpp>
15 #include <boost/bind.hpp>
19 using namespace boost
;
23 cout
<< "* Predicate Example *" << endl
<< endl
;
25 string
str1("123xxx321");
28 // Check if str1 starts with '123'
29 cout
<< "str1 starts with \"123\": " <<
30 (starts_with( str1
, string("123") )?"true":"false") << endl
;
32 // Check if str1 ends with '123'
33 cout
<< "str1 ends with \"123\": " <<
34 (ends_with( str1
, string("123") )?"true":"false") << endl
;
36 // Check if str1 contains 'xxx'
37 cout
<< "str1 contains \"xxx\": " <<
38 (contains( str1
, string("xxx") )?"true":"false") << endl
;
41 // Check if str2 equals to 'abc'
42 cout
<< "str2 equals \"abc\": " <<
43 (equals( str2
, string("abc") )?"true":"false") << endl
;
46 // Classification functors and all predicate
47 if ( all(";.,", is_punct() ) )
49 cout
<< "\";.,\" are all punctuation characters" << endl
;
52 // Classification predicates can be combined
53 if ( all("abcxxx", is_any_of("xabc") && !is_space() ) )
55 cout
<< "true" << endl
;