diff --git a/engine/XML.cpp b/engine/XML.cpp index 3c8f5a5a..4c35d11b 100644 --- a/engine/XML.cpp +++ b/engine/XML.cpp @@ -3914,6 +3914,18 @@ void XPath::dump(ObjList& lst, bool escape) const } } +String& XPath::escape(String& buf, const String& str, char quot, bool literal) +{ + if (quot != '"' && quot != '\'') + quot = '"'; + if (!str) + return buf << quot << quot; + buf << quot; + if (literal) + return XPathParseData::escapeStringLiteral(buf,str,quot) << quot; + return XmlSaxParser::escape(buf,str) << quot; +} + unsigned int XPath::maxStepPredicates() { return XPATH_MAX_PREDICATES; diff --git a/yatexml.h b/yatexml.h index c9caad08..0cf13560 100644 --- a/yatexml.h +++ b/yatexml.h @@ -2132,6 +2132,17 @@ public: */ void dump(ObjList& lst, bool escape = true) const; + /** + * Escape a string and add quoted value to buffer + * @param buf Destination buffer + * @param str String to escape + * @param quot Character to use for quoting. Use " if not " or ' + * @param literal Escape as literal (used in comparison operators) or + * XML string (used in function parameters) + * @return Destination buffer reference + */ + static String& escape(String& buf, const String& str, char quot = '"', bool literal = true); + /** * Retrieve the number of maximum allowed predicates in a path step * @return Maximum allowed predicates in a path step