Mercurial > hg > svcore
diff base/test/TestStringBits.h @ 1854:bde22957545e
Add support for doubling escapes for quotes in quoted texts in CSV-like formats on import (similar to how we, and the relevant RFC, do escaping on export now)
author | Chris Cannam |
---|---|
date | Mon, 11 May 2020 14:43:58 +0100 |
parents | 64ef24ebb19c |
children |
line wrap: on
line diff
--- a/base/test/TestStringBits.h Wed May 06 09:08:06 2020 +0100 +++ b/base/test/TestStringBits.h Mon May 11 14:43:58 2020 +0100 @@ -44,6 +44,35 @@ } private slots: + void empty() { + QString in = ""; + QStringList out; + testSplitQuoted(in, out); + } + + void empties() { + + // Behaviour here differs based on what the separator is + // (spaces are coalesced) + + QString in; + QStringList out; + out << "" << ""; + + in = " "; + QCOMPARE(StringBits::splitQuoted(in, ' '), out); + + in = ","; + QCOMPARE(StringBits::splitQuoted(in, ','), out); + + in = " "; + QCOMPARE(StringBits::splitQuoted(in, ' '), out); + + in = ",,"; + out << ""; + QCOMPARE(StringBits::splitQuoted(in, ','), out); + } + void simple() { QString in = "a b c d"; QStringList out; @@ -107,6 +136,20 @@ testSplitQuoted(in, out); } + void ddescaped() { + QString in = "a \"b c\"\" d\""; + QStringList out; + out << "a" << "b c\" d"; + testSplitQuoted(in, out); + } + + void sdescaped() { + QString in = "a 'b c'' d'"; + QStringList out; + out << "a" << "b c' d"; + testSplitQuoted(in, out); + } + void dnested() { QString in = "a \"b c' d\""; QStringList out; @@ -179,7 +222,7 @@ void multispace() { QString in = " a'a \\' 'bb' ' \\\"cc\" ' dd\\\" '"; QStringList out; - out << "a'a" << "'" << "bb" << " \"cc\" " << "dd\"" << "'"; + out << "" << "a'a" << "'" << "bb" << " \"cc\" " << "dd\"" << "'"; QCOMPARE(StringBits::splitQuoted(in, ' '), out); QString in2 = ",,a'a,\\',,,,,,,,,'bb',,,,',,,,,,\\\"cc\",',dd\\\",'";