From 39394ef0b75dac11aa141c796111238e6c689bbd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 11 Aug 2022 20:43:22 +0100 Subject: Don't define function in header, also use string_view to avoid copying --- gentoobrowse-api/domain/converters.impl.h | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/gentoobrowse-api/domain/converters.impl.h b/gentoobrowse-api/domain/converters.impl.h index ebff336..1d79e56 100644 --- a/gentoobrowse-api/domain/converters.impl.h +++ b/gentoobrowse-api/domain/converters.impl.h @@ -18,15 +18,6 @@ namespace Slicer { std::vector & list; }; - std::string - escapePqChar(char c) - { - if (c == '"') { - return std::string("\\\"", 2); - } - return std::string(1, c); - } - template void packPqVar(std::ostream & s, const T & l) @@ -35,9 +26,14 @@ namespace Slicer { s << l; } else { - s << "\""; - std::transform(l.begin(), l.end(), std::ostream_iterator(s), escapePqChar); - s << "\""; + s << '\"'; + std::transform(l.begin(), l.end(), std::ostream_iterator(s), [](const char & c) { + if (c == '"') { + return std::string_view(R"(\")"); + } + return std::string_view(&c, 1); + }); + s << '\"'; } } -- cgit v1.2.3