diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-08-11 20:43:22 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-08-11 20:43:22 +0100 |
commit | 39394ef0b75dac11aa141c796111238e6c689bbd (patch) | |
tree | 89179174f877ff0fa656b5ac217b761161673f95 | |
parent | Use stringstream str by move (diff) | |
download | gentoobrowse-api-39394ef0b75dac11aa141c796111238e6c689bbd.tar.bz2 gentoobrowse-api-39394ef0b75dac11aa141c796111238e6c689bbd.tar.xz gentoobrowse-api-39394ef0b75dac11aa141c796111238e6c689bbd.zip |
Don't define function in header, also use string_view to avoid copying
-rw-r--r-- | gentoobrowse-api/domain/converters.impl.h | 20 |
1 files 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<T> & list; }; - std::string - escapePqChar(char c) - { - if (c == '"') { - return std::string("\\\"", 2); - } - return std::string(1, c); - } - template<typename T> 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<std::string>(s), escapePqChar); - s << "\""; + s << '\"'; + std::transform(l.begin(), l.end(), std::ostream_iterator<std::string_view>(s), [](const char & c) { + if (c == '"') { + return std::string_view(R"(\")"); + } + return std::string_view(&c, 1); + }); + s << '\"'; } } |