Last active
August 29, 2015 13:56
-
-
Save slimane/8855718 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
def getEncoding(text: String): Option[String] = { | |
def checkEncoding(encoding: String): Boolean = { | |
try{ | |
text == new String(text.getBytes(encoding), encoding) | |
}catch{ | |
case NonFatal(_) => false | |
case th: Throtable => throw th | |
} | |
} | |
List("ascii", "iso-2022-jp", "utf-8", "euc-jp", "sjis", "utf-16") | |
.par | |
.find(checkEncoding(_)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment