Skip to content

Commit ea687e4

Browse files
committed
[llvm][mustache] Use StringRef parameters
1 parent f18412d commit ea687e4

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

llvm/lib/Support/Mustache.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "llvm/Support/raw_ostream.h"
1212

1313
#include <cctype>
14+
#include <optional>
1415
#include <sstream>
1516

1617
#define DEBUG_TYPE "mustache"
@@ -367,22 +368,22 @@ static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open,
367368
return Result;
368369
}
369370

370-
static void processTag(const Tag &T, SmallVectorImpl<Token> &Tokens,
371-
SmallString<8> &Open, SmallString<8> &Close) {
371+
static std::optional<std::pair<StringRef, StringRef>>
372+
processTag(const Tag &T, SmallVectorImpl<Token> &Tokens) {
372373
LLVM_DEBUG(dbgs() << " Found tag: \"" << T.FullMatch << "\", Content: \""
373374
<< T.Content << "\"\n");
374375
if (T.TagKind == Tag::Kind::Triple) {
375376
Tokens.emplace_back(T.FullMatch.str(), "&" + T.Content.str(), '&');
376377
LLVM_DEBUG(dbgs() << " Created UnescapeVariable token.\n");
377-
return;
378+
return std::nullopt;
378379
}
379380
StringRef Interpolated = T.Content;
380381
std::string RawBody = T.FullMatch.str();
381382
if (!Interpolated.trim().starts_with("=")) {
382383
char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front();
383384
Tokens.emplace_back(RawBody, Interpolated.str(), Front);
384385
LLVM_DEBUG(dbgs() << " Created tag token of type '" << Front << "'\n");
385-
return;
386+
return std::nullopt;
386387
}
387388
Tokens.emplace_back(RawBody, Interpolated.str(), '=');
388389
StringRef DelimSpec = Interpolated.trim();
@@ -391,11 +392,9 @@ static void processTag(const Tag &T, SmallVectorImpl<Token> &Tokens,
391392
DelimSpec = DelimSpec.trim();
392393

393394
auto [NewOpen, NewClose] = DelimSpec.split(' ');
394-
Open = NewOpen;
395-
Close = NewClose;
396-
397-
LLVM_DEBUG(dbgs() << " Found Set Delimiter tag. NewOpen='" << Open
398-
<< "', NewClose='" << Close << "'\n");
395+
LLVM_DEBUG(dbgs() << " Found Set Delimiter tag. NewOpen='" << NewOpen
396+
<< "', NewClose='" << NewClose << "'\n");
397+
return std::make_pair(NewOpen, NewClose);
399398
}
400399

401400
// Simple tokenizer that splits the template into tokens.
@@ -429,7 +428,9 @@ static SmallVector<Token> tokenize(StringRef Template) {
429428
LLVM_DEBUG(dbgs() << " Created Text token: \"" << Text << "\"\n");
430429
}
431430

432-
processTag(T, Tokens, Open, Close);
431+
if (auto NewDelims = processTag(T, Tokens)) {
432+
std::tie(Open, Close) = *NewDelims;
433+
}
433434

434435
// Move past the tag.
435436
Start = T.StartPosition + T.FullMatch.size();

0 commit comments

Comments
 (0)