From 8c49c53dde6a51c4f49fe256fd389c424bb5a5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 18 Dec 2021 17:23:21 +0100 Subject: [PATCH] Add unescapedValue() for String objects --- include/uPDFTypes.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/uPDFTypes.h b/include/uPDFTypes.h index 0804d67..b9adf9f 100644 --- a/include/uPDFTypes.h +++ b/include/uPDFTypes.h @@ -26,6 +26,22 @@ #include #include +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 { /** @@ -151,6 +167,18 @@ namespace uPDFParser 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: std::string _value; };