| 14 | namespace utility |
| 15 | { |
| 16 | static std::string convert_from_xml(std::string_view _string, bool& _ok) |
| 17 | { |
| 18 | std::string ret; |
| 19 | _ok = true; |
| 20 | |
| 21 | size_t pos = _string.find('&'); |
| 22 | if (pos == std::string::npos) |
| 23 | return std::string{_string}; |
| 24 | |
| 25 | ret.reserve(_string.size()); |
| 26 | size_t old = 0; |
| 27 | while (pos != std::string::npos) |
| 28 | { |
| 29 | ret += _string.substr(old, pos - old); |
| 30 | |
| 31 | size_t end = _string.find(';', pos + 1); |
| 32 | if (end == std::string::npos) |
| 33 | { |
| 34 | _ok = false; |
| 35 | return ret; |
| 36 | } |
| 37 | |
| 38 | std::string_view tag = _string.substr(pos, end - pos + 1); |
| 39 | if (tag == "&") |
| 40 | ret += '&'; |
| 41 | else if (tag == "<") |
| 42 | ret += '<'; |
| 43 | else if (tag == ">") |
| 44 | ret += '>'; |
| 45 | else if (tag == "'") |
| 46 | ret += '\''; |
| 47 | else if (tag == """) |
| 48 | ret += '\"'; |
| 49 | else |
| 50 | { |
| 51 | _ok = false; |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | old = end + 1; |
| 56 | pos = _string.find('&', old); |
| 57 | } |
| 58 | ret += _string.substr(old, std::string::npos); |
| 59 | |
| 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | static std::string convert_to_xml(std::string_view _string) |
| 64 | { |