| 529 | template <typename Iter> struct serialize_str_char { |
| 530 | Iter oi; |
| 531 | void operator()(char c) { |
| 532 | switch (c) { |
| 533 | #define MAP(val, sym) \ |
| 534 | case val: \ |
| 535 | copy(sym, oi); \ |
| 536 | break |
| 537 | MAP('"', "\\\""); |
| 538 | MAP('\\', "\\\\"); |
| 539 | MAP('/', "\\/"); |
| 540 | MAP('\b', "\\b"); |
| 541 | MAP('\f', "\\f"); |
| 542 | MAP('\n', "\\n"); |
| 543 | MAP('\r', "\\r"); |
| 544 | MAP('\t', "\\t"); |
| 545 | #undef MAP |
| 546 | default: |
| 547 | if (static_cast<unsigned char>(c) < 0x20 || c == 0x7f) { |
| 548 | char buf[7]; |
| 549 | SNPRINTF(buf, sizeof(buf), "\\u%04x", c & 0xff); |
| 550 | copy(buf, buf + 6, oi); |
| 551 | } else { |
| 552 | *oi++ = c; |
| 553 | } |
| 554 | break; |
| 555 | } |
| 556 | } |
| 557 | }; |
| 558 | |
| 559 | template <typename Iter> void serialize_str(const std::string &s, Iter oi) { |