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

Method addBracketsToStatement

astyle/src/ASFormatter.cpp:5267–5315  ·  view source on GitHub ↗

* Add brackets to a single line statement following a header. * Brackets are not added if the proper conditions are not met. * Brackets are added to the currentLine. */

Source from the content-addressed store, hash-verified

5265 * Brackets are added to the currentLine.
5266 */
5267bool ASFormatter::addBracketsToStatement()
5268{
5269 assert(isImmediatelyPostHeader);
5270
5271 if (currentHeader != &AS_IF
5272 && currentHeader != &AS_ELSE
5273 && currentHeader != &AS_FOR
5274 && currentHeader != &AS_WHILE
5275 && currentHeader != &AS_DO
5276 && currentHeader != &AS_FOREACH)
5277 return false;
5278
5279 if (currentHeader == &AS_WHILE && foundClosingHeader) // do-while
5280 return false;
5281
5282 // do not bracket an empty statement
5283 if (currentChar == ';')
5284 return false;
5285
5286 // do not add if a header follows
5287 if (isCharPotentialHeader(currentLine, charNum))
5288 if (findHeader(headers) != NULL)
5289 return false;
5290
5291 // find the next semi-colon
5292 size_t nextSemiColon = charNum;
5293 if (currentChar != ';')
5294 nextSemiColon = findNextChar(currentLine, ';', charNum + 1);
5295 if (nextSemiColon == string::npos)
5296 return false;
5297
5298 // add closing bracket before changing the line length
5299 if (nextSemiColon == currentLine.length() - 1)
5300 currentLine.append(" }");
5301 else
5302 currentLine.insert(nextSemiColon + 1, " }");
5303 // add opening bracket
5304 currentLine.insert(charNum, "{ ");
5305 assert(computeChecksumIn("{}"));
5306 currentChar = '{';
5307 // remove extra spaces
5308 if (!shouldAddOneLineBrackets)
5309 {
5310 size_t lastText = formattedLine.find_last_not_of(" \t");
5311 if ((formattedLine.length() - 1) - lastText > 1)
5312 formattedLine.erase(lastText + 1);
5313 }
5314 return true;
5315}
5316
5317/**
5318 * Remove brackets from a single line statement following a header.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected