Remove braces for single lines of conditions

#!/usr/bin/env ruby

Dir.glob('**/*.cpp') { |file|
  # skip ast (excluding paste, astpath, and canv'ast'imer)
  next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
  s = File.read(file)
  next if s.include?('qlalr')
  orig = s.dup
  s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
    res = $&
    if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
      res
    else
      res.gsub!('} else', 'else')
      res.gsub!(/\n +} *\n/m, "\n")
      res.gsub(/ *{$/, '')
    end
  }
  s.gsub!(/ *$/, '')
  File.open(file, 'wb').write(s) if s != orig
}

Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Orgad Shaneh
2013-01-08 03:32:53 +02:00
committed by hjk
parent 73a2717bed
commit 29a93998df
396 changed files with 1856 additions and 3135 deletions

View File

@@ -224,29 +224,23 @@ QString Error::toXml() const
}
foreach (const Stack &stack, d->stacks) {
if (!stack.auxWhat().isEmpty()) {
if (!stack.auxWhat().isEmpty())
stream << " <auxwhat>" << stack.auxWhat() << "</auxwhat>\n";
}
stream << " <stack>\n";
foreach (const Frame &frame, stack.frames()) {
stream << " <frame>\n";
stream << " <ip>0x" << QString::number(frame.instructionPointer(), 16) << "</ip>\n";
if (!frame.object().isEmpty()) {
if (!frame.object().isEmpty())
stream << " <obj>" << frame.object() << "</obj>\n";
}
if (!frame.functionName().isEmpty()) {
if (!frame.functionName().isEmpty())
stream << " <fn>" << frame.functionName() << "</fn>\n";
}
if (!frame.directory().isEmpty()) {
if (!frame.directory().isEmpty())
stream << " <dir>" << frame.directory() << "</dir>\n";
}
if (!frame.file().isEmpty()) {
if (!frame.file().isEmpty())
stream << " <file>" << frame.file() << "</file>\n";
}
if (frame.line() != -1) {
if (frame.line() != -1)
stream << " <line>" << frame.line() << "</line>";
}
stream << " </frame>\n";
}

View File

@@ -221,9 +221,8 @@ QXmlStreamReader::TokenType Parser::Private::blockingReadNext()
QIODevice *dev = reader.device();
QAbstractSocket *sock = qobject_cast<QAbstractSocket *>(dev);
if (!sock || sock->state() != QAbstractSocket::ConnectedState) {
if (!sock || sock->state() != QAbstractSocket::ConnectedState)
throw ParserException(dev->errorString());
}
}
} else if (reader.hasError()) {
throw ParserException(reader.errorString()); //TODO add line, column?

View File

@@ -105,11 +105,10 @@ void SuppressionFrame::setObject(const QString &obj)
QString SuppressionFrame::toString() const
{
if (!d->fun.isEmpty()) {
if (!d->fun.isEmpty())
return QLatin1String("fun:") + d->fun;
} else {
else
return QLatin1String("obj:") + d->obj;
}
}
class Suppression::Private : public QSharedData