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

@@ -989,11 +989,10 @@ int CodeFormatter::column(int index) const
const QChar tab = QLatin1Char('\t');
for (int i = 0; i < index; i++) {
if (m_currentLine[i] == tab) {
if (m_currentLine[i] == tab)
col = ((col / m_tabSize) + 1) * m_tabSize;
} else {
else
col++;
}
}
return col;
}
@@ -1328,9 +1327,8 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
*indentDepth += m_tabSettings.m_indentSize;
}
if (followedByData) {
if (followedByData)
*paddingDepth = nextTokenPosition-*indentDepth;
}
break;
}
@@ -1483,11 +1481,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
} else if ((topState.type == expression && previousState.type == declaration_start)
|| topState.type == member_init || topState.type == member_init_open) {
// the declaration_start indent is the base
if (topState.type == member_init) {
if (topState.type == member_init)
*indentDepth = state(2).savedIndentDepth;
} else {
else
*indentDepth = previousState.savedIndentDepth;
}
if (m_styleSettings.indentFunctionBraces)
*indentDepth += m_tabSettings.m_indentSize;
*paddingDepth = 0;