moved utf8tail() to strings utils

This commit is contained in:
Vitaly Puzrin 2014-04-13 21:39:29 +04:00
parent 33c90194d0
commit b949c39564
2 changed files with 8 additions and 7 deletions

View file

@ -10,11 +10,6 @@ var zstream = require('./zlib/zstream');
var gzheader = require('./zlib/gzheader');
// calculate tail size of utf8 char by current byte value
function utf8tail(code) {
return code >= 252 ? 6 : code >= 248 ? 5 : code >= 240 ? 4 : code >= 224 ? 3 : code >= 192 ? 2 : 1;
}
/**
* class Inflate
*
@ -220,10 +215,10 @@ Inflate.prototype.push = function(data, mode) {
next_out_utf8_index = strm.next_out_index - 6;
if (next_out_utf8_index < 0) { next_out_utf8_index = 0; }
tail = utf8tail(strm.next_out[next_out_utf8_index]);
tail = strings.utf8tail(strm.next_out[next_out_utf8_index]);
while (next_out_utf8_index + tail <= strm.next_out_index) {
next_out_utf8_index += tail;
tail = utf8tail(strm.next_out[next_out_utf8_index]);
tail = strings.utf8tail(strm.next_out[next_out_utf8_index]);
}
// shit happened - broken tail. then take it all.

View file

@ -119,3 +119,9 @@ exports.binstring2buf = function(str) {
}
return buf;
};
// calculate tail size of utf8 char by current byte value
exports.utf8tail = function(code) {
return code >= 252 ? 6 : code >= 248 ? 5 : code >= 240 ? 4 : code >= 224 ? 3 : code >= 192 ? 2 : 1;
};