Writing a string to a text node in XML (not into an attribute - otherwise you need more escaping).
| 712 | |
| 713 | /// Writing a string to a text node in XML (not into an attribute - otherwise you need more escaping). |
| 714 | inline void writeXMLStringForTextElement(const char * begin, const char * end, WriteBuffer & buf) |
| 715 | { |
| 716 | const char * pos = begin; |
| 717 | while (true) |
| 718 | { |
| 719 | /// NOTE Perhaps for some XML parsers, you need to escape the zero byte and some control characters. |
| 720 | const char * next_pos = find_first_symbols<'<', '&'>(pos, end); |
| 721 | |
| 722 | if (next_pos == end) |
| 723 | { |
| 724 | buf.write(pos, end - pos); |
| 725 | break; |
| 726 | } |
| 727 | if (*next_pos == '<') |
| 728 | { |
| 729 | buf.write(pos, next_pos - pos); |
| 730 | ++next_pos; |
| 731 | writeCString("<", buf); |
| 732 | } |
| 733 | else if (*next_pos == '&') |
| 734 | { |
| 735 | buf.write(pos, next_pos - pos); |
| 736 | ++next_pos; |
| 737 | writeCString("&", buf); |
| 738 | } |
| 739 | |
| 740 | pos = next_pos; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | inline void writeXMLStringForTextElement(std::string_view s, WriteBuffer & buf) |
| 745 | { |
no test coverage detected