Maintenance

This commit is contained in:
Dmitry Shirokov 2021-10-19 20:27:41 +11:00
parent 1aeb866af9
commit fb50dcbcdb
No known key found for this signature in database
GPG Key ID: B5BDB86B2BCFF8EC
8 changed files with 39 additions and 39 deletions

View File

@ -12,7 +12,7 @@ jobs:
strategy: strategy:
matrix: matrix:
node-version: [10.x, 12.x, 14.x] node-version: [12.x, 14.x, 16x]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2

View File

@ -7,10 +7,10 @@ export interface Recogniser {
} }
export interface Context { export interface Context {
fByteStats: number[]; byteStats: number[];
fC1Bytes: boolean; c1Bytes: boolean;
fRawInput: Uint8Array; rawInput: Uint8Array;
fRawLength: number; rawLen: number;
fInputBytes: Uint8Array; inputBytes: Uint8Array;
fInputLen: number; inputLen: number;
} }

View File

@ -36,8 +36,8 @@ class ISO_2022 implements Recogniser {
let quality; let quality;
// TODO: refactor me // TODO: refactor me
const text = det.fInputBytes; const text = det.inputBytes;
const textLen = det.fInputLen; const textLen = det.inputLen;
scanInput: for (i = 0; i < textLen; i++) { scanInput: for (i = 0; i < textLen; i++) {
if (text[i] == 0x1b) { if (text[i] == 0x1b) {

View File

@ -64,11 +64,11 @@ class IteratedChar {
} }
nextByte(det: Context) { nextByte(det: Context) {
if (this.nextIndex >= det.fRawLength) { if (this.nextIndex >= det.rawLen) {
this.done = true; this.done = true;
return -1; return -1;
} }
const byteValue = det.fRawInput[this.nextIndex++] & 0x00ff; const byteValue = det.rawInput[this.nextIndex++] & 0x00ff;
return byteValue; return byteValue;
} }
} }

View File

@ -58,9 +58,9 @@ class NGramParser {
} }
nextByte(det: Context) { nextByte(det: Context) {
if (this.byteIndex >= det.fInputLen) return -1; if (this.byteIndex >= det.inputLen) return -1;
return det.fInputBytes[this.byteIndex++] & 0xff; return det.inputBytes[this.byteIndex++] & 0xff;
} }
parse(det: Context, spaceCh: number) { parse(det: Context, spaceCh: number) {
@ -1080,7 +1080,7 @@ export class ISO_8859_1 extends sbcs {
} }
name(input: Context): string { name(input: Context): string {
return input && input.fC1Bytes ? 'windows-1252' : 'ISO-8859-1'; return input && input.c1Bytes ? 'windows-1252' : 'ISO-8859-1';
} }
} }
@ -1616,7 +1616,7 @@ export class ISO_8859_2 extends sbcs {
} }
name(det: Context): string { name(det: Context): string {
return det && det.fC1Bytes ? 'windows-1250' : 'ISO-8859-2'; return det && det.c1Bytes ? 'windows-1250' : 'ISO-8859-2';
} }
} }
@ -2632,7 +2632,7 @@ export class ISO_8859_7 extends sbcs {
} }
name(det: Context): string { name(det: Context): string {
return det && det.fC1Bytes ? 'windows-1253' : 'ISO-8859-7'; return det && det.c1Bytes ? 'windows-1253' : 'ISO-8859-7';
} }
language() { language() {
@ -3040,7 +3040,7 @@ export class ISO_8859_8 extends sbcs {
} }
name(det: Context): string { name(det: Context): string {
return det && det.fC1Bytes ? 'windows-1255' : 'ISO-8859-8'; return det && det.c1Bytes ? 'windows-1255' : 'ISO-8859-8';
} }
language() { language() {
@ -3380,7 +3380,7 @@ export class ISO_8859_9 extends sbcs {
} }
name(det: Context): string { name(det: Context): string {
return det && det.fC1Bytes ? 'windows-1254' : 'ISO-8859-9'; return det && det.c1Bytes ? 'windows-1254' : 'ISO-8859-9';
} }
language() { language() {
@ -4425,7 +4425,7 @@ module.exports.ISO_8859_7 = function() {
this.name = function(det) { this.name = function(det) {
if (typeof det == 'undefined') if (typeof det == 'undefined')
return 'ISO-8859-7'; return 'ISO-8859-7';
return det.fC1Bytes ? 'windows-1253' : 'ISO-8859-7'; return det.c1Bytes ? 'windows-1253' : 'ISO-8859-7';
}; };
language() { language() {

View File

@ -11,7 +11,7 @@ export class UTF_16BE implements Recogniser {
} }
match(det: Context): Match | null { match(det: Context): Match | null {
const input = det.fRawInput; const input = det.rawInput;
if ( if (
input.length >= 2 && input.length >= 2 &&
@ -31,7 +31,7 @@ export class UTF_16LE implements Recogniser {
return 'UTF-16LE'; return 'UTF-16LE';
} }
match(det: Context): Match | null { match(det: Context): Match | null {
const input = det.fRawInput; const input = det.rawInput;
if ( if (
input.length >= 2 && input.length >= 2 &&
@ -69,8 +69,8 @@ class UTF_32 implements Recogniser, WithGetChar {
numInvalid = 0, numInvalid = 0,
hasBOM = false, hasBOM = false,
confidence = 0; confidence = 0;
const limit = (det.fRawLength / 4) * 4; const limit = (det.rawLen / 4) * 4;
const input = det.fRawInput; const input = det.rawInput;
if (limit == 0) { if (limit == 0) {
return null; return null;

View File

@ -12,10 +12,10 @@ export default class Utf8 implements Recogniser {
numInvalid = 0, numInvalid = 0,
trailBytes = 0, trailBytes = 0,
confidence; confidence;
const input = det.fRawInput; const input = det.rawInput;
if ( if (
det.fRawLength >= 3 && det.rawLen >= 3 &&
(input[0] & 0xff) == 0xef && (input[0] & 0xff) == 0xef &&
(input[1] & 0xff) == 0xbb && (input[1] & 0xff) == 0xbb &&
(input[2] & 0xff) == 0xbf (input[2] & 0xff) == 0xbf
@ -24,7 +24,7 @@ export default class Utf8 implements Recogniser {
} }
// Scan for multi-byte sequences // Scan for multi-byte sequences
for (let i = 0; i < det.fRawLength; i++) { for (let i = 0; i < det.rawLen; i++) {
const b = input[i]; const b = input[i];
if ((b & 0x80) == 0) continue; // ASCII if ((b & 0x80) == 0) continue; // ASCII
@ -44,7 +44,7 @@ export default class Utf8 implements Recogniser {
// 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) break; if (i >= det.rawLen) break;
if ((input[i] & 0xc0) != 0x080) { if ((input[i] & 0xc0) != 0x080) {
numInvalid++; numInvalid++;

View File

@ -50,26 +50,26 @@ export const detect = (buffer: Uint8Array): string | null => {
export const analyse = (buffer: Uint8Array): Match[] => { export const analyse = (buffer: Uint8Array): Match[] => {
// Tally up the byte occurrence statistics. // Tally up the byte occurrence statistics.
const fByteStats = []; const byteStats = [];
for (let i = 0; i < 256; i++) fByteStats[i] = 0; for (let i = 0; i < 256; i++) byteStats[i] = 0;
for (let i = buffer.length - 1; i >= 0; i--) fByteStats[buffer[i] & 0x00ff]++; for (let i = buffer.length - 1; i >= 0; i--) byteStats[buffer[i] & 0x00ff]++;
let fC1Bytes = false; let c1Bytes = false;
for (let i = 0x80; i <= 0x9f; i += 1) { for (let i = 0x80; i <= 0x9f; i += 1) {
if (fByteStats[i] !== 0) { if (byteStats[i] !== 0) {
fC1Bytes = true; c1Bytes = true;
break; break;
} }
} }
const context: Context = { const context: Context = {
fByteStats, byteStats,
fC1Bytes, c1Bytes,
fRawInput: buffer, rawInput: buffer,
fRawLength: buffer.length, rawLen: buffer.length,
fInputBytes: buffer, inputBytes: buffer,
fInputLen: buffer.length, inputLen: buffer.length,
}; };
const matches = recognisers const matches = recognisers