Add unescapedValue() for String objects

This commit is contained in:
Grégory Soutadé 2021-12-18 17:23:21 +01:00
parent 224267f360
commit 8c49c53dde

View File

@ -26,6 +26,22 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
static std::string strReplace(const std::string& orig, const std::string& pattern, const std::string subst)
{
std::string res = orig;
std::size_t pos;
do
{
pos = res.find(pattern);
if (pos != std::string::npos)
res.replace(pos, pattern.size(), subst);
} while (pos != std::string::npos);
return res;
}
namespace uPDFParser namespace uPDFParser
{ {
/** /**
@ -151,6 +167,18 @@ namespace uPDFParser
return res; return res;
} }
// Remove escape character '\'
virtual std::string unescapedValue() {
// Unescape '\n', \r', '\', '(' and ')'
std::string res = strReplace(_value, "\\\\", "\\");
res = strReplace(res, "\\(", "(");
res = strReplace(res, "\\)", ")");
res = strReplace(res, "\\n", "\n");
res = strReplace(res, "\\r", "\r");
return res;
}
private: private:
std::string _value; std::string _value;
}; };