Created
March 22, 2019 05:15
-
-
Save uugan/b1b1243f764ae0eb1a11dfa396025921 to your computer and use it in GitHub Desktop.
Encoding windows-1251|cp1251 to utf-8
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
public static String windows1251_to_utf8(String str_1251) throws Exception{ | |
String str_utf8 = ""; | |
for(int i=0;i<str_1251.length();i++){ | |
int c = Character.codePointAt(str_1251,i); | |
switch (c){ | |
case 184: c=1105;break; //eo | |
case 168: c=1025;break; // capital EO | |
case 175: c=1198; break; //capital UE | |
case 191: c=1199; break; //ue | |
case 170: c=1256; break; // capital OE | |
case 186: c=1257; break; //oe | |
} | |
if (256>c && c>191) c=c+848; | |
switch(c) { | |
case 1111: c=1199;break; //u | |
case 1031: c= 1198; break; //capital U | |
case 1108: c=1257; break; //ou | |
case 1028: c=1256; break; //capital OU | |
} | |
str_utf8=str_utf8+(char)(c); | |
} | |
return str_utf8; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment