| 61 | } |
| 62 | |
| 63 | static std::string convert_to_xml(std::string_view _string) |
| 64 | { |
| 65 | std::string ret; |
| 66 | |
| 67 | size_t pos = _string.find_first_of("&<>'\""); |
| 68 | if (pos == std::string::npos) |
| 69 | return std::string{_string}; |
| 70 | |
| 71 | ret.reserve(_string.size() * 2); |
| 72 | size_t old = 0; |
| 73 | while (pos != std::string::npos) |
| 74 | { |
| 75 | ret += _string.substr(old, pos - old); |
| 76 | |
| 77 | if (_string[pos] == '&') |
| 78 | ret += "&"; |
| 79 | else if (_string[pos] == '<') |
| 80 | ret += "<"; |
| 81 | else if (_string[pos] == '>') |
| 82 | ret += ">"; |
| 83 | else if (_string[pos] == '\'') |
| 84 | ret += "'"; |
| 85 | else if (_string[pos] == '\"') |
| 86 | ret += """; |
| 87 | |
| 88 | old = pos + 1; |
| 89 | pos = _string.find_first_of("&<>'\"", old); |
| 90 | } |
| 91 | ret += _string.substr(old, std::string::npos); |
| 92 | |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | } |
| 97 |
no test coverage detected