-
-
Save seratch/1680875 to your computer and use it in GitHub Desktop.
@hiratara's first sample of Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val uriEscaped = args(0) | |
def unescapeHexChars(char1: Char, char2: Char): Byte = { | |
Integer.decode("0x" + char1 + char2).toByte | |
} | |
def unescape(str: List[Char]): List[Byte] = { | |
str match { | |
case '%' :: x1 :: x2 :: xs => unescapeHexChars(x1, x2) :: unescape(xs) | |
case x :: xs => x.toByte :: unescape(xs) | |
case Nil => Nil | |
} | |
} | |
println(new String(unescape(uriEscaped toList).toArray, "Shift_JIS")) | |
/* | |
% _JAVA_OPTIONS=-Dfile.encoding=UTF-8 scala /tmp/test.scala %92%b4%8bv%81X%82%cc%93%8c%8e%ba%97%96%89w%81B%89%bd%94N%82%d4%82%e8%82%be%81H10%94N%82%ad%82%e7%82%a2%82%a9%81H | |
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8 | |
超久々の東室蘭駅。何年ぶりだ?10年くらいか? | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment