|
10 | 10 | #include "llvm/Support/Debug.h" |
11 | 11 | #include "llvm/Support/raw_ostream.h" |
12 | 12 | #include <cctype> |
| 13 | +#include <optional> |
13 | 14 | #include <sstream> |
14 | 15 |
|
15 | 16 | #define DEBUG_TYPE "mustache" |
@@ -364,35 +365,33 @@ static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open, |
364 | 365 | return Result; |
365 | 366 | } |
366 | 367 |
|
367 | | -static void processTag(const Tag &T, SmallVectorImpl<Token> &Tokens, |
368 | | - SmallString<8> &Open, SmallString<8> &Close) { |
| 368 | +static std::optional<std::pair<StringRef, StringRef>> |
| 369 | +processTag(const Tag &T, SmallVectorImpl<Token> &Tokens) { |
369 | 370 | LLVM_DEBUG(dbgs() << " Found tag: \"" << T.FullMatch << "\", Content: \"" |
370 | 371 | << T.Content << "\"\n"); |
371 | 372 | if (T.TagKind == Tag::Kind::Triple) { |
372 | 373 | Tokens.emplace_back(T.FullMatch.str(), "&" + T.Content.str(), '&'); |
373 | 374 | LLVM_DEBUG(dbgs() << " Created UnescapeVariable token.\n"); |
374 | | - return; |
| 375 | + return std::nullopt; |
375 | 376 | } |
376 | 377 | StringRef Interpolated = T.Content; |
377 | 378 | std::string RawBody = T.FullMatch.str(); |
378 | 379 | if (!Interpolated.trim().starts_with("=")) { |
379 | 380 | char Front = Interpolated.empty() ? ' ' : Interpolated.trim().front(); |
380 | 381 | Tokens.emplace_back(RawBody, Interpolated.str(), Front); |
381 | 382 | LLVM_DEBUG(dbgs() << " Created tag token of type '" << Front << "'\n"); |
382 | | - return; |
| 383 | + return std::nullopt; |
383 | 384 | } |
384 | 385 | Tokens.emplace_back(RawBody, Interpolated.str(), '='); |
385 | 386 | StringRef DelimSpec = Interpolated.trim(); |
386 | 387 | DelimSpec = DelimSpec.drop_front(1); |
387 | 388 | DelimSpec = DelimSpec.take_until([](char C) { return C == '='; }); |
388 | 389 | DelimSpec = DelimSpec.trim(); |
389 | 390 |
|
390 | | - auto [NewOpen, NewClose] = DelimSpec.split(' '); |
391 | | - Open = NewOpen; |
392 | | - Close = NewClose; |
393 | | - |
394 | | - LLVM_DEBUG(dbgs() << " Found Set Delimiter tag. NewOpen='" << Open |
395 | | - << "', NewClose='" << Close << "'\n"); |
| 391 | + std::pair<StringRef, StringRef> Ret = DelimSpec.split(' '); |
| 392 | + LLVM_DEBUG(dbgs() << " Found Set Delimiter tag. NewOpen='" << Ret.first |
| 393 | + << "', NewClose='" << Ret.second << "'\n"); |
| 394 | + return Ret; |
396 | 395 | } |
397 | 396 |
|
398 | 397 | // Simple tokenizer that splits the template into tokens. |
@@ -426,7 +425,9 @@ static SmallVector<Token> tokenize(StringRef Template) { |
426 | 425 | LLVM_DEBUG(dbgs() << " Created Text token: \"" << Text << "\"\n"); |
427 | 426 | } |
428 | 427 |
|
429 | | - processTag(T, Tokens, Open, Close); |
| 428 | + if (auto NewDelims = processTag(T, Tokens)) { |
| 429 | + std::tie(Open, Close) = *NewDelims; |
| 430 | + } |
430 | 431 |
|
431 | 432 | // Move past the tag. |
432 | 433 | Start = T.StartPosition + T.FullMatch.size(); |
|
0 commit comments