summaryrefslogtreecommitdiff
path: root/libs/algorithm/string/example/predicate_example.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-06-25 22:59:01 +0000
committer <>2013-09-27 11:49:28 +0000
commit8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch)
treec09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/algorithm/string/example/predicate_example.cpp
downloadboost-tarball-baserock/morph.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/algorithm/string/example/predicate_example.cpp')
-rw-r--r--libs/algorithm/string/example/predicate_example.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/libs/algorithm/string/example/predicate_example.cpp b/libs/algorithm/string/example/predicate_example.cpp
new file mode 100644
index 000000000..473ab8b57
--- /dev/null
+++ b/libs/algorithm/string/example/predicate_example.cpp
@@ -0,0 +1,61 @@
+// Boost string_algo library example file ---------------------------------//
+
+// Copyright Pavol Droba 2002-2003. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#include <string>
+#include <iostream>
+#include <functional>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/bind.hpp>
+
+
+using namespace std;
+using namespace boost;
+
+int main()
+{
+ cout << "* Predicate Example *" << endl << endl;
+
+ string str1("123xxx321");
+ string str2("abc");
+
+ // Check if str1 starts with '123'
+ cout << "str1 starts with \"123\": " <<
+ (starts_with( str1, string("123") )?"true":"false") << endl;
+
+ // Check if str1 ends with '123'
+ cout << "str1 ends with \"123\": " <<
+ (ends_with( str1, string("123") )?"true":"false") << endl;
+
+ // Check if str1 contains 'xxx'
+ cout << "str1 contains \"xxx\": " <<
+ (contains( str1, string("xxx") )?"true":"false") << endl;
+
+
+ // Check if str2 equals to 'abc'
+ cout << "str2 equals \"abc\": " <<
+ (equals( str2, string("abc") )?"true":"false") << endl;
+
+
+ // Classification functors and all predicate
+ if ( all(";.,", is_punct() ) )
+ {
+ cout << "\";.,\" are all punctuation characters" << endl;
+ }
+
+ // Classification predicates can be combined
+ if ( all("abcxxx", is_any_of("xabc") && !is_space() ) )
+ {
+ cout << "true" << endl;
+ }
+
+ cout << endl;
+
+ return 0;
+}