XUserDefinedEncoder.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { encoderError } from "../../encoding/encodings";
  2. import { finished } from "../../encoding/finished";
  3. import { end_of_stream, isASCIICodePoint } from "../../encoding/terminology";
  4. import { inRange } from "../../encoding/utilities";
  5. /**
  6. * @constructor
  7. * @implements {Encoder}
  8. * @param {{fatal: boolean}} options
  9. */
  10. var XUserDefinedEncoder = /** @class */ (function () {
  11. function XUserDefinedEncoder(options) {
  12. this.fatal = options.fatal;
  13. }
  14. /**
  15. * @param {Stream} stream Input stream.
  16. * @param {number} code_point Next code point read from the stream.
  17. * @return {(number|!Array.<number>)} Byte(s) to emit.
  18. */
  19. XUserDefinedEncoder.prototype.handler = function (stream, code_point) {
  20. // 1.If code point is end-of-stream, return finished.
  21. if (code_point === end_of_stream)
  22. return finished;
  23. // 2. If code point is an ASCII code point, return a byte whose
  24. // value is code point.
  25. if (isASCIICodePoint(code_point))
  26. return code_point;
  27. // 3. If code point is in the range U+F780 to U+F7FF, inclusive,
  28. // return a byte whose value is code point − 0xF780 + 0x80.
  29. if (inRange(code_point, 0xF780, 0xF7FF))
  30. return code_point - 0xF780 + 0x80;
  31. // 4. Return error with code point.
  32. return encoderError(code_point);
  33. };
  34. return XUserDefinedEncoder;
  35. }());
  36. export { XUserDefinedEncoder };
  37. //# sourceMappingURL=XUserDefinedEncoder.js.map