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,78 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var encodings_1 = require("../../encoding/encodings");
var finished_1 = require("../../encoding/finished");
var indexes_1 = require("../../encoding/indexes");
var terminology_1 = require("../../encoding/terminology");
var utilities_1 = require("../../encoding/utilities");
/**
* @constructor
* @implements {Decoder}
* @param {{fatal: boolean}} options
*/
var EUCKRDecoder = /** @class */ (function () {
function EUCKRDecoder(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.
*/
EUCKRDecoder.prototype.handler = function (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 === terminology_1.end_of_stream && this.euckr_lead !== 0) {
this.euckr_lead = 0x00;
return encodings_1.decoderError(this.fatal);
}
// 2. If byte is end-of-stream and euc-kr lead is 0x00, return
// finished.
if (bite === terminology_1.end_of_stream && this.euckr_lead === 0)
return finished_1.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) {
var lead = this.euckr_lead;
var 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 (utilities_1.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.
var code_point = (pointer === null)
? null : indexes_1.indexCodePointFor(pointer, indexes_1.index('euc-kr'));
// 3. If code point is null and byte is an ASCII byte, prepend
// byte to stream.
if (pointer === null && terminology_1.isASCIIByte(bite))
stream.prepend(bite);
// 4. If code point is null, return error.
if (code_point === null)
return encodings_1.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 (terminology_1.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 (utilities_1.inRange(bite, 0x81, 0xFE)) {
this.euckr_lead = bite;
return null;
}
// 6. Return error.
return encodings_1.decoderError(this.fatal);
};
return EUCKRDecoder;
}());
exports.EUCKRDecoder = EUCKRDecoder;
//# sourceMappingURL=EUCKRDecoder.js.map
@@ -0,0 +1 @@
{"version":3,"file":"EUCKRDecoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/EUCKRDecoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAkE;AAClE,0DAAwE;AACxE,sDAAmD;AAEnD;;;;GAIG;AACH;IAME,sBAAY,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,8BAAO,GAAP,UAAQ,MAAc,EAAE,IAAY;QAClC,+DAA+D;QAC/D,wCA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,IAAI,yBAAW,CAAC,IAAI,CAAC;YACnB,OAAO,IAAI,CAAC;QAEd,0DAA0D;QAC1D,2CAA2C;QAC3C,IAAI,mBAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,OAAO,IAAI,CAAC;SACb;QAED,mBAAmB;QACnB,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IACH,mBAAC;AAAD,CAAC,AA9ED,IA8EC;AA9EY,oCAAY"}
@@ -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,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var encodings_1 = require("../../encoding/encodings");
var finished_1 = require("../../encoding/finished");
var indexes_1 = require("../../encoding/indexes");
var terminology_1 = require("../../encoding/terminology");
/**
* @constructor
* @implements {Encoder}
* @param {{fatal: boolean}} options
*/
var EUCKREncoder = /** @class */ (function () {
function EUCKREncoder(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.
*/
EUCKREncoder.prototype.handler = function (stream, code_point) {
// 1. If code point is end-of-stream, return finished.
if (code_point === terminology_1.end_of_stream)
return finished_1.finished;
// 2. If code point is an ASCII code point, return a byte whose
// value is code point.
if (terminology_1.isASCIICodePoint(code_point))
return code_point;
// 3. Let pointer be the index pointer for code point in index
// euc-kr.
var pointer = indexes_1.indexPointerFor(code_point, indexes_1.index('euc-kr'));
// 4. If pointer is null, return error with code point.
if (pointer === null)
return encodings_1.encoderError(code_point);
// 5. Let lead be Math.floor(pointer / 190) + 0x81.
var lead = Math.floor(pointer / 190) + 0x81;
// 6. Let trail be pointer % 190 + 0x41.
var trail = (pointer % 190) + 0x41;
// 7. Return two bytes whose values are lead and trail.
return [lead, trail];
};
return EUCKREncoder;
}());
exports.EUCKREncoder = EUCKREncoder;
//# sourceMappingURL=EUCKREncoder.js.map
@@ -0,0 +1 @@
{"version":3,"file":"EUCKREncoder.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/EUCKREncoder.ts"],"names":[],"mappings":";;AACA,sDAAwD;AACxD,oDAAmD;AACnD,kDAAgE;AAChE,0DAA6E;AAE7E;;;;GAIG;AACH;IAIE,sBAAY,OAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,8BAAO,GAAP,UAAQ,MAAc,EAAE,UAAkB;QACxC,sDAAsD;QACtD,IAAI,UAAU,KAAK,2BAAa;YAC9B,OAAO,mBAAQ,CAAC;QAElB,+DAA+D;QAC/D,uBAAuB;QACvB,IAAI,8BAAgB,CAAC,UAAU,CAAC;YAC9B,OAAO,UAAU,CAAC;QAEpB,8DAA8D;QAC9D,UAAU;QACV,IAAM,OAAO,GAAG,yBAAe,CAAC,UAAU,EAAE,eAAK,CAAC,QAAQ,CAAa,CAAC,CAAC;QAEzE,uDAAuD;QACvD,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,wBAAY,CAAC,UAAU,CAAC,CAAC;QAElC,mDAAmD;QACnD,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAE9C,wCAAwC;QACxC,IAAM,KAAK,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAErC,uDAAuD;QACvD,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IACH,mBAAC;AAAD,CAAC,AAxCD,IAwCC;AAxCY,oCAAY"}
@@ -0,0 +1,2 @@
export * from './EUCKRDecoder';
export * from './EUCKREncoder';
@@ -0,0 +1,8 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./EUCKRDecoder"));
__export(require("./EUCKREncoder"));
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/coders/euc-kr/index.ts"],"names":[],"mappings":";;;;;AAAA,oCAA+B;AAC/B,oCAA+B"}