Created
November 1, 2012 01:32
-
-
Save nlf/3991059 to your computer and use it in GitHub Desktop.
read string from buffer
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
function reads(buf, start, end) { | |
var pos = start, | |
bytes = [], | |
byte, | |
byte2; | |
while (pos < end) { | |
byte = buf[pos]; | |
if (byte > 191 && byte < 224) { | |
pos++; | |
byte = ((byte & 31) << 6) | (buf[pos] & 63); | |
} else if ((byte > 128 && byte < 191) || byte > 224) { | |
pos++; | |
byte2 = buf[pos]; | |
pos++; | |
byte = ((byte & 15) << 12) | ((byte2 & 63) << 6) | (buf[pos] & 63); | |
} | |
bytes.push(byte); | |
pos++; | |
} | |
return String.fromCharCode.apply(String, bytes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment