* format pointer or reference with align to name */
| 3526 | * format pointer or reference with align to name |
| 3527 | */ |
| 3528 | void ASFormatter::formatPointerOrReferenceToName() |
| 3529 | { |
| 3530 | assert(currentChar == '*' || currentChar == '&' || currentChar == '^'); |
| 3531 | assert(!isJavaStyle()); |
| 3532 | |
| 3533 | // do this before bumping charNum |
| 3534 | bool isOldPRCentered = isPointerOrReferenceCentered(); |
| 3535 | |
| 3536 | size_t startNum = formattedLine.find_last_not_of(" \t"); |
| 3537 | if (startNum == string::npos) |
| 3538 | startNum = 0; |
| 3539 | string sequenceToInsert(1, currentChar); |
| 3540 | if (isSequenceReached("**")) |
| 3541 | { |
| 3542 | sequenceToInsert = "**"; |
| 3543 | goForward(1); |
| 3544 | } |
| 3545 | else if (isSequenceReached("&&")) |
| 3546 | { |
| 3547 | sequenceToInsert = "&&"; |
| 3548 | goForward(1); |
| 3549 | } |
| 3550 | // if reference to a pointer align both to name |
| 3551 | else if (currentChar == '*' && peekNextChar() == '&') |
| 3552 | { |
| 3553 | sequenceToInsert = "*&"; |
| 3554 | goForward(1); |
| 3555 | for (size_t i = charNum; i < currentLine.length() - 1 && isWhiteSpace(currentLine[i]); i++) |
| 3556 | goForward(1); |
| 3557 | } |
| 3558 | char peekedChar = peekNextChar(); |
| 3559 | bool isAfterScopeResolution = previousNonWSChar == ':'; // check for :: |
| 3560 | // if this is not the last thing on the line |
| 3561 | if (!isBeforeAnyComment() |
| 3562 | && (int) currentLine.find_first_not_of(" \t", charNum + 1) > charNum) |
| 3563 | { |
| 3564 | // goForward() to convert tabs to spaces, if necessary, |
| 3565 | // and move following characters to preceding characters |
| 3566 | // this may not work every time with tab characters |
| 3567 | for (size_t i = charNum + 1; i < currentLine.length() && isWhiteSpace(currentLine[i]); i++) |
| 3568 | { |
| 3569 | // if a padded paren follows don't move |
| 3570 | if (shouldPadParensOutside && peekedChar == '(' && !isOldPRCentered) |
| 3571 | { |
| 3572 | // empty parens don't count |
| 3573 | size_t start = currentLine.find_first_not_of("( \t", charNum + 1); |
| 3574 | if (start != string::npos && currentLine[start] != ')') |
| 3575 | break; |
| 3576 | } |
| 3577 | goForward(1); |
| 3578 | if (formattedLine.length() > 0) |
| 3579 | formattedLine.append(1, currentLine[i]); |
| 3580 | else |
| 3581 | spacePadNum--; |
| 3582 | } |
| 3583 | } |
| 3584 | // don't pad before scope resolution operator |
| 3585 | if (isAfterScopeResolution) |
nothing calls this directly
no outgoing calls
no test coverage detected