|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- var util = require('util'),
- Match = require ('../match');
-
-
-
-
- function ISO_2022() {}
-
- ISO_2022.prototype.match = function(det) {
-
-
-
-
- var i, j;
- var escN;
- var hits = 0;
- var misses = 0;
- var shifts = 0;
- var quality;
-
-
- var text = det.fInputBytes;
- var textLen = det.fInputLen;
-
- scanInput:
- for (i = 0; i < textLen; i++) {
- if (text[i] == 0x1b) {
- checkEscapes:
- for (escN = 0; escN < this.escapeSequences.length; escN++) {
- var seq = this.escapeSequences[escN];
-
- if ((textLen - i) < seq.length)
- continue checkEscapes;
-
- for (j = 1; j < seq.length; j++)
- if (seq[j] != text[i + j])
- continue checkEscapes;
-
-
- hits++;
- i += seq.length - 1;
- continue scanInput;
- }
-
- misses++;
- }
-
-
- if (text[i] == 0x0e || text[i] == 0x0f)
- shifts++;
-
- }
-
- if (hits == 0)
- return null;
-
-
-
-
-
-
-
- quality = (100 * hits - 100 * misses) / (hits + misses);
-
-
-
-
- if (hits + shifts < 5)
- quality -= (5 - (hits + shifts)) * 10;
-
- return quality <= 0 ? null : new Match(det, this, quality);
- };
-
- module.exports.ISO_2022_JP = function() {
- this.name = function() {
- return 'ISO-2022-JP';
- };
- this.escapeSequences = [
- [ 0x1b, 0x24, 0x28, 0x43 ],
- [ 0x1b, 0x24, 0x28, 0x44 ],
- [ 0x1b, 0x24, 0x40 ],
- [ 0x1b, 0x24, 0x41 ],
- [ 0x1b, 0x24, 0x42 ],
- [ 0x1b, 0x26, 0x40 ],
- [ 0x1b, 0x28, 0x42 ],
- [ 0x1b, 0x28, 0x48 ],
- [ 0x1b, 0x28, 0x49 ],
- [ 0x1b, 0x28, 0x4a ],
- [ 0x1b, 0x2e, 0x41 ],
- [ 0x1b, 0x2e, 0x46 ]
- ];
- };
- util.inherits(module.exports.ISO_2022_JP, ISO_2022);
-
-
-
- module.exports.ISO_2022_KR = function() {
- this.name = function() {
- return 'ISO-2022-KR';
- };
- this.escapeSequences = [
- [ 0x1b, 0x24, 0x29, 0x43 ]
- ];
- };
- util.inherits(module.exports.ISO_2022_KR, ISO_2022);
-
-
-
- module.exports.ISO_2022_CN = function() {
- this.name = function() {
- return 'ISO-2022-CN';
- };
- this.escapeSequences = [
- [ 0x1b, 0x24, 0x29, 0x41 ],
- [ 0x1b, 0x24, 0x29, 0x47 ],
- [ 0x1b, 0x24, 0x2A, 0x48 ],
- [ 0x1b, 0x24, 0x29, 0x45 ],
- [ 0x1b, 0x24, 0x2B, 0x49 ],
- [ 0x1b, 0x24, 0x2B, 0x4A ],
- [ 0x1b, 0x24, 0x2B, 0x4B ],
- [ 0x1b, 0x24, 0x2B, 0x4C ],
- [ 0x1b, 0x24, 0x2B, 0x4D ],
- [ 0x1b, 0x4e ],
- [ 0x1b, 0x4f ]
- ];
- };
- util.inherits(module.exports.ISO_2022_CN, ISO_2022);
|