UNPKG

2.51 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * JavaScript code in this page
4 *
5 * Copyright 2022 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
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.ToUnicodeMap = exports.IdentityToUnicodeMap = void 0;
28
29var _util = require("../shared/util.js");
30
31class ToUnicodeMap {
32 constructor(cmap = []) {
33 this._map = cmap;
34 }
35
36 get length() {
37 return this._map.length;
38 }
39
40 forEach(callback) {
41 for (const charCode in this._map) {
42 callback(charCode, this._map[charCode].charCodeAt(0));
43 }
44 }
45
46 has(i) {
47 return this._map[i] !== undefined;
48 }
49
50 get(i) {
51 return this._map[i];
52 }
53
54 charCodeOf(value) {
55 const map = this._map;
56
57 if (map.length <= 0x10000) {
58 return map.indexOf(value);
59 }
60
61 for (const charCode in map) {
62 if (map[charCode] === value) {
63 return charCode | 0;
64 }
65 }
66
67 return -1;
68 }
69
70 amend(map) {
71 for (const charCode in map) {
72 this._map[charCode] = map[charCode];
73 }
74 }
75
76}
77
78exports.ToUnicodeMap = ToUnicodeMap;
79
80class IdentityToUnicodeMap {
81 constructor(firstChar, lastChar) {
82 this.firstChar = firstChar;
83 this.lastChar = lastChar;
84 }
85
86 get length() {
87 return this.lastChar + 1 - this.firstChar;
88 }
89
90 forEach(callback) {
91 for (let i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
92 callback(i, i);
93 }
94 }
95
96 has(i) {
97 return this.firstChar <= i && i <= this.lastChar;
98 }
99
100 get(i) {
101 if (this.firstChar <= i && i <= this.lastChar) {
102 return String.fromCharCode(i);
103 }
104
105 return undefined;
106 }
107
108 charCodeOf(v) {
109 return Number.isInteger(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
110 }
111
112 amend(map) {
113 (0, _util.unreachable)("Should not call amend()");
114 }
115
116}
117
118exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
\No newline at end of file