Permalink
Browse files

faster unicode check

  • Loading branch information...
1 parent b1b7b87 commit 05664c4d6034301e1b740efb6eed275a2322d9ce @chjj chjj committed Oct 17, 2011
Showing with 12 additions and 33 deletions.
  1. +12 −33 lib/json.js
View
@@ -284,39 +284,18 @@ Parser.prototype._parse = function(data) {
break;
}
case 'unicode': {
- switch (ch) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case 'a':
- case 'A':
- case 'b':
- case 'B':
- case 'c':
- case 'C':
- case 'd':
- case 'D':
- case 'e':
- case 'E':
- case 'f':
- case 'F':
- this.unicode += ch;
- if (this.unicode.length === 4) {
- this.unicode = parseInt(this.unicode, 16);
- this.value += String.fromCharCode(this.unicode);
- this.unicode = '';
- this.state = 'string';
- }
- break;
- default:
- return this._unexpected(ch);
+ if ((ch >= '0' && ch <= '9')
+ || (ch >= 'A' && ch <= 'F')
+ || (ch >= 'a' && ch <= 'f')) {
+ this.unicode += ch;
+ if (this.unicode.length === 4) {
+ this.unicode = parseInt(this.unicode, 16);
+ this.value += String.fromCharCode(this.unicode);
+ this.unicode = '';
+ this.state = 'string';
+ }
+ } else {
+ return this._unexpected(ch);
}
break;
}

0 comments on commit 05664c4

Please sign in to comment.