// File: /workspace/github_cpp_makefile_star2_O1/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 0x1c3a8
movq (%rbx), %r13
leaq -0x48(%rbp), %r14
movzbl (%r13), %r15d
testb %r15b, %r15b
js 0x1c303
leal -0x22(%r15), %eax
cmpl $0x5, %eax
ja 0x1c345
leaq 0x13d59(%rip), %rcx     # 0x30040
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
leaq 0x14bb2(%rip), %rsi     # 0x30ea7
jmpq *%rax
leaq 0x14bc1(%rip), %rsi     # 0x30ebf
jmp 0x1c38d
notl %r15d
movl $0x2, %r12d
testb $-0x40, %r15b
je 0x1c32e
movl $0x3, %r12d
testb $-0x20, %r15b
je 0x1c32e
xorl %eax, %eax
testb $-0x8, %r15b
sete %al
leal (%rax,%rax,2), %r12d
incl %r12d
movsbl (%r13), %esi
movq %r14, %rdi
callq 0x179d0
incq %r13
decl %r12d
jne 0x1c32e
jmp 0x1c398
cmpl $0x3c, %r15d
je 0x1c386
cmpl $0x3e, %r15d
jne 0x1c35a
leaq 0x14b62(%rip), %rsi     # 0x30eba
jmp 0x1c38d
movl %r15d, %edi
callq 0x18080
testl %eax, %eax
jne 0x1c395
movsbl %r15b, %esi
movq %r14, %rdi
callq 0x179d0
jmp 0x1c395
leaq 0x14b33(%rip), %rsi     # 0x30eae
jmp 0x1c38d
leaq 0x14b1d(%rip), %rsi     # 0x30ea1
jmp 0x1c38d
leaq 0x14b28(%rip), %rsi     # 0x30eb5
movq %r14, %rdi
callq 0x18680
incq %r13
movq (%rbx), %rax
addq 0x8(%rbx), %rax
cmpq %rax, %r13
jne 0x1c2cd
leaq -0x48(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x17770
movq (%r14), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x1c3c8
callq 0x17b00
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c3d9
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x1c3ee
callq 0x17b00
movq %rbx, %rdi
callq 0x184b0