Skip to content
Snippets Groups Projects
Commit e646d433 authored by ilor's avatar ilor
Browse files

Escaping \ with \\ and " with \" in StrSet to_string functions

parent 3acdb4a2
No related merge requests found
......@@ -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));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment