MCPcopy Create free account
hub / github.com/MyGUI/mygui / convert_to_xml

Function convert_to_xml

MyGUIEngine/src/MyGUI_XmlDocument.cpp:63–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 += "&amp;";
79 else if (_string[pos] == '<')
80 ret += "&lt;";
81 else if (_string[pos] == '>')
82 ret += "&gt;";
83 else if (_string[pos] == '\'')
84 ret += "&apos;";
85 else if (_string[pos] == '\"')
86 ret += "&quot;";
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

Callers 1

saveMethod · 0.85

Calls 4

find_first_ofMethod · 0.80
substrMethod · 0.80
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected