Index: src/uri.js |
=================================================================== |
--- src/uri.js (revision 6653) |
+++ src/uri.js (working copy) |
@@ -90,11 +90,13 @@ |
} |
-function URIHexCharsToCharCode(ch1, ch2) { |
- if (HexValueOf(ch1) == -1 || HexValueOf(ch2) == -1) { |
+function URIHexCharsToCharCode(highChar, lowChar) { |
+ var highCode = HexValueOf(highChar); |
+ var lowCode = HexValueOf(lowChar); |
+ if (highCode == -1 || lowCode == -1) { |
throw new $URIError("URI malformed"); |
} |
- return HexStrToCharCode(ch1 + ch2); |
+ return (highCode << 4) + lowCode; |
} |
@@ -196,7 +198,7 @@ |
var ch = uri.charAt(k); |
if (ch == '%') { |
if (k + 2 >= uriLength) throw new $URIError("URI malformed"); |
- var cc = URIHexCharsToCharCode(uri.charAt(++k), uri.charAt(++k)); |
+ var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k)); |
if (cc >> 7) { |
var n = 0; |
while (((cc << ++n) & 0x80) != 0) ; |
@@ -206,7 +208,7 @@ |
if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed"); |
for (var i = 1; i < n; i++) { |
if (uri.charAt(++k) != '%') throw new $URIError("URI malformed"); |
- octets[i] = URIHexCharsToCharCode(uri.charAt(++k), uri.charAt(++k)); |
+ octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k)); |
} |
index = URIDecodeOctets(octets, result, index); |
} else { |
@@ -325,9 +327,7 @@ |
} |
-function HexValueOf(c) { |
- var code = c.charCodeAt(0); |
- |
+function HexValueOf(code) { |
// 0-9 |
if (code >= 48 && code <= 57) return code - 48; |
// A-F |
@@ -356,18 +356,6 @@ |
} |
-// Converts hex string to char code. Not efficient. |
-function HexStrToCharCode(s) { |
- var m = 0; |
- var r = 0; |
- for (var i = s.length - 1; i >= 0; --i) { |
- r = r + (HexValueOf(s.charAt(i)) << m); |
- m = m + 4; |
- } |
- return r; |
-} |
- |
- |
// Returns true if all digits in string s are valid hex numbers |
function IsValidHex(s) { |
for (var i = 0; i < s.length; ++i) { |