Created
January 26, 2012 02:53
-
-
Save hiratara/1680664 to your computer and use it in GitHub Desktop.
My 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) | |
implicit def listToArray[T: ClassManifest](list: List[T]): Array[T] = | |
list.toArray | |
implicit def arrayToList[T](arr: Array[T]): List[T] = | |
(arr: scala.collection.mutable.WrappedArray[T]).toList | |
def unescapeHexChars(char1: Char, char2: Char): Byte = { | |
Integer.decode("0x" + char1 + char2).toByte | |
} | |
def unescape(str: List[Char]): List[Byte] = { | |
str match { | |
case '%' :: xs => unescapeHexChars(xs.head, xs.tail.head) :: | |
unescape(xs.tail.tail) | |
case x :: xs => x.toByte :: unescape(xs) | |
case Nil => Nil | |
} | |
} | |
println(new String(unescape(uriEscaped toCharArray), "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