From fd0647db850118edb37d95897c40121621753ddc Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 30 Aug 2007 21:38:22 +0000 Subject: Added function to unquote strings. --- src/utility/stringUtils.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/utility/stringUtils.cpp') diff --git a/src/utility/stringUtils.cpp b/src/utility/stringUtils.cpp index 2455cfff..09c7f8f4 100644 --- a/src/utility/stringUtils.cpp +++ b/src/utility/stringUtils.cpp @@ -151,5 +151,41 @@ const string::size_type stringUtils::countASCIIchars } +const string stringUtils::unquote(const string& str) +{ + if (str.length() < 2) + return str; + + if (str[0] != '"' || str[str.length() - 1] != '"') + return str; + + string res; + res.reserve(str.length()); + + bool escaped = false; + + for (string::const_iterator it = str.begin() + 1, end = str.end() - 1 ; it != end ; ++it) + { + const string::value_type c = *it; + + if (escaped) + { + res += c; + escaped = false; + } + else if (!escaped && c == '\\') + { + escaped = true; + } + else + { + res += c; + } + } + + return res; +} + + } // utility } // vmime -- cgit v1.2.3