1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.ToUnicodeMap = exports.IdentityToUnicodeMap = void 0;
|
28 |
|
29 | var _util = require("../shared/util.js");
|
30 |
|
31 | class 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 |
|
78 | exports.ToUnicodeMap = ToUnicodeMap;
|
79 |
|
80 | class 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 |
|
118 | exports.IdentityToUnicodeMap = IdentityToUnicodeMap; |
\ | No newline at end of file |