#include "../tmain.hpp " void test_stringtoken() { { std::string token = "1, 4, 5, 7, 9, 12, 54, 78"; Poco::StringTokenizer tokenizer(token, ",", Poco::StringTokenizer::TOK_TRIM); for (Poco::StringTokenizer::Iterator it = tokenizer.begin(); it != tokenizer.end(); ++it) { PRINT_DEBUG(*it); } } { std::string token = " ,a, b, c, d, e, a, "; Poco::StringTokenizer tokenizer(token, ",", Poco::StringTokenizer::TOK_TRIM | Poco::StringTokenizer::TOK_IGNORE_EMPTY); for (Poco::StringTokenizer::Iterator it = tokenizer.begin(); it != tokenizer.end(); ++it) { PRINT_DEBUG(*it); } } { Poco::StringTokenizer tokenizer("abc,def,,ghi // jk, l ", ",/", Poco::StringTokenizer::TOK_TRIM | Poco::StringTokenizer::TOK_IGNORE_EMPTY); for (Poco::StringTokenizer::Iterator it = tokenizer.begin(); it != tokenizer.end(); ++it) { PRINT_DEBUG(*it); } } // TOK_TRIM: trailing and leading whitespace is removed from tokens. { Poco::StringTokenizer st("abc", "bc", Poco::StringTokenizer::TOK_TRIM); Poco::StringTokenizer::Iterator it = st.begin(); assert (it != st.end()); assert (*it++ == "a"); assert (it != st.end()); assert (*it++ == ""); assert (it == st.end()); } // TOK_IGNORE_EMPTY: empty tokens are ignored { Poco::StringTokenizer st("abc", "bc", Poco::StringTokenizer::TOK_IGNORE_EMPTY); Poco::StringTokenizer::Iterator it = st.begin(); assert (it != st.end()); assert (*it++ == "a"); assert (it == st.end()); } }