From: Jay Freeman (saurik) Date: Wed, 26 Dec 2012 14:33:36 +0000 (+0000) Subject: Simplify utf16.decode API (make points optional). X-Git-Url: https://git.saurik.com/utf16js.git/commitdiff_plain/9d0c291dbb4a69e382cc00552856e297b5a9fadf?ds=sidebyside Simplify utf16.decode API (make points optional). --- diff --git a/utf16.js b/utf16.js index 89322ec..e42f42f 100644 --- a/utf16.js +++ b/utf16.js @@ -2,31 +2,34 @@ if (typeof define !== 'function') { var define = require('amdefine')(module) } define(function(require) { -var decode = function(array, string) { +var decode = function(string, points) { + if (typeof points === "undefined") + points = []; + for (var i = 0, e = string.length; i != e; ++i) { var unit = string.charCodeAt(i); var part = unit & 0xfc00; if (part == 0xdc00) return null; else if (part != 0xd800) - array.push(unit); + points.push(unit); else if (++i == e) return null; else { var next = string.charCodeAt(i); if ((next & 0xfc00) != 0xdc00) return null; - array.push(0x10000 | (unit & 0x03ff) << 10 | next & 0x03ff); + points.push(0x10000 | (unit & 0x03ff) << 10 | next & 0x03ff); } } - return array; + return points; }; -var encode = function(array) { +var encode = function(points) { var units = []; - for (var i = 0, e = array.length; i != e; ++i) { - var point = array[i]; + for (var i = 0, e = points.length; i != e; ++i) { + var point = points[i]; if (point < 0x10000) units.push(point); else {