@@ -168,7 +168,7 @@ class ASTNode {
168168
169169 void indentTextNode (std::string &Body, size_t Indentation, bool FinalNode);
170170
171- void indentNodes (ASTNode *Node, bool isPartial );
171+ void indentNodes (ASTNode *Node, bool IsPartial );
172172
173173 void renderPartial (const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
174174 ASTNode *Partial);
@@ -687,40 +687,41 @@ void ASTNode::renderChild(const json::Value &Contexts, llvm::raw_ostream &OS) {
687687
688688void ASTNode::indentTextNode (std::string &Body, size_t Indentation,
689689 bool FinalNode) {
690- std::string spaces (Indentation, ' ' );
691- size_t pos = 0 ;
690+ std::string Spaces (Indentation, ' ' );
691+ size_t Pos = 0 ;
692692 size_t LastChar = std::string::npos;
693693
694694 if (FinalNode)
695- // body.erase(body.find_last_not_of(" \t\r\f\v") + 1);
696695 LastChar = Body.find_last_not_of (" \t\r\f\v " );
697696
698697 while ((pos = Body.find (' \n ' , pos)) != std::string::npos) {
699- if ((!FinalNode) || (pos != LastChar)) {
700- Body.insert (pos + 1 , spaces);
701- pos += 1 + Indentation;
702- } else {
698+ if (FinalNode && (pos == LastChar))
703699 break ;
704- }
700+
701+ Body.insert (pos + 1 , Spaces);
702+ pos += 1 + Indentation;
705703 }
706704}
707705
708- void ASTNode::indentNodes (ASTNode *Node, bool isPartial ) {
709- size_t size = Node->Children .size ();
706+ void ASTNode::indentNodes (ASTNode *Node, bool IsPartial ) {
707+ size_t Size = Node->Children .size ();
710708
711- for (size_t i = 0 ; i < size ; ++i) {
712- ASTNode *child = Node->Children [i].get ();
713- switch (child ->Ty ) {
709+ for (size_t i = 0 ; i < Size ; ++i) {
710+ ASTNode *Child = Node->Children [i].get ();
711+ switch (Child ->Ty ) {
714712 case ASTNode::Text: {
715- indentTextNode (child->Body , Indentation, ((i == size - 1 ) && isPartial));
713+ // Only track the final node for partials.
714+ bool IsFinalNode = ((i == Size - 1 ) && IsPartial);
715+ indentTextNode (Child->Body , Indentation, IsFinalNode);
716716 break ;
717717 }
718718 case ASTNode::Section: {
719- indentNodes (child , false );
719+ indentNodes (Child , false );
720720 break ;
721721 }
722722 case ASTNode::Partial: {
723- indentNodes (child, true );
723+ indentNodes (Child, true );
724+ break ;
724725 }
725726 case ASTNode::Root:
726727 case ASTNode::Variable:
0 commit comments