* process the character at the current index in a switch block. * * @param line a reference to the line to indent. * @param index the current line index. * @return the new line index. */
| 636 | * @return the new line index. |
| 637 | */ |
| 638 | size_t ASEnhancer::processSwitchBlock(string &line, size_t index) |
| 639 | { |
| 640 | size_t i = index; |
| 641 | bool isPotentialKeyword = isCharPotentialHeader(line, i); |
| 642 | |
| 643 | if (line[i] == '{') |
| 644 | { |
| 645 | sw.switchBracketCount++; |
| 646 | if (lookingForCaseBracket) // if 1st after case statement |
| 647 | { |
| 648 | sw.unindentCase = true; // unindenting this case |
| 649 | sw.unindentDepth++; |
| 650 | lookingForCaseBracket = false; // not looking now |
| 651 | } |
| 652 | return i; |
| 653 | } |
| 654 | lookingForCaseBracket = false; // no opening bracket, don't indent |
| 655 | |
| 656 | if (line[i] == '}') |
| 657 | { |
| 658 | sw.switchBracketCount--; |
| 659 | assert(sw.switchBracketCount <= bracketCount); |
| 660 | if (sw.switchBracketCount == 0) // if end of switch statement |
| 661 | { |
| 662 | int lineUnindent = sw.unindentDepth; |
| 663 | if (line.find_first_not_of(" \t") == i |
| 664 | && !switchStack.empty()) |
| 665 | lineUnindent = switchStack[switchStack.size() - 1].unindentDepth; |
| 666 | if (shouldUnindentLine) |
| 667 | { |
| 668 | if (lineUnindent > 0) |
| 669 | i -= unindentLine(line, lineUnindent); |
| 670 | shouldUnindentLine = false; |
| 671 | } |
| 672 | switchDepth--; |
| 673 | sw = switchStack.back(); |
| 674 | switchStack.pop_back(); |
| 675 | } |
| 676 | return i; |
| 677 | } |
| 678 | |
| 679 | if (isPotentialKeyword |
| 680 | && (findKeyword(line, i, "case") || findKeyword(line, i, "default"))) |
| 681 | { |
| 682 | if (sw.unindentCase) // if unindented last case |
| 683 | { |
| 684 | sw.unindentCase = false; // stop unindenting previous case |
| 685 | sw.unindentDepth--; |
| 686 | } |
| 687 | |
| 688 | i = findCaseColon(line, i); |
| 689 | |
| 690 | i++; |
| 691 | for (; i < line.length(); i++) // bypass whitespace |
| 692 | { |
| 693 | if (!isWhiteSpace(line[i])) |
| 694 | break; |
| 695 | } |
nothing calls this directly
no outgoing calls
no test coverage detected