From e1d6585423e5e005fc7828485ed273e7acb2e86a Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 13 Sep 2018 22:31:05 +0200 Subject: [PATCH] Simplify EscapePathForShell by using std functions. --- src/openrct2-ui/UiContext.Linux.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/openrct2-ui/UiContext.Linux.cpp b/src/openrct2-ui/UiContext.Linux.cpp index 0b56939935..4c391581ed 100644 --- a/src/openrct2-ui/UiContext.Linux.cpp +++ b/src/openrct2-ui/UiContext.Linux.cpp @@ -377,27 +377,13 @@ namespace OpenRCT2::Ui throw std::runtime_error(dialogMissingWarning); } - static std::string EscapePathForShell(const std::string& path) + static std::string EscapePathForShell(std::string path) { - char output[256] = { 0 }; - char* outputPtr = output; - *outputPtr = '"'; - outputPtr++; - - for (uint32_t i = 0; i < path.length(); i++) + for (size_t index = 0; (index = path.find('"', index)) != std::string::npos; index += 2) { - if (path[i] == '"') - { - *outputPtr = '\\'; - outputPtr++; - } - - *outputPtr = path[i]; - outputPtr++; + path.replace(index, 1, "\\\""); } - *outputPtr = '"'; - - return std::string(output); + return '"' + path + '"'; } };