summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/tokenizer/test/examples.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/tokenizer/test/examples.cpp
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/tokenizer/test/examples.cpp')
-rw-r--r--src/boost/libs/tokenizer/test/examples.cpp150
1 files changed, 150 insertions, 0 deletions
diff --git a/src/boost/libs/tokenizer/test/examples.cpp b/src/boost/libs/tokenizer/test/examples.cpp
new file mode 100644
index 00000000..1e0b69b8
--- /dev/null
+++ b/src/boost/libs/tokenizer/test/examples.cpp
@@ -0,0 +1,150 @@
+// Boost tokenizer examples -------------------------------------------------//
+
+// (c) Copyright John R. Bandela 2001.
+
+// Distributed under 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 <iostream>
+#include <iterator>
+#include <string>
+#include <algorithm>
+#include <boost/tokenizer.hpp>
+#include <boost/array.hpp>
+
+#include <boost/test/minimal.hpp>
+
+int test_main( int /*argc*/, char* /*argv*/[] )
+{
+ using namespace boost;
+
+ // Use tokenizer
+ {
+ const std::string test_string = ";;Hello|world||-foo--bar;yow;baz|";
+ std::string answer[] = { "Hello", "world", "foo", "bar", "yow", "baz" };
+ typedef tokenizer<char_separator<char> > Tok;
+ char_separator<char> sep("-;|");
+ Tok t(test_string, sep);
+ BOOST_REQUIRE(std::equal(t.begin(),t.end(),answer));
+ }
+ {
+ const std::string test_string = ";;Hello|world||-foo--bar;yow;baz|";
+ std::string answer[] = { "", "", "Hello", "|", "world", "|", "", "|", "",
+ "foo", "", "bar", "yow", "baz", "|", "" };
+ typedef tokenizer<char_separator<char> > Tok;
+ char_separator<char> sep("-;", "|", boost::keep_empty_tokens);
+ Tok t(test_string, sep);
+ BOOST_REQUIRE(std::equal(t.begin(), t.end(), answer));
+ }
+ {
+ const std::string test_string = "This,,is, a.test..";
+ std::string answer[] = {"This","is","a","test"};
+ typedef tokenizer<> Tok;
+ Tok t(test_string);
+ BOOST_REQUIRE(std::equal(t.begin(),t.end(),answer));
+ }
+
+ {
+ const std::string test_string = "Field 1,\"embedded,comma\",quote \\\", escape \\\\";
+ std::string answer[] = {"Field 1","embedded,comma","quote \""," escape \\"};
+ typedef tokenizer<escaped_list_separator<char> > Tok;
+ Tok t(test_string);
+ BOOST_REQUIRE(std::equal(t.begin(),t.end(),answer));
+ }
+
+ {
+ const std::string test_string = ",1,;2\\\";3\\;,4,5^\\,\'6,7\';";
+ std::string answer[] = {"","1","","2\"","3;","4","5\\","6,7",""};
+ typedef tokenizer<escaped_list_separator<char> > Tok;
+ escaped_list_separator<char> sep("\\^",",;","\"\'");
+ Tok t(test_string,sep);
+ BOOST_REQUIRE(std::equal(t.begin(),t.end(),answer));
+ }
+
+ {
+ const std::string test_string = "12252001";
+ std::string answer[] = {"12","25","2001"};
+ typedef tokenizer<offset_separator > Tok;
+ boost::array<int,3> offsets = {{2,2,4}};
+ offset_separator func(offsets.begin(),offsets.end());
+ Tok t(test_string,func);
+ BOOST_REQUIRE(std::equal(t.begin(),t.end(),answer));
+ }
+
+ // Use token_iterator_generator
+ {
+ const std::string test_string = "This,,is, a.test..";
+ std::string answer[] = {"This","is","a","test"};
+ typedef token_iterator_generator<char_delimiters_separator<char> >::type Iter;
+ Iter begin = make_token_iterator<std::string>(test_string.begin(),
+ test_string.end(),char_delimiters_separator<char>());
+ Iter end;
+ BOOST_REQUIRE(std::equal(begin,end,answer));
+ }
+
+ {
+ const std::string test_string = "Field 1,\"embedded,comma\",quote \\\", escape \\\\";
+ std::string answer[] = {"Field 1","embedded,comma","quote \""," escape \\"};
+ typedef token_iterator_generator<escaped_list_separator<char> >::type Iter;
+ Iter begin = make_token_iterator<std::string>(test_string.begin(),
+ test_string.end(),escaped_list_separator<char>());
+ Iter begin_c(begin);
+ Iter end;
+ BOOST_REQUIRE(std::equal(begin,end,answer));
+
+ while(begin_c != end)
+ {
+ BOOST_REQUIRE(begin_c.at_end() == 0);
+ ++begin_c;
+ }
+ BOOST_REQUIRE(begin_c.at_end());
+ }
+
+ {
+ const std::string test_string = "12252001";
+ std::string answer[] = {"12","25","2001"};
+ typedef token_iterator_generator<offset_separator>::type Iter;
+ boost::array<int,3> offsets = {{2,2,4}};
+ offset_separator func(offsets.begin(),offsets.end());
+ Iter begin = make_token_iterator<std::string>(test_string.begin(),
+ test_string.end(),func);
+ Iter end= make_token_iterator<std::string>(test_string.end(),
+ test_string.end(),func);
+ BOOST_REQUIRE(std::equal(begin,end,answer));
+ }
+
+ // Test copying
+ {
+ const std::string test_string = "abcdef";
+ token_iterator_generator<offset_separator>::type beg, end, other;
+ boost::array<int,3> ar = {{1,2,3}};
+ offset_separator f(ar.begin(),ar.end());
+ beg = make_token_iterator<std::string>(test_string.begin(),test_string.end(),f);
+
+ ++beg;
+ other = beg;
+ ++other;
+
+ BOOST_REQUIRE(*beg=="bc");
+ BOOST_REQUIRE(*other=="def");
+
+ other = make_token_iterator<std::string>(test_string.begin(),
+ test_string.end(),f);
+
+ BOOST_REQUIRE(*other=="a");
+ }
+
+ // Test non-default constructed char_delimiters_separator
+ {
+ const std::string test_string = "how,are you, doing";
+ std::string answer[] = {"how",",","are you",","," doing"};
+ tokenizer<> t(test_string,char_delimiters_separator<char>(true,",",""));
+ BOOST_REQUIRE(std::equal(t.begin(),t.end(),answer));
+ }
+
+ return 0;
+}
+