File tree Expand file tree Collapse file tree 7 files changed +21
-3
lines changed
dotty/tools/dotc/printing
scala/quoted/runtime/impl/printers Expand file tree Collapse file tree 7 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import typer.Implicits._
1212import typer .ImportInfo
1313import Variances .varianceSign
1414import util .SourcePosition
15- import java .lang .Integer .toOctalString
1615import scala .util .control .NonFatal
1716import scala .annotation .switch
1817
@@ -525,7 +524,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
525524 case '"' => " \\\" "
526525 case '\' ' => " \\\' "
527526 case '\\ ' => " \\\\ "
528- case _ => if (ch.isControl) " \\ 0 " + toOctalString(ch) else String .valueOf(ch)
527+ case _ => if (ch.isControl) f " \u ${ch.toInt} %04x " else String .valueOf(ch)
529528 }
530529
531530 def toText (const : Constant ): Text = const.tag match {
Original file line number Diff line number Diff line change @@ -1419,7 +1419,7 @@ object SourceCode {
14191419 case '"' => " \\\" "
14201420 case '\' ' => " \\\' "
14211421 case '\\ ' => " \\\\ "
1422- case _ => if (ch.isControl) " \\ 0 " + Integer .toOctalString(ch) else String .valueOf(ch)
1422+ case _ => if (ch.isControl) f " \u ${ch.toInt} %04x " else String .valueOf(ch)
14231423 }
14241424
14251425 private def escapedString (str : String ): String = str flatMap escapedChar
Original file line number Diff line number Diff line change 1+ "\u001b"
2+ "\u0000\u0001\u0003"
3+ "ABC"
4+ "\u0080\u0081翿"
5+ "\t\n\r👋👌🥳"
Original file line number Diff line number Diff line change 1+ import scala .quoted .*
2+
3+ object Macro_1 :
4+ inline def stringLiteral (inline s : String ): String = $ {showExpr(' s )}
5+ def showExpr (s : Expr [? ])(using Quotes ): Expr [String ] = Expr (s.show.toString)
Original file line number Diff line number Diff line change 1+ @ main def Test =
2+ println(Macro_1 .stringLiteral(" \u001b " )) // "\u001b"
3+ println(Macro_1 .stringLiteral(" \u0000\u0001\u0003 " )) // "\u0000\u0001\u0003"
4+ println(Macro_1 .stringLiteral(" A\u0042 C" )) // "ABC"
5+ println(Macro_1 .stringLiteral(" \u0080\u0081\u7fff " )) // "\u0080\u0081翿"
6+ println(Macro_1 .stringLiteral(" \t\n\r 👋👌🥳" )) // "\t\n\r👋👌🥳"
Original file line number Diff line number Diff line change 1+ "\u001b"
Original file line number Diff line number Diff line change 1+ @ main def Test (): Unit =
2+ println(scala.compiletime.codeOf(" \u001b " ))
You can’t perform that action at this time.
0 commit comments