https://project.mdnd-it.cc/work_packages/94
This commit is contained in:
2025-08-23 04:25:28 +02:00
parent 725516ad6c
commit 19cfa031d0
25823 changed files with 1095587 additions and 2801760 deletions
@@ -0,0 +1,21 @@
import { Stream } from "../../common";
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
export declare class EUCKRDecoder {
readonly fatal: boolean;
euckr_lead: number;
constructor(options: {
fatal: boolean;
});
/**
* @param {Stream} stream The stream of bytes being decoded.
* @param {number} bite The next byte read from the stream.
* @return {?(number|!Array.<number>)} The next code point(s)
* decoded, or null if not enough data exists in the input
* stream to decode a complete code point.
*/
handler(stream: Stream, bite: number): (number | Array<number>) | null;
}
@@ -0,0 +1,74 @@
import { decoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexCodePointFor } from "../../encoding/indexes";
import { end_of_stream, isASCIIByte } from "../../encoding/terminology";
import { inRange } from "../../encoding/utilities";
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
export class EUCKRDecoder {
constructor(options) {
this.fatal = options.fatal;
// euc-kr's decoder has an associated euc-kr lead (initially 0x00).
/** @type {number} */ this.euckr_lead = 0x00;
}
/**
* @param {Stream} stream The stream of bytes being decoded.
* @param {number} bite The next byte read from the stream.
* @return {?(number|!Array.<number>)} The next code point(s)
* decoded, or null if not enough data exists in the input
* stream to decode a complete code point.
*/
handler(stream, bite) {
// 1. If byte is end-of-stream and euc-kr lead is not 0x00, set
// euc-kr lead to 0x00 and return error.
if (bite === end_of_stream && this.euckr_lead !== 0) {
this.euckr_lead = 0x00;
return decoderError(this.fatal);
}
// 2. If byte is end-of-stream and euc-kr lead is 0x00, return
// finished.
if (bite === end_of_stream && this.euckr_lead === 0)
return finished;
// 3. If euc-kr lead is not 0x00, let lead be euc-kr lead, let
// pointer be null, set euc-kr lead to 0x00, and then run these
// substeps:
if (this.euckr_lead !== 0x00) {
const lead = this.euckr_lead;
let pointer = null;
this.euckr_lead = 0x00;
// 1. If byte is in the range 0x41 to 0xFE, inclusive, set
// pointer to (lead 0x81) × 190 + (byte 0x41).
if (inRange(bite, 0x41, 0xFE))
pointer = (lead - 0x81) * 190 + (bite - 0x41);
// 2. Let code point be null, if pointer is null, and the
// index code point for pointer in index euc-kr otherwise.
const code_point = (pointer === null)
? null : indexCodePointFor(pointer, index('euc-kr'));
// 3. If code point is null and byte is an ASCII byte, prepend
// byte to stream.
if (pointer === null && isASCIIByte(bite))
stream.prepend(bite);
// 4. If code point is null, return error.
if (code_point === null)
return decoderError(this.fatal);
// 5. Return a code point whose value is code point.
return code_point;
}
// 4. If byte is an ASCII byte, return a code point whose value
// is byte.
if (isASCIIByte(bite))
return bite;
// 5. If byte is in the range 0x81 to 0xFE, inclusive, set
// euc-kr lead to byte and return continue.
if (inRange(bite, 0x81, 0xFE)) {
this.euckr_lead = bite;
return null;
}
// 6. Return error.
return decoderError(this.fatal);
}
}
//# sourceMappingURL=EUCKRDecoder.js.map
@@ -0,0 +1 @@
{"version":3,"file":"EUCKRDecoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/EUCKRDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAMvB,YAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE3B,mEAAmE;QACnE,qBAAqB,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IAC/C,CAAC;IACD;;;;;;OAMG;IACH,OAAO,CAAC,MAAc,EAAE,IAAY;Q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AC/D,WAAW;QACX,IAAI,WAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QAEd,0DAA0D;QAC1D,2CAA2C;QAC3C,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,OAAO,IAAI,CAAC;SACb;QAED,mBAAmB;QACnB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,18 @@
import { Stream } from "../../common";
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
*/
export declare class EUCKREncoder {
readonly fatal: boolean;
constructor(options: {
fatal: boolean;
});
/**
* @param {Stream} stream Input stream.
* @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit.
*/
handler(stream: Stream, code_point: number): (number | Array<number>);
}
@@ -0,0 +1,41 @@
import { encoderError } from "../../encoding/encodings";
import { finished } from "../../encoding/finished";
import { index, indexPointerFor } from "../../encoding/indexes";
import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
*/
export class EUCKREncoder {
constructor(options) {
this.fatal = options.fatal;
}
/**
* @param {Stream} stream Input stream.
* @param {number} code_point Next code point read from the stream.
* @return {(number|!Array.<number>)} Byte(s) to emit.
*/
handler(stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === end_of_stream)
return finished;
// 2. If code point is an ASCII code point, return a byte whose
// value is code point.
if (isASCIICodePoint(code_point))
return code_point;
// 3. Let pointer be the index pointer for code point in index
// euc-kr.
const pointer = indexPointerFor(code_point, index('euc-kr'));
// 4. If pointer is null, return error with code point.
if (pointer === null)
return encoderError(code_point);
// 5. Let lead be Math.floor(pointer / 190) + 0x81.
const lead = Math.floor(pointer / 190) + 0x81;
// 6. Let trail be pointer % 190 + 0x41.
const trail = (pointer % 190) + 0x41;
// 7. Return two bytes whose values are lead and trail.
return [lead, trail];
}
}
//# sourceMappingURL=EUCKREncoder.js.map
@@ -0,0 +1 @@
{"version":3,"file":"EUCKREncoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/EUCKREncoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE7E;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAIvB,YAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,aAAa;YAC9B,OAAO,QAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,gBAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,8DAA8D;QAC9D,UAAU;QACV,MAAM,OAAO,GAAG,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAa,CAAC,CAAC;QAEzE,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;QAElC,mDAAmD;QACnD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAE9C,wCAAwC;QACxC,MAAM,KAAK,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAErC,uDAAuD;QACvD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,2 @@
export * from './EUCKRDecoder';
export * from './EUCKREncoder';
@@ -0,0 +1,3 @@
export * from './EUCKRDecoder';
export * from './EUCKREncoder';
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}