1111#include " llvm/Support/raw_ostream.h"
1212
1313#include < cctype>
14+ #include < optional>
1415#include < sstream>
1516
1617#define DEBUG_TYPE " mustache"
@@ -325,9 +326,8 @@ struct Tag {
325326 size_t StartPosition = StringRef::npos;
326327};
327328
328- static Tag findNextTag (StringRef Template, size_t StartPos,
329- const SmallString<8 > &Open,
330- const SmallString<8 > &Close) {
329+ static Tag findNextTag (StringRef Template, size_t StartPos, StringRef Open,
330+ StringRef Close) {
331331 const StringLiteral TripleOpen (" {{{" );
332332 const StringLiteral TripleClose (" }}}" );
333333
@@ -368,22 +368,22 @@ static Tag findNextTag(StringRef Template, size_t StartPos,
368368 return Result;
369369}
370370
371- static void processTag ( const Tag &T, SmallVectorImpl<Token> &Tokens,
372- SmallString< 8 > &Open, SmallString< 8 > &Close ) {
371+ static std::optional<std::pair<StringRef, StringRef>>
372+ processTag ( const Tag &T, SmallVectorImpl<Token > &Tokens ) {
373373 LLVM_DEBUG (dbgs () << " Found tag: \" " << T.FullMatch << " \" , Content: \" "
374374 << T.Content << " \"\n " );
375375 if (T.TagKind == Tag::Kind::Triple) {
376376 Tokens.emplace_back (T.FullMatch .str (), " &" + T.Content .str (), ' &' );
377377 LLVM_DEBUG (dbgs () << " Created UnescapeVariable token.\n " );
378- return ;
378+ return std:: nullopt ;
379379 }
380380 StringRef Interpolated = T.Content ;
381381 std::string RawBody = T.FullMatch .str ();
382382 if (!Interpolated.trim ().starts_with (" =" )) {
383383 char Front = Interpolated.empty () ? ' ' : Interpolated.trim ().front ();
384384 Tokens.emplace_back (RawBody, Interpolated.str (), Front);
385385 LLVM_DEBUG (dbgs () << " Created tag token of type '" << Front << " '\n " );
386- return ;
386+ return std:: nullopt ;
387387 }
388388 Tokens.emplace_back (RawBody, Interpolated.str (), ' =' );
389389 StringRef DelimSpec = Interpolated.trim ();
@@ -392,11 +392,9 @@ static void processTag(const Tag &T, SmallVectorImpl<Token> &Tokens,
392392 DelimSpec = DelimSpec.trim ();
393393
394394 auto [NewOpen, NewClose] = DelimSpec.split (' ' );
395- Open = NewOpen;
396- Close = NewClose;
397-
398- LLVM_DEBUG (dbgs () << " Found Set Delimiter tag. NewOpen='" << Open
399- << " ', NewClose='" << Close << " '\n " );
395+ LLVM_DEBUG (dbgs () << " Found Set Delimiter tag. NewOpen='" << NewOpen
396+ << " ', NewClose='" << NewClose << " '\n " );
397+ return std::make_pair (NewOpen, NewClose);
400398}
401399
402400// Simple tokenizer that splits the template into tokens.
@@ -430,7 +428,9 @@ static SmallVector<Token> tokenize(StringRef Template) {
430428 LLVM_DEBUG (dbgs () << " Created Text token: \" " << Text << " \"\n " );
431429 }
432430
433- processTag (T, Tokens, Open, Close);
431+ if (auto NewDelims = processTag (T, Tokens)) {
432+ std::tie (Open, Close) = *NewDelims;
433+ }
434434
435435 // Move past the tag.
436436 Start = T.StartPosition + T.FullMatch .size ();
0 commit comments