2
0

to_unicode_map.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.ToUnicodeMap = exports.IdentityToUnicodeMap = void 0;
  27. var _util = require("../shared/util.js");
  28. class ToUnicodeMap {
  29. constructor(cmap = []) {
  30. this._map = cmap;
  31. }
  32. get length() {
  33. return this._map.length;
  34. }
  35. forEach(callback) {
  36. for (const charCode in this._map) {
  37. callback(charCode, this._map[charCode].charCodeAt(0));
  38. }
  39. }
  40. has(i) {
  41. return this._map[i] !== undefined;
  42. }
  43. get(i) {
  44. return this._map[i];
  45. }
  46. charCodeOf(value) {
  47. const map = this._map;
  48. if (map.length <= 0x10000) {
  49. return map.indexOf(value);
  50. }
  51. for (const charCode in map) {
  52. if (map[charCode] === value) {
  53. return charCode | 0;
  54. }
  55. }
  56. return -1;
  57. }
  58. amend(map) {
  59. for (const charCode in map) {
  60. this._map[charCode] = map[charCode];
  61. }
  62. }
  63. }
  64. exports.ToUnicodeMap = ToUnicodeMap;
  65. class IdentityToUnicodeMap {
  66. constructor(firstChar, lastChar) {
  67. this.firstChar = firstChar;
  68. this.lastChar = lastChar;
  69. }
  70. get length() {
  71. return this.lastChar + 1 - this.firstChar;
  72. }
  73. forEach(callback) {
  74. for (let i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  75. callback(i, i);
  76. }
  77. }
  78. has(i) {
  79. return this.firstChar <= i && i <= this.lastChar;
  80. }
  81. get(i) {
  82. if (this.firstChar <= i && i <= this.lastChar) {
  83. return String.fromCharCode(i);
  84. }
  85. return undefined;
  86. }
  87. charCodeOf(v) {
  88. return Number.isInteger(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  89. }
  90. amend(map) {
  91. (0, _util.unreachable)("Should not call amend()");
  92. }
  93. }
  94. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;