diff --git a/src/text.cpp b/src/text.cpp index 0271ea07b..b79438169 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,21 @@ void wrapText ( //////////////////////////////////////////////////////////////////////////////// // UTF-8 +// +// Splits on unicode whitespace, removeѕ quotes. +void splitq (std::vector & results, const std::string& input) +{ + results.clear (); + + std::string token; + Lexer::Type type; + Lexer lex (input); + while (lex.token (token, type)) + results.push_back (token); +} + +//////////////////////////////////////////////////////////////////////////////// +// TODO Obsolete this call. void splitq ( std::vector& results, const std::string& input, diff --git a/src/text.h b/src/text.h index 8414eb1cd..c55dccad7 100644 --- a/src/text.h +++ b/src/text.h @@ -39,6 +39,7 @@ std::string unquoteText (const std::string&); int longestWord (const std::string&); int longestLine (const std::string&); bool extractLine (std::string&, const std::string&, int, bool, unsigned int&); +void splitq (std::vector&, const std::string&); void splitq (std::vector&, const std::string&, const char); void split (std::vector&, const std::string&, const char); void split (std::vector&, const std::string&, const std::string&); diff --git a/test/text.t.cpp b/test/text.t.cpp index 2d9d655ed..8b733cd97 100644 --- a/test/text.t.cpp +++ b/test/text.t.cpp @@ -37,7 +37,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (264); + UnitTest t (270); // Ensure environment has no influence. unsetenv ("TASKDATA"); @@ -183,6 +183,16 @@ int main (int argc, char** argv) t.is (items[4], "five six seven", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [4] 'five six seven'"); t.is (items[5], "eight'nine ten'", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [4] 'eight\\'nine ten\\''"); + // void splitq (std::vector&, const std::string&); + unsplit = " ( A or B ) "; + splitq (items, unsplit); + t.is (items.size (), (size_t) 5, "splitq ' ( A or B ) '"); + t.is (items[0], "(", "splitq ' ( A or B ) ' -> [0] '('"); + t.is (items[1], "A", "splitq ' ( A or B ) ' -> [1] 'A'"); + t.is (items[2], "or", "splitq ' ( A or B ) ' -> [2] 'or'"); + t.is (items[3], "B", "splitq ' ( A or B ) ' -> [3] 'B'"); + t.is (items[4], ")", "splitq ' ( A or B ) ' -> [4] ')'"); + // void join (std::string& result, const std::string& separator, const std::vector& items) std::vector unjoined; std::string joined;