22inline void XMLEscape(std::string_view s, Output output)
24 auto chunk = s.begin();
29 if (
auto uc =
static_cast<unsigned char>(c); uc < 32) {
30 output(std::string_view(chunk, it));
31 std::array<char, 6> buf = {
'&',
'#',
'x',
'0',
'0',
';'};
32 auto hex = [](
unsigned x) {
return (x < 10) ? char(x +
'0') : char(x - 10 +
'a'); };
33 buf[3] = hex(uc / 16);
34 buf[4] = hex(uc % 16);
35 output(std::string_view(buf.data(),
sizeof(buf)));
37 }
else if (c ==
'<') {
38 output(std::string_view(chunk, it));
41 }
else if (c ==
'>') {
42 output(std::string_view(chunk, it));
45 }
else if (c ==
'&') {
46 output(std::string_view(chunk, it));
49 }
else if (c ==
'"') {
50 output(std::string_view(chunk, it));
53 }
else if (c ==
'\'') {
54 output(std::string_view(chunk, it));
62 output(std::string_view(chunk, last));