From e646d43319f72096ca671995ba87923c53060332 Mon Sep 17 00:00:00 2001 From: ilor <kailoran@gmail.com> Date: Mon, 6 Jun 2011 13:36:30 +0200 Subject: [PATCH] Escaping \ with \\ and " with \" in StrSet to_string functions --- libwccl/values/strset.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libwccl/values/strset.cpp b/libwccl/values/strset.cpp index e3c6999..9c869ef 100644 --- a/libwccl/values/strset.cpp +++ b/libwccl/values/strset.cpp @@ -2,7 +2,7 @@ #include <libpwrutils/foreach.h> #include <libpwrutils/util.h> #include <sstream> - +#include <boost/algorithm/string.hpp> namespace Wccl { @@ -14,7 +14,12 @@ std::string StrSet::to_raw_string() const ss << "["; value_type::const_iterator it = set_.begin(); while(it != set_.end()) { - ss << '\"' << PwrNlp::to_utf8(*it) << '\"'; //TODO escaping + ss << '\"'; + std::string item = PwrNlp::to_utf8(*it); + boost::algorithm::replace_all(item, "\\", "\\\\"); + boost::algorithm::replace_all(item, "\"", "\\\""); + ss << item; + ss << '\"'; if(++it != set_.end()) { ss << ", "; } @@ -30,7 +35,10 @@ UnicodeString StrSet::to_raw_string_u() const value_type::const_iterator it = set_.begin(); while(it != set_.end()) { u.append(UNICODE_STRING("\"", 1)); - u.append(*it); //TODO escaping + UnicodeString item = *it; + item.findAndReplace(UNICODE_STRING("\\", 1), UNICODE_STRING("\\\\", 2)); + item.findAndReplace(UNICODE_STRING("\"", 1), UNICODE_STRING("\\\"", 2)); + u.append(item); u.append(UNICODE_STRING("\"", 1)); if(++it != set_.end()) { u.append(UNICODE_STRING(", ", 2)); -- GitLab