comparison 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
comparison
equal deleted inserted replaced
1853:f36fef97ac81 1854:bde22957545e
42 } 42 }
43 QCOMPARE(StringBits::splitQuoted(in2, ','), out2); 43 QCOMPARE(StringBits::splitQuoted(in2, ','), out2);
44 } 44 }
45 45
46 private slots: 46 private slots:
47 void empty() {
48 QString in = "";
49 QStringList out;
50 testSplitQuoted(in, out);
51 }
52
53 void empties() {
54
55 // Behaviour here differs based on what the separator is
56 // (spaces are coalesced)
57
58 QString in;
59 QStringList out;
60 out << "" << "";
61
62 in = " ";
63 QCOMPARE(StringBits::splitQuoted(in, ' '), out);
64
65 in = ",";
66 QCOMPARE(StringBits::splitQuoted(in, ','), out);
67
68 in = " ";
69 QCOMPARE(StringBits::splitQuoted(in, ' '), out);
70
71 in = ",,";
72 out << "";
73 QCOMPARE(StringBits::splitQuoted(in, ','), out);
74 }
75
47 void simple() { 76 void simple() {
48 QString in = "a b c d"; 77 QString in = "a b c d";
49 QStringList out; 78 QStringList out;
50 out << "a" << "b" << "c" << "d"; 79 out << "a" << "b" << "c" << "d";
51 testSplitQuoted(in, out); 80 testSplitQuoted(in, out);
100 testSplitQuoted(in, out); 129 testSplitQuoted(in, out);
101 } 130 }
102 131
103 void sescaped() { 132 void sescaped() {
104 QString in = "a 'b c\\' d'"; 133 QString in = "a 'b c\\' d'";
134 QStringList out;
135 out << "a" << "b c' d";
136 testSplitQuoted(in, out);
137 }
138
139 void ddescaped() {
140 QString in = "a \"b c\"\" d\"";
141 QStringList out;
142 out << "a" << "b c\" d";
143 testSplitQuoted(in, out);
144 }
145
146 void sdescaped() {
147 QString in = "a 'b c'' d'";
105 QStringList out; 148 QStringList out;
106 out << "a" << "b c' d"; 149 out << "a" << "b c' d";
107 testSplitQuoted(in, out); 150 testSplitQuoted(in, out);
108 } 151 }
109 152
177 } 220 }
178 221
179 void multispace() { 222 void multispace() {
180 QString in = " a'a \\' 'bb' ' \\\"cc\" ' dd\\\" '"; 223 QString in = " a'a \\' 'bb' ' \\\"cc\" ' dd\\\" '";
181 QStringList out; 224 QStringList out;
182 out << "a'a" << "'" << "bb" << " \"cc\" " << "dd\"" << "'"; 225 out << "" << "a'a" << "'" << "bb" << " \"cc\" " << "dd\"" << "'";
183 QCOMPARE(StringBits::splitQuoted(in, ' '), out); 226 QCOMPARE(StringBits::splitQuoted(in, ' '), out);
184 227
185 QString in2 = ",,a'a,\\',,,,,,,,,'bb',,,,',,,,,,\\\"cc\",',dd\\\",'"; 228 QString in2 = ",,a'a,\\',,,,,,,,,'bb',,,,',,,,,,\\\"cc\",',dd\\\",'";
186 QStringList out2; 229 QStringList out2;
187 out2 << "" << "" << "a'a" << "'" << "" << "" << "" << "" << "" << "" 230 out2 << "" << "" << "a'a" << "'" << "" << "" << "" << "" << "" << ""