diff --git a/src/shared/qscripthighlighter/qscriptindenter.cpp b/src/shared/qscripthighlighter/qscriptindenter.cpp index 4f8d5ab9e6c1a8cd2c73fecd2fbc3b9a992232d3..dd639e03754ed283bed332c1025af6b9ab64bc90 100644 --- a/src/shared/qscripthighlighter/qscriptindenter.cpp +++ b/src/shared/qscripthighlighter/qscriptindenter.cpp @@ -272,21 +272,36 @@ QString QScriptIndenter::trimmedCodeLine(const QString &t) const /* Remove C++-style comments. */ - k = trimmed.indexOf(QLatin1String("//")); + k = trimmed.indexOf(QRegExp(QLatin1String("\\s*//"))); if (k != -1) trimmed.truncate(k); - const QString e = trimmed.trimmed(); - - if (insertSemicolon || e.endsWith(QLatin1Char(',')) || e.endsWith(QLatin1Char(']'))) - trimmed.append(QLatin1Char(';')); - else if (trimmed.indexOf(propertylikeKeyword) != -1) { + if (! insertSemicolon && ! trimmed.isEmpty()) { const QChar ch = trimmed.at(trimmed.length() - 1); - if (ch.isLetterOrNumber() || ch == QLatin1Char(')') || ch == QLatin1Char(']') - || ch == QLatin1Char('"') || ch == QLatin1Char('\'')) - trimmed.append(QLatin1Char(';')); + + switch (ch.unicode()) { + case ',': + case ']': + case '"': + case '\'': + case '_': + insertSemicolon = true; + break; + + default: + if (ch.isLetterOrNumber()) { + if (! trimmed.endsWith(QLatin1String("else"))) + insertSemicolon = true; + } else if (trimmed.indexOf(propertylikeKeyword) != -1) + insertSemicolon = true; + + break; + } } + if (insertSemicolon) + trimmed.append(QLatin1Char(';')); + return trimmed; }