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

Method stripCommentPrefix

astyle/src/ASFormatter.cpp:6485–6581  ·  view source on GitHub ↗

Remove the leading '*' from a comment line and indent to the next tab.

Source from the content-addressed store, hash-verified

6483
6484// Remove the leading '*' from a comment line and indent to the next tab.
6485void ASFormatter::stripCommentPrefix()
6486{
6487 int firstChar = formattedLine.find_first_not_of(" \t");
6488 if (firstChar < 0)
6489 return;
6490
6491 if (isInCommentStartLine)
6492 {
6493 // comment opener must begin the line
6494 if (formattedLine.compare(firstChar, 2, "/*") != 0)
6495 return;
6496 int commentOpener = firstChar;
6497 // ignore single line comments
6498 int commentEnd = formattedLine.find("*/", firstChar + 2);
6499 if (commentEnd != -1)
6500 return;
6501 // first char after the comment opener must be at least one indent
6502 int followingText = formattedLine.find_first_not_of(" \t", commentOpener + 2);
6503 if (followingText < 0)
6504 return;
6505 if (formattedLine[followingText] == '*' || formattedLine[followingText] == '!')
6506 followingText = formattedLine.find_first_not_of(" \t", followingText + 1);
6507 if (followingText < 0)
6508 return;
6509 if (formattedLine[followingText] == '*')
6510 return;
6511 int indentLen = getIndentLength();
6512 int followingTextIndent = followingText - commentOpener;
6513 if (followingTextIndent < indentLen)
6514 {
6515 string stringToInsert(indentLen - followingTextIndent, ' ');
6516 formattedLine.insert(followingText, stringToInsert);
6517 }
6518 return;
6519 }
6520 // comment body including the closer
6521 else if (formattedLine[firstChar] == '*')
6522 {
6523 if (formattedLine.compare(firstChar, 2, "*/") == 0)
6524 {
6525 // line starts with an end comment
6526 formattedLine = "*/";
6527 }
6528 else
6529 {
6530 // build a new line with one indent
6531 string newLine;
6532 int secondChar = formattedLine.find_first_not_of(" \t", firstChar + 1);
6533 if (secondChar < 0)
6534 {
6535 adjustChecksumIn(-'*');
6536 formattedLine = newLine;
6537 return;
6538 }
6539 if (formattedLine[secondChar] == '*')
6540 return;
6541 // replace the leading '*'
6542 int indentLen = getIndentLength();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected