From 693958f8b7cc6630bad440260eb0df96488068b6 Mon Sep 17 00:00:00 2001 From: gibbed Date: Sun, 4 Aug 2019 07:29:29 -0500 Subject: [PATCH] [Base] Fix escaping quote runs. --- src/xenia/base/cvar.cc | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/xenia/base/cvar.cc b/src/xenia/base/cvar.cc index 7ac498219..ef3b645da 100644 --- a/src/xenia/base/cvar.cc +++ b/src/xenia/base/cvar.cc @@ -95,11 +95,22 @@ std::string EscapeBasicString(const std::string& str) { } std::string EscapeMultilineBasicString(const std::string& str) { - const std::string three_escaped_quotes("\\\"\\\"\\\""); std::string result; - char lc = '\0'; int quote_run = 0; for (char c : str) { + if (quote_run > 0) { + if (c == '"') { + ++quote_run; + continue; + } + for (int i = 0; i < quote_run; ++i) { + if ((i % 3) == 2) { + result += "\\"; + } + result += '"'; + } + quote_run = 0; + } if (c == '\b') { result += "\\b"; } else if (c == '\t' || c == '\n') { @@ -110,15 +121,7 @@ std::string EscapeMultilineBasicString(const std::string& str) { // Silently drop \r. // result += c; } else if (c == '"') { - result += '"'; - if (lc == '"') { - ++quote_run; - if (quote_run >= 3) { - result.resize(result.size() - 3); - result += three_escaped_quotes; - quote_run = 0; - } - } + quote_run = 1; } else if (c == '\\') { result += "\\\\"; } else if (static_cast(c) < 0x20 || @@ -138,7 +141,12 @@ std::string EscapeMultilineBasicString(const std::string& str) { } else { result += c; } - lc = c; + } + for (int i = 0; i < quote_run; ++i) { + if ((i % 3) == 2) { + result += "\\"; + } + result += '"'; } return result; }