jtc-utils
Version:
Utilities for Japanese Traditional Companies
41 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.utf16be = void 0;
const charset_ts_1 = require("./charset.js");
class Utf16beCharset {
get name() {
return "utf-16be";
}
createDecoder(options) {
return new charset_ts_1.StandardDecoder("utf-16be", options);
}
createEncoder(options) {
return new Utf16beEncoder();
}
isUnicode() {
return true;
}
isEbcdic() {
return false;
}
}
class Utf16beEncoder {
canEncode(str) {
return true;
}
encode(str, options) {
const out = new Uint8Array(str.length * 2);
const limit = options?.limit ?? Number.POSITIVE_INFINITY;
for (let i = 0; i < str.length; i++) {
const cp = str.charCodeAt(i);
out[i * 2] = (cp >>> 8) & 0xff;
out[i * 2 + 1] = cp & 0xff;
}
if (out.length > limit) {
return out.subarray(0, Math.floor(limit / 2) * 2);
}
return out;
}
}
exports.utf16be = new Utf16beCharset();
//# sourceMappingURL=utf16be.js.map