From 99d2e628696865b05cdf5042f4bf342d1143cc8f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 21 May 2005 18:07:29 +0000 Subject: [PATCH] Enhanced the escape_xml function to escape quotes if necessary. --- src/common/common.cpp | 5 ++++- src/common/common.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/common.cpp b/src/common/common.cpp index 3d5321de9..2bd40f43d 100644 --- a/src/common/common.cpp +++ b/src/common/common.cpp @@ -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 += "<"; + else if (escape_quotes && (*src == '"')) + dst += """; else dst += *src; src++; diff --git a/src/common/common.h b/src/common/common.h index abf0d3e41..6c0239f17 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -225,7 +225,7 @@ string MTX_DLL_API join(const char *pattern, vector &strings); void MTX_DLL_API strip(string &s, bool newlines = false); void MTX_DLL_API strip(vector &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);