Skip to content

Instantly share code, notes, and snippets.

@isterin
Created October 15, 2012 17:23
Show Gist options
  • Save isterin/3893793 to your computer and use it in GitHub Desktop.
Save isterin/3893793 to your computer and use it in GitHub Desktop.
CharsetEncoder encLatin = Charset.forName("ISO-8859-1").newEncoder();
if (encLatin.canEncode(msg)) {
return Normalizer.
normalize(msg, Normalizer.Form.NFD).
replaceAll("[^\\p{ASCII}\\x0a\\x0d\\x20-\\x7a\\xa1\\xa3\\xa4\\xa5\\xa7\\xbf\\xc4\\xc5\\xc6\\xc7\\xc9\\xd1\\xd6\\xd8\\xdc\\xdf\\xe0\\xe4\\xe5\\xe6\\xe8\\xe9\\xec\\xf1\\xf2\\xf6\\xf8\\xf9\\xfc]", "");
} else {
return new String(Hex.encodeHex(msg.getBytes("UTF-16")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment