// File: WayfireWM[P]wf-utils/wayfire/lexer/lexer.cpp
// Function: wf::lexer_t::_parse_encapsulated_literal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
variant_t lexer_t::_parse_encapsulated_literal(const std::string &s_bound, const std::string &e_bound)
{
    // Check if the boundary is at the end of the of the line.
    auto begin = _parse_position + s_bound.size();
    if (begin >= _size)
    {
        _parse_position = _size;
        throw std::runtime_error("Lexical parser error. Encapsulated literal is truncated.");
    }

    // Find the next occurrence of the boundary. Avoid escaped ones (\boundary).
    std::size_t found_at = 0;
    auto found = false;
    while (!found)
    {
        auto p = _text.find(e_bound, begin);
        if (p == std::string::npos)
        {
            // Not found before end of line, complain and bail out.
            _parse_position = _size;
            throw std::runtime_error("Lexical parser error. Encapsulated literal is truncated.");
        }

        // check the character before the boundary match to see if it is not an escape.
        if (_text.at(p - 1) != '\\')
        {
            found = true;
            found_at = p;
            break;
        }
    }

    // If we get here, and found == false, it must mean that all the matches were escaped -> trunctated.
    if (!found)
    {
        _parse_position = _size;
        throw std::runtime_error("Lexical parser error. Encapsulated literal is truncated.");
    }

    // Found a good match. The string we want is between _parse_position and (found_at + boundary_length)
    auto length = (found_at + e_bound.size()) - _parse_position;
    auto literal_text = _text.substr(_parse_position, length);
    _parse_position += length;
    return parse_literal(literal_text);
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0x30(%rsp)
movq %rdi, %rax
movq %rax, 0x38(%rsp)
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movq %rdx, 0xb0(%rsp)
movq %rcx, 0xa8(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x28(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x6200
movq 0x40(%rsp), %rcx
movq %rax, %rdx
movq 0x48(%rsp), %rax
addq %rdx, %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
cmpq (%rcx), %rax
jb 0xcd36
movq 0x40(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x28(%rax)
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x28(%rsp)
leaq 0x12512(%rip), %rsi     # 0x1f206
callq 0x6100
jmp 0xccfb
movq 0x28(%rsp), %rdi
movq 0x222e9(%rip), %rsi     # 0x2eff0
movq 0x2229a(%rip), %rdx     # 0x2efa8
callq 0x64d0
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
callq 0x6240
jmp 0xcf50
movq $0x0, 0x88(%rsp)
movb $0x0, 0x87(%rsp)
movb 0x87(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xcd5c
jmp 0xce2c
movq 0x40(%rsp), %rdi
addq $0x8, %rdi
movq 0xa8(%rsp), %rsi
movq 0xa0(%rsp), %rdx
callq 0x6590
movq %rax, 0x78(%rsp)
cmpq $-0x1, 0x78(%rsp)
jne 0xcdf1
movq 0x40(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x28(%rax)
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
leaq 0x12457(%rip), %rsi     # 0x1f206
callq 0x6100
jmp 0xcdb6
movq 0x20(%rsp), %rdi
movq 0x2222e(%rip), %rsi     # 0x2eff0
movq 0x221df(%rip), %rdx     # 0x2efa8
callq 0x64d0
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
callq 0x6240
jmp 0xcf50
movq 0x40(%rsp), %rdi
addq $0x8, %rdi
movq 0x78(%rsp), %rsi
subq $0x1, %rsi
callq 0x6550
movsbl (%rax), %eax
cmpl $0x5c, %eax
je 0xce27
movb $0x1, 0x87(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x88(%rsp)
jmp 0xce2c
jmp 0xcd4a
testb $0x1, 0x87(%rsp)
jne 0xcea0
movq 0x40(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x28(%rax)
movl $0x10, %edi
callq 0x6170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
leaq 0x123a8(%rip), %rsi     # 0x1f206
callq 0x6100
jmp 0xce65
movq 0x18(%rsp), %rdi
movq 0x2217f(%rip), %rsi     # 0x2eff0
movq 0x22130(%rip), %rdx     # 0x2efa8
callq 0x64d0
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
callq 0x6240
jmp 0xcf50
movq 0x88(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x6200
movq 0x8(%rsp), %rcx
movq %rax, %rdx
movq 0x40(%rsp), %rax
addq %rdx, %rcx
movq 0x28(%rax), %rdx
subq %rdx, %rcx
movq %rcx, 0x70(%rsp)
movq %rax, %rsi
addq $0x8, %rsi
movq 0x28(%rax), %rdx
movq 0x70(%rsp), %rcx
leaq 0x50(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x6320
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x28(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x28(%rax)
callq 0x10160
jmp 0xcf1b
leaq 0x50(%rsp), %rdi
callq 0x61d0
movq 0x38(%rsp), %rax
addq $0xc8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x61d0
movq 0x98(%rsp), %rdi
callq 0x64f0
nopl (%rax)