MCPcopy Create free account
hub / github.com/dirkvranckaert/AndroidDecompiler / removeBracketsFromStatement

Method removeBracketsFromStatement

astyle/src/ASFormatter.cpp:5322–5414  ·  view source on GitHub ↗

* Remove brackets from a single line statement following a header. * Brackets are not removed if the proper conditions are not met. * The first bracket is replaced by a space. */

Source from the content-addressed store, hash-verified

5320 * The first bracket is replaced by a space.
5321 */
5322bool ASFormatter::removeBracketsFromStatement()
5323{
5324 assert(isImmediatelyPostHeader);
5325 assert(currentChar == '{');
5326
5327 if (currentHeader != &AS_IF
5328 && currentHeader != &AS_ELSE
5329 && currentHeader != &AS_FOR
5330 && currentHeader != &AS_WHILE
5331 && currentHeader != &AS_FOREACH)
5332 return false;
5333
5334 if (currentHeader == &AS_WHILE && foundClosingHeader) // do-while
5335 return false;
5336
5337 bool isFirstLine = true;
5338 bool needReset = false;
5339 string nextLine_;
5340 // leave nextLine_ empty if end of line comment follows
5341 if (!isBeforeAnyLineEndComment(charNum) || currentLineBeginsWithBracket)
5342 nextLine_ = currentLine.substr(charNum + 1);
5343 size_t nextChar = 0;
5344
5345 // find the first non-blank text
5346 while (sourceIterator->hasMoreLines() || isFirstLine)
5347 {
5348 if (isFirstLine)
5349 isFirstLine = false;
5350 else
5351 {
5352 nextLine_ = sourceIterator->peekNextLine();
5353 nextChar = 0;
5354 needReset = true;
5355 }
5356
5357 nextChar = nextLine_.find_first_not_of(" \t", nextChar);
5358 if (nextChar != string::npos)
5359 break;
5360 }
5361
5362 // don't remove if comments or a header follow the bracket
5363 if ((nextLine_.compare(nextChar, 2, "/*") == 0)
5364 || (nextLine_.compare(nextChar, 2, "//") == 0)
5365 || (isCharPotentialHeader(nextLine_, nextChar)
5366 && ASBeautifier::findHeader(nextLine_, nextChar, headers) != NULL))
5367 {
5368 if (needReset)
5369 sourceIterator->peekReset();
5370 return false;
5371 }
5372
5373 // find the next semi-colon
5374 size_t nextSemiColon = nextChar;
5375 if (nextLine_[nextChar] != ';')
5376 nextSemiColon = findNextChar(nextLine_, ';', nextChar + 1);
5377 if (nextSemiColon == string::npos)
5378 {
5379 if (needReset)

Callers

nothing calls this directly

Calls 3

peekNextLineMethod · 0.80
peekResetMethod · 0.80
hasMoreLinesMethod · 0.45

Tested by

no test coverage detected