// File: /workspace/github_cpp_makefile_star2_O3/xelia-it[P]mustache/src/mustache-light.cpp
// Function: mustache::Mustache::htmlEscape(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void Mustache::htmlEscape(string& data)
{
    std::string buffer;

	auto it = data.cbegin();
	while (it != data.cend()) {
		int sz = 1;
		const uint8_t tchar = *it;

        // From Wikipedia: https://en.wikipedia.org/wiki/UTF-8
        // U+0000  - U+007F   0xxxxxxx
        // U+0080  - U+07FF   110xxxxx  10xxxxxx
        // U+0800  - U+FFFF   1110xxxx  10xxxxxx  10xxxxxx
        // U+10000 - U+10FFFF 11110xxx  10xxxxxx  10xxxxxx  10xxxxxx
		if ((tchar & 0x80) == 0x80) {
            // Multi-byte UTF-8 character
            if ((tchar & 0xC0) == 0xC0) {
                // 2-byte UTF-8 character
                // 110xxxxx
                sz = 2;
            } else if ((tchar & 0xE0) == 0xE0) {
                sz = 3; // 3-byte UTF-8 character
            } else if ((tchar & 0xF8) == 0xF8) {
                sz = 4; // 4-byte UTF-8 character
            }
			for (int cnt = 0; cnt < sz; ++cnt) {
				buffer.push_back(*it++);
			}
		} else { // single-byte character
			switch (tchar) {
			case '&':	buffer.append("&amp;");		break;
			case '\"':	buffer.append("&quot;");	break;
			case '\'':	buffer.append("&apos;");	break;
			case '<':	buffer.append("&lt;");		break;
			case '>':	buffer.append("&gt;");		break;
			case '%':	buffer.append("&percnt;");	break;
			default:
				if (! std::iscntrl(tchar)) {
					buffer.push_back(tchar);
				}
				break;
			}
			++it;
		}
	}
	data.swap(buffer);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpq $0x0, 0x8(%rsi)
je 0x1c493
movq (%rbx), %r13
leaq -0x48(%rbp), %r14
movzbl (%r13), %r15d
testb %r15b, %r15b
js 0x1c402
leal -0x22(%r15), %eax
cmpl $0x5, %eax
ja 0x1c430
leaq 0x12cb7(%rip), %rcx     # 0x2f0a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
leaq 0x13aa4(%rip), %rsi     # 0x2fe9b
jmpq *%rax
leaq 0x13ab3(%rip), %rsi     # 0x2feb3
jmp 0x1c478
andl $-0x40, %r15d
movb $0x1, %r12b
movsbl (%r13), %esi
movq %r14, %rdi
callq 0x179b0
cmpl $0xc0, %r15d
sete %al
incq %r13
testb %r12b, %al
movl $0x0, %r12d
jne 0x1c409
jmp 0x1c483
cmpl $0x3c, %r15d
je 0x1c471
cmpl $0x3e, %r15d
jne 0x1c445
leaq 0x13a6b(%rip), %rsi     # 0x2feae
jmp 0x1c478
movl %r15d, %edi
callq 0x18060
testl %eax, %eax
jne 0x1c480
movsbl %r15b, %esi
movq %r14, %rdi
callq 0x179b0
jmp 0x1c480
leaq 0x13a3c(%rip), %rsi     # 0x2fea2
jmp 0x1c478
leaq 0x13a26(%rip), %rsi     # 0x2fe95
jmp 0x1c478
leaq 0x13a31(%rip), %rsi     # 0x2fea9
movq %r14, %rdi
callq 0x18660
incq %r13
movq (%rbx), %rax
addq 0x8(%rbx), %rax
cmpq %rax, %r13
jne 0x1c3cf
leaq -0x48(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x17760
movq (%r14), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x1c4b3
callq 0x17ae0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c4c4
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x1c4d9
callq 0x17ae0
movq %rbx, %rdi
callq 0x18490
nop