Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,22 @@ public static String toLiteral(Object argument) {
return argument.toString();
}

private static String toStringLiteral(String agrument) {
String s = agrument.replaceAll("(['\\\\])", "\\\\$1");
if (s.contains("\n")) {
return "\"\"\"" + s + "\"\"\"";
private static String toStringLiteral(String argument) {
if (argument.contains("\n")) {
// Handle multiline strings
if (argument.contains("\"\"\"")) {
// If the string contains """, use single quotes and escape newlines and quotes
return "'" + argument.replaceAll("(['\\\\])", "\\\\$1")
.replaceAll("\n", "\\\\n")
.replaceAll("\r", "\\\\r") + "'";
} else {
// Use triple quotes for multiline strings, but escape any ending triple quotes
String processed = argument.replaceAll("\"\"\"", "\\\\\"\\\\\"\\\\\"");
return "\"\"\"" + processed + "\"\"\"";
}
} else {
return "'" + s + "'";
// For single line strings, use the original approach with single quotes
return "'" + argument.replaceAll("(['\\\\])", "\\\\$1") + "'";
}
}

Expand Down