]>
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>
17 using namespace boost
;
21 cout
<< "* Predicate Example *" << endl
<< endl
;
23 string
str1("123xxx321");
26 // Check if str1 starts with '123'
27 cout
<< "str1 starts with \"123\": " <<
28 (starts_with( str1
, string("123") )?"true":"false") << endl
;
30 // Check if str1 ends with '123'
31 cout
<< "str1 ends with \"123\": " <<
32 (ends_with( str1
, string("123") )?"true":"false") << endl
;
34 // Check if str1 contains 'xxx'
35 cout
<< "str1 contains \"xxx\": " <<
36 (contains( str1
, string("xxx") )?"true":"false") << endl
;
39 // Check if str2 equals to 'abc'
40 cout
<< "str2 equals \"abc\": " <<
41 (equals( str2
, string("abc") )?"true":"false") << endl
;
44 // Classification functors and all predicate
45 if ( all(";.,", is_punct() ) )
47 cout
<< "\";.,\" are all punctuation characters" << endl
;
50 // Classification predicates can be combined
51 if ( all("abcxxx", is_any_of("xabc") && !is_space() ) )
53 cout
<< "true" << endl
;