Skip to content

Instantly share code, notes, and snippets.

@seratch
Forked from hiratara/uriunescape.scala
Created January 26, 2012 03:51
Show Gist options
  • Save seratch/1680875 to your computer and use it in GitHub Desktop.
Save seratch/1680875 to your computer and use it in GitHub Desktop.
@hiratara's first sample of Scala
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