Created
May 2, 2010 12:51
-
-
Save kmizu/387103 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
object StringDump{ | |
class DumpableString(str: String) { | |
def dump = StringDump.dump(str) | |
} | |
implicit def enrichString(str: String) = new DumpableString(str) | |
def dump(str:String):String={ | |
str.getBytes("UTF-8").map{ | |
case 34 => "\\\"" | |
case 92 => "\\" | |
case n if 32 <= n && n <= 126 => new String(Array[Byte](n)) | |
case n if n < 0 => "\\%03o" format (256+n) | |
case n => "\\%03o" format n | |
}.mkString("\"","","\"") | |
} | |
def main(args: Array[String])={ | |
println(args(0).dump) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment