// File: 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
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x6bf40
movq -0x10(%rbp), %rdi
callq 0x68470
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x67680
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x67ae0
testb $0x1, %al
jne 0x752f9
jmp 0x754a4
movl $0x1, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6d5c0
movb (%rax), %al
movb %al, -0x45(%rbp)
movzbl -0x45(%rbp), %eax
andl $0x80, %eax
cmpl $0x80, %eax
jne 0x753d0
movzbl -0x45(%rbp), %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
jne 0x7533b
movl $0x2, -0x44(%rbp)
jmp 0x7536f
movzbl -0x45(%rbp), %eax
andl $0xe0, %eax
cmpl $0xe0, %eax
jne 0x75354
movl $0x3, -0x44(%rbp)
jmp 0x7536d
movzbl -0x45(%rbp), %eax
andl $0xf8, %eax
cmpl $0xf8, %eax
jne 0x7536b
movl $0x4, -0x44(%rbp)
jmp 0x7536d
jmp 0x7536f
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x753cb
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x6de10
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x6d5c0
movsbl (%rax), %esi
leaq -0x30(%rbp), %rdi
callq 0x6a190
jmp 0x753a4
jmp 0x753a6
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x75376
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x6e458
jmp 0x754c0
jmp 0x7549f
movzbl -0x45(%rbp), %eax
addl $-0x22, %eax
movl %eax, %ecx
movq %rcx, -0x70(%rbp)
subl $0x1c, %eax
ja 0x75475
movq -0x70(%rbp), %rax
leaq 0x32c5f(%rip), %rcx     # 0xa8050
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x3449d(%rip), %rsi     # 0xa989e
leaq -0x30(%rbp), %rdi
callq 0x6e080
jmp 0x7540c
jmp 0x75496
leaq 0x3448c(%rip), %rsi     # 0xa98a4
leaq -0x30(%rbp), %rdi
callq 0x6e080
jmp 0x75423
jmp 0x75496
leaq 0x3447f(%rip), %rsi     # 0xa98ab
leaq -0x30(%rbp), %rdi
callq 0x6e080
jmp 0x75437
jmp 0x75496
leaq 0x34472(%rip), %rsi     # 0xa98b2
leaq -0x30(%rbp), %rdi
callq 0x6e080
jmp 0x7544b
jmp 0x75496
leaq 0x34463(%rip), %rsi     # 0xa98b7
leaq -0x30(%rbp), %rdi
callq 0x6e080
jmp 0x7545f
jmp 0x75496
leaq 0x34454(%rip), %rsi     # 0xa98bc
leaq -0x30(%rbp), %rdi
callq 0x6e080
jmp 0x75473
jmp 0x75496
movzbl -0x45(%rbp), %edi
callq 0x6c3a0
cmpl $0x0, %eax
jne 0x75494
movsbl -0x45(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x6a190
jmp 0x75492
jmp 0x75494
jmp 0x75496
leaq -0x38(%rbp), %rdi
callq 0x69450
jmp 0x752d6
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x69810
leaq -0x30(%rbp), %rdi
callq 0x6e458
addq $0x70, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x6d7b0
nopl (%rax)