40 while (i < len && s[i].isSpace()) ++i;
41 if (i < len && s[i] ==
'-') sign = -1;
49 double d = c.digitValue();
52 for (
int p = dp; p > 0; --p) d /= 10.0;
60 }
else if (c ==
'.') {
86 enum { beg, sep, unq, q1, q2 } mode = beg;
88 bool use_doubling = (escapeMode == EscapeDoubling ||
89 escapeMode == EscapeAny);
90 bool use_backslash = (escapeMode == EscapeBackslash ||
91 escapeMode == EscapeAny);
93 for (
int i = 0; i < s.length(); ++i) {
99 case beg:
case sep: mode = q1;
break;
100 case unq:
case q2: tok += c;
break;
102 if (use_doubling && i+1 < s.length() && s[i+1] == c) {
103 tok += c; ++i;
break;
109 }
else if (c ==
'"') {
111 case beg:
case sep: mode = q2;
break;
112 case unq:
case q1: tok += c;
break;
114 if (use_doubling && i+1 < s.length() && s[i+1] == c) {
115 tok += c; ++i;
break;
121 }
else if (c == separator || (separator ==
' ' && c.isSpace())) {
123 case beg: mode = sep; tokens <<
"";
break;
124 case sep:
if (separator !=
' ') tokens <<
"";
break;
125 case unq: mode = sep; tokens << tok; tok =
"";
break;
126 case q1:
case q2: tok += c;
break;
129 }
else if (c ==
'\\' && use_backslash) {
130 if (++i < s.length()) {
133 case beg:
case sep: mode = unq; tok += c;
break;
134 case unq:
case q1:
case q2: tok += c;
break;
140 case beg:
case sep: mode = unq; tok += c;
break;
141 case unq:
case q1:
case q2: tok += c;
break;
146 if (tok !=
"" || mode != beg) {
148 tokens << (
"'" + tok);
149 }
else if (mode == q2) {
150 tokens << (
"\"" + tok);
163 return splitQuoted(line, separator);
165 return line.split(separator,
166 separator ==
' ' ? QString::SkipEmptyParts :
167 QString::KeepEmptyParts);
175 for (
auto col: row) {
179 if (col.contains(delimiter)) {
180 col.replace(
"\"",
"\"\"");
181 col =
"\"" + col +
"\"";
191 size_t len = bytes.length();
193 unsigned char first =
'\0';
195 for (
size_t i = 0; i < len; ++i) {
197 unsigned char c = bytes[i];
199 if (((c & 0xc0) == 0xc0) || !(c & 0x80)) {
207 (!(first & 0x20)) ? 2 :
208 (!(first & 0x10)) ? 3 :
209 (!(first & 0x08)) ? 4 :
210 (!(first & 0x04)) ? 5 : 0;
212 if (length != 0 && mblen != length) {
243 (!(first & 0x20)) ? 2 :
244 (!(first & 0x10)) ? 3 :
245 (!(first & 0x08)) ? 4 :
246 (!(first & 0x04)) ? 5 : 0;
248 if (length != 0 && mblen != length) {
static bool isValidUtf8(const std::string &bytes, bool isTruncated)
Return true if the given byte array contains a valid UTF-8 sequence, false if not.
static QStringList split(QString s, QChar separator, bool quoted)
Split a string at the given separator character.
static QString joinDelimited(QVector< QString > row, QString delimiter)
Join a vector of strings into a single string, with the delimiter as the joining string.
static QStringList splitQuoted(QString s, QChar separator, EscapeMode escapeMode=EscapeAny)
Split a string at the given separator character, allowing quoted sections that contain the separator...
static double stringToDoubleLocaleFree(QString s, bool *ok=0)
Convert a string to a double using basic "C"-locale syntax, i.e.