mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Text Processing
- Implemented splitq, which can handle quoted and oddly-quoted string splits.
This commit is contained in:
parent
0308ee953a
commit
05b3fa0bb6
3 changed files with 59 additions and 5 deletions
|
@ -35,7 +35,7 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (236);
|
||||
UnitTest t (243);
|
||||
|
||||
// void wrapText (std::vector <std::string>& lines, const std::string& text, const int width)
|
||||
std::string text = "This is a test of the line wrapping code.";
|
||||
|
@ -155,6 +155,17 @@ int main (int argc, char** argv)
|
|||
t.is (items[2], "bc", "split '-a-bc-def' '--' -> [2] 'bc'");
|
||||
t.is (items[3], "def", "split '-a-bc-def' '--' -> [3] 'def'");
|
||||
|
||||
// void splitq (std::vector<std::string>&, const std::string&, const char);
|
||||
unsplit = "one 'two' '' 'three four' \"five six seven\" eight'nine ten'";
|
||||
splitq (items, unsplit, ' ');
|
||||
t.is (items.size () , (size_t) 6, "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten'");
|
||||
t.is (items[0], "one", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [0] 'one'");
|
||||
t.is (items[1], "two", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [1] 'two'");
|
||||
t.is (items[2], "", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [2] ''");
|
||||
t.is (items[3], "three four", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [3] 'three four'");
|
||||
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 join (std::string& result, const std::string& separator, const std::vector<std::string>& items)
|
||||
std::vector <std::string> unjoined;
|
||||
std::string joined;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue