diff --git a/lib/encoding.js b/lib/encoding.js index 87db3d0..bbdd071 100644 --- a/lib/encoding.js +++ b/lib/encoding.js @@ -917,6 +917,29 @@ if (typeof module !== "undefined" && module.exports) { return pointer; } + /** + * @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. + */ + function indexBig5PointerFor(code_point) { + + // 1. Let index be index big5. + var index_ = index('big5'); + + // 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_); + } + // // 7. API // @@ -1864,9 +1887,8 @@ if (typeof module !== "undefined" && module.exports) { if (inRange(code_point, 0x0000, 0x007F)) return code_point; - // 3. Let pointer be the index pointer for code point in index - // big5. - var pointer = indexPointerFor(code_point, index('big5')); + // 3. Let pointer be the index big5 pointer for code point. + var pointer = indexBig5PointerFor(code_point, index('big5')); // 4. If pointer is null, return error with code point. if (pointer === null)