mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63565 954022d7-b5bf-4e40-9824-e11837661b57
173 lines
5.9 KiB
C++
173 lines
5.9 KiB
C++
#include "utils.h"
|
|
|
|
#include <boost/regex.hpp>
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
namespace xml {
|
|
|
|
namespace utils {
|
|
|
|
namespace {
|
|
|
|
#define XML_REPLACE_REGEX_EXPR "(&)|(')|(<)|(>)|(\")"
|
|
#define XML_REPLACE_FORMAT_EXPR "(?1&)(?2')(?3<)(?4>)(?5")"
|
|
|
|
#define XML_REPLACE_REGEX_EXPRW L"(&)|(')|(<)|(>)|(\")"
|
|
#define XML_REPLACE_FORMAT_EXPRW L"(?1&)(?2')(?3<)(?4>)(?5")"
|
|
|
|
#define XML_INV_REPLACE_REGEX_EXPR "(&)|(')|(<)|(>)|(")"
|
|
#define XML_INV_REPLACE_FORMAT_EXPR "(?1&)(?2')(?3<)(?4>)(?5\")"
|
|
|
|
#define XML_INV_REPLACE_REGEX_EXPRW L"(&)|(')|(<)|(>)|(")"
|
|
#define XML_INV_REPLACE_FORMAT_EXPRW L"(?1&)(?2')(?3<)(?4>)(?5\")"
|
|
|
|
const boost::wregex replace_text_to_xml_expr_w(XML_REPLACE_REGEX_EXPRW);
|
|
const std::wstring replace_text_to_xml_fmt_w(XML_REPLACE_FORMAT_EXPRW);
|
|
|
|
const boost::regex replace_text_to_xml_expr(XML_REPLACE_REGEX_EXPR);
|
|
const std::string replace_text_to_xml_fmt(XML_REPLACE_FORMAT_EXPR);
|
|
|
|
const boost::wregex replace_xml_to_text_expr_w(XML_INV_REPLACE_REGEX_EXPRW);
|
|
const std::wstring replace_xml_to_text_fmt_w(XML_INV_REPLACE_FORMAT_EXPRW);
|
|
|
|
const boost::regex replace_xml_to_text_expr(XML_INV_REPLACE_REGEX_EXPR);
|
|
const std::string replace_xml_to_text_fmt(XML_INV_REPLACE_FORMAT_EXPR);
|
|
|
|
|
|
#undef XML_REPLACE_REGEX_EXPR
|
|
#undef XML_REPLACE_FORMAT_EXPR
|
|
|
|
#undef XML_REPLACE_REGEX_EXPRW
|
|
#undef XML_REPLACE_FORMAT_EXPRW
|
|
|
|
}
|
|
|
|
namespace details {
|
|
std::wstring replace_text_to_xml_ImplRegEx(const std::wstring & Text)
|
|
{
|
|
return boost::regex_replace(Text, replace_text_to_xml_expr_w, replace_text_to_xml_fmt_w, boost::match_default | boost::format_all);
|
|
}
|
|
|
|
std::string replace_text_to_xml_ImplRegEx(const std::string & Text)
|
|
{
|
|
return boost::regex_replace(Text, replace_text_to_xml_expr, replace_text_to_xml_fmt, boost::match_default | boost::format_all);
|
|
}
|
|
|
|
std::wstring replace_xml_to_text_ImplRegEx(const std::wstring & Text)
|
|
{
|
|
return boost::regex_replace(Text, replace_xml_to_text_expr_w, replace_xml_to_text_fmt_w, boost::match_default | boost::format_all);
|
|
|
|
}
|
|
|
|
std::string replace_xml_to_text_ImplRegEx(const std::string & Text)
|
|
{
|
|
return boost::regex_replace(Text, replace_xml_to_text_expr, replace_xml_to_text_fmt, boost::match_default | boost::format_all);
|
|
}
|
|
|
|
std::wstring replace_text_to_xml_ImplReplace(const std::wstring & Text)
|
|
{
|
|
std::wstring newStr;
|
|
newStr.resize(Text.size());
|
|
newStr = ::boost::algorithm::replace_all_copy(Text, L"&", L"&");
|
|
::boost::algorithm::replace_all(newStr, L"'", L"'");
|
|
::boost::algorithm::replace_all(newStr, L"<", L"<");
|
|
::boost::algorithm::replace_all(newStr, L">", L">");
|
|
::boost::algorithm::replace_all(newStr, L"\"", L""");
|
|
return newStr;
|
|
}
|
|
|
|
std::string replace_text_to_xml_ImplReplace(const std::string & Text)
|
|
{
|
|
std::string newStr;
|
|
newStr.resize(Text.size());
|
|
newStr = ::boost::algorithm::replace_all_copy(Text, "&", "&");
|
|
::boost::algorithm::replace_all(newStr, "'", "'");
|
|
::boost::algorithm::replace_all(newStr, "<", "<");
|
|
::boost::algorithm::replace_all(newStr, ">", ">");
|
|
::boost::algorithm::replace_all(newStr, "\"", """);
|
|
return newStr;
|
|
}
|
|
std::string replace_amp_text_to_xml_ImplReplace(const std::string & Text)
|
|
{
|
|
std::string newStr;
|
|
newStr.resize(Text.size());
|
|
newStr = ::boost::algorithm::replace_all_copy(Text, "&", "&");
|
|
::boost::algorithm::replace_all(newStr, L"<", L"<");
|
|
::boost::algorithm::replace_all(newStr, L">", L">");
|
|
|
|
return newStr;
|
|
}
|
|
std::wstring replace_amp_text_to_xml_ImplReplace(const std::wstring & Text)
|
|
{
|
|
std::wstring newStr;
|
|
newStr.resize(Text.size());
|
|
newStr = ::boost::algorithm::replace_all_copy(Text, "&", "&");
|
|
::boost::algorithm::replace_all(newStr, L"<", L"<");
|
|
::boost::algorithm::replace_all(newStr, L">", L">");
|
|
|
|
return newStr;
|
|
}
|
|
std::wstring replace_xml_to_text_ImplReplace(const std::wstring & Text)
|
|
{
|
|
std::wstring newStr;
|
|
newStr = ::boost::algorithm::replace_all_copy(Text, L"&", L"&");
|
|
::boost::algorithm::replace_all(newStr, L"'", L"'");
|
|
::boost::algorithm::replace_all(newStr, L"<", L"<");
|
|
::boost::algorithm::replace_all(newStr, L">", L">");
|
|
::boost::algorithm::replace_all(newStr, L""", L"\"");
|
|
return newStr;
|
|
}
|
|
|
|
std::string replace_xml_to_text_ImplReplace(const std::string & Text)
|
|
{
|
|
std::string newStr;
|
|
newStr = ::boost::algorithm::replace_all_copy(Text, "&", "&");
|
|
::boost::algorithm::replace_all(newStr, "'", "'");
|
|
::boost::algorithm::replace_all(newStr, "<", "<");
|
|
::boost::algorithm::replace_all(newStr, ">", ">");
|
|
::boost::algorithm::replace_all(newStr, """, "\"");
|
|
return newStr;
|
|
}
|
|
|
|
std::wstring replace_lt_gt_ImplReplace(const std::wstring & Text)
|
|
{
|
|
std::wstring newStr;
|
|
newStr = ::boost::algorithm::replace_all_copy(Text, L"<", L"<");
|
|
::boost::algorithm::replace_all(newStr, L">", L">");
|
|
return newStr;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
std::wstring replace_lt_gt(const std::wstring & Text)
|
|
{
|
|
return details::replace_lt_gt_ImplReplace(Text);
|
|
}
|
|
std::wstring replace_amp_text_to_xml(const std::wstring & Text)
|
|
{
|
|
return details::replace_amp_text_to_xml_ImplReplace(Text);
|
|
}
|
|
std::wstring replace_text_to_xml(const std::wstring & Text)
|
|
{
|
|
return details::replace_text_to_xml_ImplReplace(Text);
|
|
}
|
|
|
|
std::string replace_text_to_xml(const std::string & Text)
|
|
{
|
|
return details::replace_text_to_xml_ImplReplace(Text);
|
|
}
|
|
|
|
std::wstring replace_xml_to_text(const std::wstring & Text)
|
|
{
|
|
return details::replace_xml_to_text_ImplReplace(Text);
|
|
}
|
|
|
|
std::string replace_xml_to_text(const std::string & Text)
|
|
{
|
|
return details::replace_xml_to_text_ImplReplace(Text);
|
|
}
|
|
|
|
}
|
|
}
|