// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x8(%rdx), %r13
movq (%rsi), %rax
movq %rsi, %r14
addq 0x28(%rsi), %r13
cmpq %rax, %r13
jae 0x7489
leaq 0x8(%r14), %r12
movq %rcx, %r15
movq %rdi, %rbx
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x53a0
cmpq $-0x1, %rax
je 0x7452
leaq -0x1(%rax), %rsi
movq %r12, %rdi
movq %rax, %rbp
callq 0x5380
cmpb $0x5c, (%rax)
je 0x73e1
addq 0x8(%r15), %rbp
movq 0x28(%r14), %rdx
leaq 0x8(%rsp), %r15
movq %r12, %rsi
movq %r15, %rdi
subq %rdx, %rbp
movq %rbp, %rcx
callq 0x5210
addq %rbp, 0x28(%r14)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7ca8
leaq 0x8(%rsp), %rdi
callq 0x50e0
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rax
movq %rax, 0x28(%r14)
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %r14
leaq 0x4d7c(%rip), %rsi      # 0xc1e7
movq %rax, %rdi
callq 0x50a0
movq 0xcb76(%rip), %rsi      # 0x13ff0
movq 0xcb27(%rip), %rdx      # 0x13fa8
movq %r14, %rdi
callq 0x5320
movq %rax, 0x28(%r14)
pushq $0x10
popq %rdi
callq 0x5100
movq %rax, %r14
leaq 0x4d48(%rip), %rsi      # 0xc1e7
movq %rax, %rdi
callq 0x50a0
jmp 0x7473
jmp 0x74ba
leaq 0x8(%rsp), %rdi
movq %rax, %rbx
callq 0x50e0
jmp 0x74c5
movq %r14, %rdi
movq %rax, %rbx
callq 0x5180
movq %rbx, %rdi
callq 0x5340