Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions llvm/lib/Support/Mustache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ void stripTokenBefore(SmallVectorImpl<Token> &Tokens, size_t Idx,
StringRef PrevTokenBody = PrevToken.TokenBody;
StringRef Unindented = PrevTokenBody.rtrim(" \r\t\v");
size_t Indentation = PrevTokenBody.size() - Unindented.size();
if (CurrentType != Token::Type::Partial)
PrevToken.TokenBody = Unindented.str();
PrevToken.TokenBody = Unindented.str();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the function comment possibly stale now, since the distinction for partials is no longer made?

// The exception for this is partial tag which requires us to
// keep track of the indentation once it's rendered.

CurrentToken.setIndentation(Indentation);
}

Expand Down Expand Up @@ -425,7 +424,8 @@ class AddIndentationStringStream : public raw_ostream {
public:
explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
size_t Indentation)
: Indentation(Indentation), WrappedStream(WrappedStream) {
: Indentation(Indentation), WrappedStream(WrappedStream),
NeedsIndent(true) {
SetUnbuffered();
}

Expand All @@ -434,10 +434,15 @@ class AddIndentationStringStream : public raw_ostream {
llvm::StringRef Data(Ptr, Size);
SmallString<0> Indent;
Indent.resize(Indentation, ' ');

for (char C : Data) {
if (NeedsIndent && C != '\n') {
WrappedStream << Indent;
NeedsIndent = false;
}
WrappedStream << C;
if (C == '\n')
WrappedStream << Indent;
NeedsIndent = true;
}
}

Expand All @@ -446,6 +451,7 @@ class AddIndentationStringStream : public raw_ostream {
private:
size_t Indentation;
llvm::raw_ostream &WrappedStream;
bool NeedsIndent;
};

class Parser {
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/Support/MustacheTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ TEST(MustachePartials, StandaloneIndentation) {
std::string Out;
raw_string_ostream OS(Out);
T.render(D, OS);
EXPECT_NE("\\\n |\n <\n ->\n |\n/\n", Out);
EXPECT_EQ("\\\n |\n <\n ->\n |\n/\n", Out);
}

TEST(MustacheLambdas, BasicInterpolation) {
Expand Down