File tree 7 files changed +21
-3
lines changed
dotty/tools/dotc/printing
scala/quoted/runtime/impl/printers
7 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import typer.Implicits._
12
12
import typer .ImportInfo
13
13
import Variances .varianceSign
14
14
import util .SourcePosition
15
- import java .lang .Integer .toOctalString
16
15
import scala .util .control .NonFatal
17
16
import scala .annotation .switch
18
17
@@ -525,7 +524,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
525
524
case '"' => " \\\" "
526
525
case '\' ' => " \\\' "
527
526
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)
529
528
}
530
529
531
530
def toText (const : Constant ): Text = const.tag match {
Original file line number Diff line number Diff line change @@ -1419,7 +1419,7 @@ object SourceCode {
1419
1419
case '"' => " \\\" "
1420
1420
case '\' ' => " \\\' "
1421
1421
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)
1423
1423
}
1424
1424
1425
1425
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