Enhanced the escape_xml function to escape quotes if necessary.

This commit is contained in:
Moritz Bunkus 2005-05-21 18:07:29 +00:00
parent 01c0480771
commit 99d2e62869
2 changed files with 5 additions and 2 deletions

View File

@ -885,7 +885,8 @@ unescape(const string &source) {
}
string
escape_xml(const string &source) {
escape_xml(const string &source,
bool escape_quotes) {
string dst;
string::const_iterator src;
@ -897,6 +898,8 @@ escape_xml(const string &source) {
dst += ">";
else if (*src == '<')
dst += "&lt;";
else if (escape_quotes && (*src == '"'))
dst += "&quot;";
else
dst += *src;
src++;

View File

@ -225,7 +225,7 @@ string MTX_DLL_API join(const char *pattern, vector<string> &strings);
void MTX_DLL_API strip(string &s, bool newlines = false);
void MTX_DLL_API strip(vector<string> &v, bool newlines = false);
string MTX_DLL_API escape(const string &src);
string MTX_DLL_API escape_xml(const string &src);
string MTX_DLL_API escape_xml(const string &src, bool escape_quotes = false);
string MTX_DLL_API unescape(const string &src);
bool MTX_DLL_API starts_with(const string &s, const char *start,
int maxlen = -1);