MCPcopy Create free account
hub / github.com/KDE/kdevelop / processSwitchBlock

Method processSwitchBlock

plugins/astyle/3rdparty/libastyle/ASEnhancer.cpp:661–740  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

659 * @return the new line index.
660 */
661size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
662{
663 size_t i = index;
664 bool isPotentialKeyword = isCharPotentialHeader(line, i);
665
666 if (line[i] == '{')
667 {
668 sw.switchBraceCount++;
669 if (lookingForCaseBrace) // if 1st after case statement
670 {
671 sw.unindentCase = true; // unindenting this case
672 sw.unindentDepth++;
673 lookingForCaseBrace = false; // not looking now
674 }
675 return i;
676 }
677 lookingForCaseBrace = false; // no opening brace, don't indent
678
679 if (line[i] == '}')
680 {
681 sw.switchBraceCount--;
682 if (sw.switchBraceCount == 0) // if end of switch statement
683 {
684 int lineUnindent = sw.unindentDepth;
685 if (line.find_first_not_of(" \t") == i
686 && !switchStack.empty())
687 lineUnindent = switchStack[switchStack.size() - 1].unindentDepth;
688 if (shouldUnindentLine)
689 {
690 if (lineUnindent > 0)
691 i -= unindentLine(line, lineUnindent);
692 shouldUnindentLine = false;
693 }
694 switchDepth--;
695 sw = switchStack.back();
696 switchStack.pop_back();
697 }
698 return i;
699 }
700
701 if (isPotentialKeyword
702 && (findKeyword(line, i, ASResource::AS_CASE)
703 || findKeyword(line, i, ASResource::AS_DEFAULT)))
704 {
705 if (sw.unindentCase) // if unindented last case
706 {
707 sw.unindentCase = false; // stop unindenting previous case
708 sw.unindentDepth--;
709 }
710
711 i = findCaseColon(line, i);
712
713 i++;
714 for (; i < line.length(); i++) // bypass whitespace
715 {
716 if (!isWhiteSpace(line[i]))
717 break;
718 }

Callers

nothing calls this directly

Calls 4

emptyMethod · 0.80
sizeMethod · 0.45
backMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected