Houjie
2025-07-24 52a3ff1bce1417b39f6872d8e8cb378e9c2ccc6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { getArrayVal } from "../helper/getArrayVal";
import { inRange } from "./utilities";
import { getEncodingIndexes } from "./encoding-indexes-provider";
/**
 * @param {number} pointer The |pointer| to search for.
 * @param {(!Array.<?number>|undefined)} index The |index| to search within.
 * @return {?number} The code point corresponding to |pointer| in |index|,
 *     or null if |code point| is not in |index|.
 */
export function indexCodePointFor(pointer, index) {
    if (!index)
        return null;
    return index[pointer] || null;
}
/**
 * @param {number} code_point The |code point| to search for.
 * @param {!Array.<?number>} index The |index| to search within.
 * @return {?number} The first pointer corresponding to |code point| in
 *     |index|, or null if |code point| is not in |index|.
 */
export function indexPointerFor(code_point, index) {
    const pointer = index.indexOf(code_point);
    return pointer === -1 ? null : pointer;
}
/**
 * @param {string} name Name of the index.
 * @return {(!Array.<number>|!Array.<Array.<number>>)}
 *  */
export function index(name) {
    const encodingIndexes = getEncodingIndexes();
    if (!encodingIndexes) {
        throw Error("Indexes missing." +
            " Did you forget to include encoding-indexes.js first?");
    }
    return encodingIndexes[name];
}
/**
 * @param {number} pointer The |pointer| to search for in the gb18030 index.
 * @return {?number} The code point corresponding to |pointer| in |index|,
 *     or null if |code point| is not in the gb18030 index.
 */
export function indexGB18030RangesCodePointFor(pointer) {
    // 1. If pointer is greater than 39419 and less than 189000, or
    // pointer is greater than 1237575, return null.
    if ((pointer > 39419 && pointer < 189000) || (pointer > 1237575))
        return null;
    // 2. If pointer is 7457, return code point U+E7C7.
    if (pointer === 7457)
        return 0xE7C7;
    // 3. Let offset be the last pointer in index gb18030 ranges that
    // is equal to or less than pointer and let code point offset be
    // its corresponding code point.
    let offset = 0;
    let code_point_offset = 0;
    const idx = index('gb18030-ranges');
    for (let i = 0; i < idx.length; ++i) {
        /** @type {!Array.<number>} */
        const entry = getArrayVal(idx[i]);
        if (entry[0] <= pointer) {
            offset = entry[0];
            code_point_offset = entry[1];
        }
        else {
            break;
        }
    }
    // 4. Return a code point whose value is code point offset +
    // pointer − offset.
    return code_point_offset + pointer - offset;
}
/**
 * @param {number} code_point The |code point| to locate in the gb18030 index.
 * @return {number} The first pointer corresponding to |code point| in the
 *     gb18030 index.
 */
export function indexGB18030RangesPointerFor(code_point) {
    // 1. If code point is U+E7C7, return pointer 7457.
    if (code_point === 0xE7C7)
        return 7457;
    // 2. Let offset be the last code point in index gb18030 ranges
    // that is equal to or less than code point and let pointer offset
    // be its corresponding pointer.
    let offset = 0;
    let pointer_offset = 0;
    const idx = index('gb18030-ranges');
    for (let i = 0; i < idx.length; ++i) {
        const idxVal = idx[i];
        /** @type {!Array.<number>} */
        const entry = getArrayVal(idxVal);
        if (entry[1] <= code_point) {
            offset = entry[1];
            pointer_offset = entry[0];
        }
        else {
            break;
        }
    }
    // 3. Return a pointer whose value is pointer offset + code point
    // − offset.
    return pointer_offset + code_point - offset;
}
/**
 * @param {number} code_point The |code_point| to search for in the Shift_JIS
 *     index.
 * @return {?number} The code point corresponding to |pointer| in |index|,
 *     or null if |code point| is not in the Shift_JIS index.
 */
export function indexShiftJISPointerFor(code_point) {
    // 1. Let index be index jis0208 excluding all entries whose
    // pointer is in the range 8272 to 8835, inclusive.
    shift_jis_index = shift_jis_index ||
        index('jis0208').map(function (code_point, pointer) {
            return inRange(pointer, 8272, 8835) ? null : code_point;
        });
    const index_ = shift_jis_index;
    // 2. Return the index pointer for code point in index.
    return index_.indexOf(code_point);
}
let shift_jis_index;
/**
 * @param {number} code_point The |code_point| to search for in the big5
 *     index.
 * @return {?number} The code point corresponding to |pointer| in |index|,
 *     or null if |code point| is not in the big5 index.
 */
export function indexBig5PointerFor(code_point) {
    // 1. Let index be index Big5 excluding all entries whose pointer
    big5_index_no_hkscs = big5_index_no_hkscs ||
        index('big5').map((code_point, pointer) => (pointer < (0xA1 - 0x81) * 157) ? null : code_point);
    const index_ = big5_index_no_hkscs;
    // 2. If code point is U+2550, U+255E, U+2561, U+256A, U+5341, or
    // U+5345, return the last pointer corresponding to code point in
    // index.
    if (code_point === 0x2550 || code_point === 0x255E ||
        code_point === 0x2561 || code_point === 0x256A ||
        code_point === 0x5341 || code_point === 0x5345) {
        return index_.lastIndexOf(code_point);
    }
    // 3. Return the index pointer for code point in index.
    return indexPointerFor(code_point, index_);
}
let big5_index_no_hkscs;
//# sourceMappingURL=indexes.js.map