From 32a0aec535ee94666497330467d53676d676ba02 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Tue, 6 Jun 2023 11:20:32 -0700 Subject: [PATCH] Use raw string literals to improve readability in OutputString --- pyc_string.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyc_string.cpp b/pyc_string.cpp index 69287c6..4b18b49 100644 --- a/pyc_string.cpp +++ b/pyc_string.cpp @@ -64,7 +64,7 @@ void OutputString(std::ostream &pyc_output, PycRef str, char prefix, const char* ch = str->value(); int len = str->length(); - if (ch == 0) { + if (len == 0) { pyc_output << "''"; return; } @@ -90,7 +90,7 @@ void OutputString(std::ostream &pyc_output, PycRef str, char prefix, // Output the string if (!parent_f_string_quote) { if (triple) - pyc_output << (useQuotes ? "\"\"\"" : "'''"); + pyc_output << (useQuotes ? R"(""")" : "'''"); else pyc_output << (useQuotes ? '"' : '\''); } @@ -117,11 +117,11 @@ void OutputString(std::ostream &pyc_output, PycRef str, char prefix, } } else { if (!useQuotes && *ch == '\'') - pyc_output << "\\'"; + pyc_output << R"(\')"; else if (useQuotes && *ch == '"') - pyc_output << "\\\""; + pyc_output << R"(\")"; else if (*ch == '\\') - pyc_output << "\\\\"; + pyc_output << R"(\\)"; else if (parent_f_string_quote && *ch == '{') pyc_output << "{{"; else if (parent_f_string_quote && *ch == '}') @@ -133,7 +133,7 @@ void OutputString(std::ostream &pyc_output, PycRef str, char prefix, } if (!parent_f_string_quote) { if (triple) - pyc_output << (useQuotes ? "\"\"\"" : "'''"); + pyc_output << (useQuotes ? R"(""")" : "'''"); else pyc_output << (useQuotes ? '"' : '\''); }