MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / processSwitchBlock

Method processSwitchBlock

other_src/astyle/src/ASEnhancer.cpp:557–636  ·  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

555 * @return the new line index.
556 */
557size_t ASEnhancer::processSwitchBlock(string& line, size_t index)
558{
559 size_t i = index;
560 bool isPotentialKeyword = isCharPotentialHeader(line, i);
561
562 if (line[i] == '{')
563 {
564 sw.switchBracketCount++;
565 if (lookingForCaseBracket) // if 1st after case statement
566 {
567 sw.unindentCase = true; // unindenting this case
568 sw.unindentDepth++;
569 lookingForCaseBracket = false; // not looking now
570 }
571 return i;
572 }
573 lookingForCaseBracket = false; // no opening bracket, don't indent
574
575 if (line[i] == '}') // if close bracket
576 {
577 sw.switchBracketCount--;
578 assert(sw.switchBracketCount <= bracketCount);
579 if (sw.switchBracketCount == 0) // if end of switch statement
580 {
581 int lineUnindent = sw.unindentDepth;
582 if (line.find_first_not_of(" \t") == i
583 && switchStack.size() > 0)
584 lineUnindent = switchStack[switchStack.size()-1].unindentDepth;
585 if (shouldIndentLine)
586 {
587 if (lineUnindent > 0)
588 i -= unindentLine(line, lineUnindent);
589 shouldIndentLine = false;
590 }
591 switchDepth--;
592 sw = switchStack.back();
593 switchStack.pop_back();
594 }
595 return i;
596 }
597
598 if (isPotentialKeyword
599 && (findKeyword(line, i, "case") || findKeyword(line, i, "default")))
600 {
601 if (sw.unindentCase) // if unindented last case
602 {
603 sw.unindentCase = false; // stop unindenting previous case
604 sw.unindentDepth--;
605 }
606
607 i = findCaseColon(line, i);
608
609 i++;
610 for (; i < line.length(); i++) // bypass whitespace
611 {
612 if (!isWhiteSpace(line[i]))
613 break;
614 }

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.45
backMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected