diff options
author | som-snytt <som.snytt@gmail.com> | 2016-04-20 07:28:54 -0700 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@typesafe.com> | 2016-04-20 16:28:54 +0200 |
commit | 956923acd32766c63cd0eab0788d1811481d7e30 (patch) | |
tree | 8ab85790662aaae53fa590c92aaa5be51ed060e4 /src/repl | |
parent | 65a7dfe3b913eb4e1310fdaedebb601ec9d13efd (diff) | |
download | scala-956923acd32766c63cd0eab0788d1811481d7e30.tar.gz scala-956923acd32766c63cd0eab0788d1811481d7e30.tar.bz2 scala-956923acd32766c63cd0eab0788d1811481d7e30.zip |
SI-9735 REPL prefer standard escapes for code text (#5086)
When constructing code text for compilation, the REPL
should prefer standard escape sequences, in case unicode
escapes are disabled.
Diffstat (limited to 'src/repl')
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/ReplStrings.scala | 16 |
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 } |