summaryrefslogtreecommitdiff
path: root/src/repl/scala/tools/nsc/interpreter/ReplStrings.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/repl/scala/tools/nsc/interpreter/ReplStrings.scala')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ReplStrings.scala16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/ReplStrings.scala b/src/repl/scala/tools/nsc/interpreter/ReplStrings.scala
index 1664546cab..bf7508cb4e 100644
--- a/src/repl/scala/tools/nsc/interpreter/ReplStrings.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ReplStrings.scala
@@ -11,13 +11,21 @@ import scala.reflect.internal.Chars
trait ReplStrings {
/** Convert a string into code that can recreate the string.
* This requires replacing all special characters by escape
- * codes. It does not add the surrounding " marks. */
+ * codes. It does not add the surrounding " marks.
+ */
def string2code(str: String): String = {
val res = new StringBuilder
for (c <- str) c match {
- case '"' | '\'' | '\\' => res += '\\' ; res += c
- case _ if c.isControl => res ++= Chars.char2uescape(c)
- case _ => res += c
+ case '"' => res ++= """\""""
+ case '\'' => res ++= """\'"""
+ case '\\' => res ++= """\\"""
+ case '\b' => res ++= """\b"""
+ case '\t' => res ++= """\t"""
+ case '\n' => res ++= """\n"""
+ case '\f' => res ++= """\f"""
+ case '\r' => res ++= """\r"""
+ case _ if c.isControl => res ++= Chars.char2uescape(c)
+ case _ => res += c
}
res.toString
}