Last active
February 7, 2019 08:49
-
-
Save desigens/2b26dd91ccca2a73e49a4d11a8fc05aa to your computer and use it in GitHub Desktop.
Revisions
-
desigens renamed this gist
Feb 7, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ /** * Decode string "ÐоÑква" (ISO-8859-1) to "Москва" (UTF-8) * @param {string} input * @returns {string} */ export function decodeISO88591toUTF8(input) { let string = ''; let i = 0; let currentChar = 0; -
desigens created this gist
Feb 7, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ /** * Decode string "ÐоÑква" (ISO-8859-1) to utf-8 one * @param {string} input * @returns {string} */ export function decodeHttpHeader(input) { let string = ''; let i = 0; let currentChar = 0; let nextChar = 0; let nextCharPlus = 0; while (i < input.length) { currentChar = input.charCodeAt(i); if (currentChar < 128) { string += String.fromCharCode(currentChar); i++; } else if (currentChar > 191 && currentChar < 224) { nextChar = input.charCodeAt(i + 1); string += String.fromCharCode( ((currentChar & 31) << 6) | (nextChar & 63) ); i += 2; } else { nextChar = input.charCodeAt(i + 1); nextCharPlus = input.charCodeAt(i + 2); string += String.fromCharCode( ((currentChar & 15) << 12) | ((nextChar & 63) << 6) | (nextCharPlus & 63) ); i += 3; } } return string; }