Use raw string literals to improve readability in OutputString

This commit is contained in:
Michael Hansen
2023-06-06 11:20:32 -07:00
parent bf3599c87a
commit 32a0aec535

View File

@@ -64,7 +64,7 @@ void OutputString(std::ostream &pyc_output, PycRef<PycString> str, char prefix,
const char* ch = str->value(); const char* ch = str->value();
int len = str->length(); int len = str->length();
if (ch == 0) { if (len == 0) {
pyc_output << "''"; pyc_output << "''";
return; return;
} }
@@ -90,7 +90,7 @@ void OutputString(std::ostream &pyc_output, PycRef<PycString> str, char prefix,
// Output the string // Output the string
if (!parent_f_string_quote) { if (!parent_f_string_quote) {
if (triple) if (triple)
pyc_output << (useQuotes ? "\"\"\"" : "'''"); pyc_output << (useQuotes ? R"(""")" : "'''");
else else
pyc_output << (useQuotes ? '"' : '\''); pyc_output << (useQuotes ? '"' : '\'');
} }
@@ -117,11 +117,11 @@ void OutputString(std::ostream &pyc_output, PycRef<PycString> str, char prefix,
} }
} else { } else {
if (!useQuotes && *ch == '\'') if (!useQuotes && *ch == '\'')
pyc_output << "\\'"; pyc_output << R"(\')";
else if (useQuotes && *ch == '"') else if (useQuotes && *ch == '"')
pyc_output << "\\\""; pyc_output << R"(\")";
else if (*ch == '\\') else if (*ch == '\\')
pyc_output << "\\\\"; pyc_output << R"(\\)";
else if (parent_f_string_quote && *ch == '{') else if (parent_f_string_quote && *ch == '{')
pyc_output << "{{"; pyc_output << "{{";
else if (parent_f_string_quote && *ch == '}') else if (parent_f_string_quote && *ch == '}')
@@ -133,7 +133,7 @@ void OutputString(std::ostream &pyc_output, PycRef<PycString> str, char prefix,
} }
if (!parent_f_string_quote) { if (!parent_f_string_quote) {
if (triple) if (triple)
pyc_output << (useQuotes ? "\"\"\"" : "'''"); pyc_output << (useQuotes ? R"(""")" : "'''");
else else
pyc_output << (useQuotes ? '"' : '\''); pyc_output << (useQuotes ? '"' : '\'');
} }