Mercurial > hg > svcore
comparison base/StringBits.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 | 91056142abd0 |
children |
comparison
equal
deleted
inserted
replaced
1853:f36fef97ac81 | 1854:bde22957545e |
---|---|
36 * If ok is non-NULL, *ok will be set to true if conversion | 36 * If ok is non-NULL, *ok will be set to true if conversion |
37 * succeeds or false otherwise. | 37 * succeeds or false otherwise. |
38 */ | 38 */ |
39 static double stringToDoubleLocaleFree(QString s, bool *ok = 0); | 39 static double stringToDoubleLocaleFree(QString s, bool *ok = 0); |
40 | 40 |
41 enum EscapeMode { | |
42 EscapeAny, // support both backslash and doubling escapes | |
43 EscapeBackslash, // support backslash escapes only | |
44 EscapeDoubling, // support doubling escapes ("" for " etc) only | |
45 EscapeNone // support no escapes | |
46 }; | |
47 | |
41 /** | 48 /** |
42 * Split a string at the given separator character, allowing | 49 * Split a string at the given separator character, allowing |
43 * quoted sections that contain the separator. If the separator | 50 * quoted sections that contain the separator. If the separator |
44 * is ' ', any (amount of) whitespace will be considered as a | 51 * is ' ', any (amount of) whitespace will be considered as a |
45 * single separator. If the separator is another whitespace | 52 * single separator. If the separator is another whitespace |
46 * character such as '\t', it will be used literally. | 53 * character such as '\t', it will be used literally. |
47 */ | 54 */ |
48 static QStringList splitQuoted(QString s, QChar separator); | 55 static QStringList splitQuoted(QString s, |
56 QChar separator, | |
57 EscapeMode escapeMode = EscapeAny); | |
49 | 58 |
50 /** | 59 /** |
51 * Split a string at the given separator character. If quoted is | 60 * Split a string at the given separator character. If quoted is |
52 * true, do so by calling splitQuoted (above). If quoted is | 61 * true, do so by calling splitQuoted (above) in EscapeAny escape |
53 * false, use QString::split; if separator is ' ', use | 62 * mode. If quoted is false, use QString::split; if separator is |
54 * SkipEmptyParts behaviour, otherwise use KeepEmptyParts (this is | 63 * ' ', use SkipEmptyParts behaviour, otherwise use KeepEmptyParts |
55 * analogous to the behaviour of splitQuoted). | 64 * (this is analogous to the behaviour of splitQuoted). |
56 */ | 65 */ |
57 static QStringList split(QString s, QChar separator, bool quoted); | 66 static QStringList split(QString s, |
67 QChar separator, | |
68 bool quoted); | |
58 | 69 |
59 /** | 70 /** |
60 * Join a vector of strings into a single string, with the | 71 * Join a vector of strings into a single string, with the |
61 * delimiter as the joining string. If a string contains the | 72 * delimiter as the joining string. If a string contains the |
62 * delimiter already, quote it with double-quotes, replacing any | 73 * delimiter already, quote it with double-quotes, replacing any |