jschardet
Advanced tools
Comparing version 2.2.0 to 2.2.1
{ | ||
"name": "jschardet", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Character encoding auto-detection in JavaScript (port of python's chardet)", | ||
@@ -5,0 +5,0 @@ "author": "António Afonso", |
@@ -52,2 +52,3 @@ /* | ||
this._mFullLen = 0; | ||
this._mBasicAsciiLen = 0; | ||
} | ||
@@ -60,3 +61,3 @@ | ||
this.feed = function(aBuf) { | ||
this._mFullLen = aBuf.length; | ||
this._mFullLen += aBuf.length; | ||
for( var i = 0, c; i < aBuf.length; i++ ) { | ||
@@ -75,2 +76,4 @@ c = aBuf[i]; | ||
this._mMBCharLen += this._mCodingSM.getCurrentCharLen(); | ||
} else if( c.charCodeAt(0) < 128 ) { // codes higher than 127 are extended ASCII | ||
this._mBasicAsciiLen++; | ||
} | ||
@@ -91,3 +94,8 @@ } | ||
var unlike = 0.99; | ||
if( this._mNumOfMBChar < 6 && (this._mMBCharLen / this._mFullLen) <= 0.6 ) { | ||
var mbCharRatio = 0; | ||
var nonBasciAsciiLen = (this._mFullLen - this._mBasicAsciiLen); | ||
if( nonBasciAsciiLen > 0 ) { | ||
mbCharRatio = this._mMBCharLen / nonBasciAsciiLen; | ||
} | ||
if( this._mNumOfMBChar < 6 && mbCharRatio <= 0.6 ) { | ||
for( var i = 0; i < this._mNumOfMBChar; i++ ) { | ||
@@ -94,0 +102,0 @@ unlike *= Math.pow(ONE_CHAR_PROB, this._mNumOfMBChar); |
@@ -35,3 +35,5 @@ /* | ||
u.feed("\xc3\xa0"); | ||
u.feed("\xc3\xadabc"); | ||
u.feed("\xc3\xad"); | ||
u.feed("this is a very loooong basic ascii string"); | ||
u.feed("this is another very loooong basci ascii string"); | ||
u.close(); | ||
@@ -43,3 +45,3 @@ equals( u.result.encoding, "UTF-8" ); | ||
// àíà | ||
var str = "\xc3\xa0\xc3\xad\xc3\xa0abc"; | ||
var str = "\xc3\xa0\xc3\xad\xc3\xa0this is a very loooong basic ascii string, and this is another very long basic ascii string"; | ||
equals( jschardet.detect(str).encoding, "UTF-8" ); | ||
@@ -46,0 +48,0 @@ }); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1362674
17357