PHP で CMS を作成しなければならなかったとき、次のような単純なunescape html
関数を作成しました。
function unescape($s) {
$s= preg_replace('/%u(....)/', '&#x$1;', $s);
$s= preg_replace('/%(..)/', '&#x$1;', $s);
return $s;
}
Boost.Regexを使用して C++ に変換する方法は?
PHP で CMS を作成しなければならなかったとき、次のような単純なunescape html
関数を作成しました。
function unescape($s) {
$s= preg_replace('/%u(....)/', '&#x$1;', $s);
$s= preg_replace('/%(..)/', '&#x$1;', $s);
return $s;
}
Boost.Regexを使用して C++ に変換する方法は?
私はそれが次のようになると思います:
std::string unescape(const std::string s)
{
std::string temp = boost::regex_replace(s, "%u(....)", "&#x$1;", boost::match_default);
temp = boost::regex_replace(temp, "%u(..)", "&#x$1;", boost::match_default);
return temp;
}
しかし、.
(DOT) は 16 進数値にのみ一致する必要があると思います。その場合、代わりに次のようなものを使用します。
std::string unescape(const std::string s)
{
return boost::regex_replace(s, "%u([0-9a-fA-F]{2}|[0-9a-fA-F]{4})", "&#x$1;",
boost::match_default);
}
(私はこれをテストしていないことに注意してください!)