Skip to content
This repository has been archived by the owner on Sep 28, 2018. It is now read-only.

Commit

Permalink
Big5 encoding quirk. Per whatwg/encoding@7f9dda7
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Aug 21, 2015
1 parent 5108784 commit 763a0bc
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 763a0bc

Please sign in to comment.