Skip to content

Instantly share code, notes, and snippets.

@thefish
Created May 21, 2013 08:31
Show Gist options
  • Save thefish/5618339 to your computer and use it in GitHub Desktop.
Save thefish/5618339 to your computer and use it in GitHub Desktop.
JS utf-8 to windows-1251 string converter
//utf8 to 1251 converter (1 byte format, RU/EN support only + any other symbols) by drgluck
function utf8_decode (aa) {
var bb = '', c = 0;
for (var i = 0; i < aa.length; i++) {
c = aa.charCodeAt(i);
if (c > 127) {
if (c > 1024) {
if (c == 1025) {
c = 1016;
} else if (c == 1105) {
c = 1032;
}
bb += String.fromCharCode(c - 848);
}
} else {
bb += aa.charAt(i);
}
}
return bb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment