File tree Expand file tree Collapse file tree 4 files changed +27
-2
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 4 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -439,6 +439,7 @@ object JavaScanners {
439439 }
440440 oct.asInstanceOf [Char ]
441441 end octal
442+ var skip = false
442443 def greatEscape : Char =
443444 nextChar()
444445 if '0' <= ch && ch <= '7' then octal
@@ -455,11 +456,12 @@ object JavaScanners {
455456 case '\\ ' => '\\ '
456457 case CR | LF if inTextBlock =>
457458 if ! scanOnly then nextChar()
459+ skip = true
458460 0
459461 case _ =>
460462 if ! scanOnly then error(" invalid escape character" , charOffset - 1 )
461463 ch
462- if x != 0 then nextChar()
464+ if ! skip then nextChar()
463465 x
464466 end greatEscape
465467
@@ -470,7 +472,7 @@ object JavaScanners {
470472 val res = ch
471473 nextChar()
472474 res
473- if c != 0 && ! scanOnly then putChar(c)
475+ if ! skip && ! scanOnly then putChar(c)
474476 end getlitch
475477
476478 /** Read a triple-quote delimited text block, starting after the first three double quotes.
Original file line number Diff line number Diff line change 6464====
6565X Y
6666====
67+ 582059
68+ ====
69+ 00
70+ ====
71+ 2a
72+ ====
73+ c3bf
74+ ====
Original file line number Diff line number Diff line change @@ -30,4 +30,16 @@ object Test extends App {
3030 println(" ====" )
3131 println(valueOf[TextBlocks .Octal .type ])
3232 println(" ====" )
33+ println(hexdump(valueOf[TextBlocks .Octal .type ]))
34+ println(" ====" )
35+ println(hexdump(valueOf[TextBlocks .Zero .type ].toString))
36+ println(" ====" )
37+ println(hexdump(valueOf[TextBlocks .Magic .type ].toString))
38+ println(" ====" )
39+ println(hexdump(valueOf[TextBlocks .Maxie .type ].toString))
40+ println(" ====" )
3341}
42+
43+ def hexdump (s : String ) = s.getBytes(io.Codec .UTF8 .charSet) // java.nio.charset.StandardCharsets.UTF_8
44+ .map(b => f " ${b & 0xff }%02x " )
45+ .mkString
Original file line number Diff line number Diff line change @@ -81,4 +81,7 @@ class TextBlocks {
8181""" ;
8282
8383 final static String Octal = "X\040 Y" ;
84+ final static char Zero = '\0' ;
85+ final static char Magic = '\52' ;
86+ final static char Maxie = '\377' ;
8487}
You can’t perform that action at this time.
0 commit comments