Fix bug where space characters in strings would cause a syntax error
Sadly, could not get a regex to match properly, so space-delimitered splitting is moved to a separate function, where quotes take precedence over space characters in splitting
MODIFY
src/syntaxhighlighter.cpp
src/syntaxhighlighter.cpp
@@ -549,10 +549,33 @@ namespace {
return QString("Unknown operation");
}
+QStringList splitQuotes(const QStringList& list) {
+ // Manual string splitter - splits at "\ " (space) characters, unless test is delimitered by "\""
+ QStringList ret;
+ for (const auto& s : list) {
+ QString outString;
+ bool inQuote = false;
+ for (int i = 0; i < s.length(); i++) {
+ inQuote ^= s[i] == '"';
+ if (s[i] == ' ' && !inQuote) {
+ ret.append(outString);
+ outString.clear();
+ } else {
+ outString.append(s[i]);
+ if (i == s.length() - 1)
+ ret.append(outString);
+ }
+ }
+ }
+ ret.removeAll("");
+ return ret;
+}
+
QString SyntaxHighlighter::checkSyntax(const QString& input) {
- const static auto splitter = QRegularExpression("(\\ |\\,|\\t|\\(|\\))");
+ const static auto splitter = QRegularExpression("(\\,|\\t|\\(|\\))");
QStringList fields = input.split(splitter);
fields.removeAll("");
+ fields = splitQuotes(fields);
// Empty fields? return
if (fields.isEmpty())

Fix bug where space characters in strings would cause a syntax error

Sadly, could not get a regex to match properly, so space-delimitered splitting is moved to a separate function, where quotes take precedence over space characters in splitting