cleaning up the code
This commit is contained in:
parent
d084074d0c
commit
7bd721b1d7
|
@ -12,7 +12,7 @@ module.exports.UTF_16BE = function() {
|
||||||
this.match = function(det) {
|
this.match = function(det) {
|
||||||
var input = det.fRawInput;
|
var input = det.fRawInput;
|
||||||
|
|
||||||
if (input.length >= 2 && ((input[0] & 0xFF) == 0xFE && (input[1] & 0xFF) == 0xFF))
|
if (input.length >= 2 && ((input[0] & 0xff) == 0xfe && (input[1] & 0xff) == 0xff))
|
||||||
return new Match(det, this, confidence = 100);
|
return new Match(det, this, confidence = 100);
|
||||||
|
|
||||||
// TODO: Do some statistics to check for unsigned UTF-16BE
|
// TODO: Do some statistics to check for unsigned UTF-16BE
|
||||||
|
@ -27,7 +27,7 @@ module.exports.UTF_16LE = function() {
|
||||||
this.match = function(det) {
|
this.match = function(det) {
|
||||||
var input = det.fRawInput;
|
var input = det.fRawInput;
|
||||||
|
|
||||||
if (input.length >= 2 && ((input[0] & 0xFF) == 0xFF && (input[1] & 0xFF) == 0xFE)) {
|
if (input.length >= 2 && ((input[0] & 0xff) == 0xff && (input[1] & 0xff) == 0xfe)) {
|
||||||
// An LE BOM is present.
|
// An LE BOM is present.
|
||||||
if (input.length >= 4 && input[2] == 0x00 && input[3] == 0x00)
|
if (input.length >= 4 && input[2] == 0x00 && input[3] == 0x00)
|
||||||
// It is probably UTF-32 LE, not UTF-16
|
// It is probably UTF-32 LE, not UTF-16
|
||||||
|
@ -89,8 +89,8 @@ module.exports.UTF_32BE = function() {
|
||||||
return 'UTF-32BE';
|
return 'UTF-32BE';
|
||||||
};
|
};
|
||||||
this.getChar = function(input, index) {
|
this.getChar = function(input, index) {
|
||||||
return (input[index + 0] & 0xFF) << 24 | (input[index + 1] & 0xFF) << 16 |
|
return (input[index + 0] & 0xff) << 24 | (input[index + 1] & 0xff) << 16 |
|
||||||
(input[index + 2] & 0xFF) << 8 | (input[index + 3] & 0xFF);
|
(input[index + 2] & 0xff) << 8 | (input[index + 3] & 0xff);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
util.inherits(module.exports.UTF_32BE, UTF_32);
|
util.inherits(module.exports.UTF_32BE, UTF_32);
|
||||||
|
@ -100,8 +100,8 @@ module.exports.UTF_32LE = function() {
|
||||||
return 'UTF-32LE';
|
return 'UTF-32LE';
|
||||||
};
|
};
|
||||||
this.getChar = function(input, index) {
|
this.getChar = function(input, index) {
|
||||||
return (input[index + 3] & 0xFF) << 24 | (input[index + 2] & 0xFF) << 16 |
|
return (input[index + 3] & 0xff) << 24 | (input[index + 2] & 0xff) << 16 |
|
||||||
(input[index + 1] & 0xFF) << 8 | (input[index + 0] & 0xFF);
|
(input[index + 1] & 0xff) << 8 | (input[index + 0] & 0xff);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
util.inherits(module.exports.UTF_32LE, UTF_32);
|
util.inherits(module.exports.UTF_32LE, UTF_32);
|
||||||
|
|
|
@ -18,7 +18,7 @@ module.exports = function() {
|
||||||
confidence;
|
confidence;
|
||||||
|
|
||||||
if (det.fRawLength >= 3 &&
|
if (det.fRawLength >= 3 &&
|
||||||
(input[0] & 0xFF) == 0xef && (input[1] & 0xFF) == 0xbb && (input[2] & 0xFF) == 0xbf) {
|
(input[0] & 0xff) == 0xef && (input[1] & 0xff) == 0xbb && (input[2] & 0xff) == 0xbf) {
|
||||||
hasBOM = true;
|
hasBOM = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ module.exports = function() {
|
||||||
if ((b & 0x80) == 0)
|
if ((b & 0x80) == 0)
|
||||||
continue; // ASCII
|
continue; // ASCII
|
||||||
|
|
||||||
|
|
||||||
// Hi bit on char found. Figure out how long the sequence should be
|
// Hi bit on char found. Figure out how long the sequence should be
|
||||||
if ((b & 0x0e0) == 0x0c0) {
|
if ((b & 0x0e0) == 0x0c0) {
|
||||||
trailBytes = 1;
|
trailBytes = 1;
|
||||||
|
@ -38,20 +37,18 @@ module.exports = function() {
|
||||||
trailBytes = 3;
|
trailBytes = 3;
|
||||||
} else {
|
} else {
|
||||||
numInvalid++;
|
numInvalid++;
|
||||||
if (numInvalid > 5) {
|
if (numInvalid > 5)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
trailBytes = 0;
|
trailBytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that we've got the right number of trail bytes in the sequence
|
// Verify that we've got the right number of trail bytes in the sequence
|
||||||
for (;;) {
|
for (;;) {
|
||||||
i++;
|
i++;
|
||||||
if (i >= det.fRawLength) {
|
if (i >= det.fRawLength)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
b = input[i];
|
if ((input[i] & 0xc0) != 0x080) {
|
||||||
if ((b & 0xc0) != 0x080) {
|
|
||||||
numInvalid++;
|
numInvalid++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
1
match.js
1
match.js
|
@ -2,4 +2,5 @@
|
||||||
module.exports = function(det, rec, confidence, name, lang) {
|
module.exports = function(det, rec, confidence, name, lang) {
|
||||||
this.confidence = confidence;
|
this.confidence = confidence;
|
||||||
this.name = name || rec.name(det);
|
this.name = name || rec.name(det);
|
||||||
|
this.lang = lang;
|
||||||
};
|
};
|
Loading…
Reference in New Issue