Scala worksheet doesn't show double quote as unicode escape

So, I don't know if this is even a bug, but I found it interesting. Paste this code in a scala worksheet, then take the list of Strings it puts out and paste them into a worksheet itself.

def inBase(base: Int)(value: Long): String = {
require(base < 36); require(base > 0); require(value >= 0)
def inBaseRecursive(vl: Long, bs: Int): Stream[Char] = {
if (vl == 0) Stream[Char]()
else {
val rem = vl % bs
val chr = rem match {
case num if num < 10 => num.toString.head
case letter => (letter + 55).toChar
}
chr #:: inBaseRecursive((vl - rem)/bs, bs)
}
}
inBaseRecursive(value, base).reverse mkString
}
val inHex: (Long) => String = inBase(16)
val a = (for (code <- 33 to 122)
yield s""""$code \\u00${inHex(code)}"""") mkString "\n"

You have to delete the second line "34 \u0022" to get it to run! The unicode escape for double quote terminates the string, although you can't use it on its own.

 

 

0
1 comment

Really, I guess all you need is "\u0022" -- before I realized what the problem was, I was looking for other problematic characters.

0

Please sign in to leave a comment.