From dce456a2330210174fdcf03668142f8c4d123a07 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 27 Dec 2012 03:26:26 +0000 Subject: [PATCH] Add replacements for charCodeAt and fromCharCode. --- utf16.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/utf16.js b/utf16.js index 9c06cdd..87f9b91 100644 --- a/utf16.js +++ b/utf16.js @@ -90,6 +90,13 @@ var charAt = function(string, offset) { return substring(string, offset, offset + 1); }; +var charCodeAt = function(string, offset) { + var char = charAt(string, offset); + if (char.length != 2) + return char.charCodeAt(0); + return 0x10000 | (char.charCodeAt(0) & 0x03ff) << 10 | char.charCodeAt(1) & 0x03ff +}; + var length = function(string) { return unit2point(string, [string.length])[0]; }; @@ -111,10 +118,18 @@ var Unicode = function(string) { this.length = length(string); }; +Unicode.fromCharCode = function() { + return encode(arguments); +}; + Unicode.prototype.charAt = function(index) { return new Unicode(charAt(this.string, index)); }; +Unicode.prototype.charCodeAt = function(index) { + return charCodeAt(this.string, index); +}; + Unicode.prototype.substr = function(start, length) { return new Unicode(substr(this.string, start, length)); }; @@ -135,6 +150,7 @@ return { unit2point: unit2point, charAt: charAt, + charCodeAt: charCodeAt, length: length, substr: substr, substring: substring, -- 2.50.0