Index: src/js/uri.js |
diff --git a/src/js/uri.js b/src/js/uri.js |
index dca83c9b2325c649412206dd1611b90db72d5219..37ba6b102fb738589e6b728cda2b9e46d77a5aed 100644 |
--- a/src/js/uri.js |
+++ b/src/js/uri.js |
@@ -37,72 +37,6 @@ function HexValueOf(code) { |
return -1; |
} |
-// Does the char code correspond to an alpha-numeric char. |
-function isAlphaNumeric(cc) { |
- // a - z |
- if (97 <= cc && cc <= 122) return true; |
- // A - Z |
- if (65 <= cc && cc <= 90) return true; |
- // 0 - 9 |
- if (48 <= cc && cc <= 57) return true; |
- |
- return false; |
-} |
- |
-// Lazily initialized. |
-var hexCharCodeArray = 0; |
- |
-function URIAddEncodedOctetToBuffer(octet, result, index) { |
- result[index++] = 37; // Char code of '%'. |
- result[index++] = hexCharCodeArray[octet >> 4]; |
- result[index++] = hexCharCodeArray[octet & 0x0F]; |
- return index; |
-} |
- |
-function URIEncodeOctets(octets, result, index) { |
- if (hexCharCodeArray === 0) { |
- hexCharCodeArray = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, |
- 65, 66, 67, 68, 69, 70]; |
- } |
- index = URIAddEncodedOctetToBuffer(octets[0], result, index); |
- if (octets[1]) index = URIAddEncodedOctetToBuffer(octets[1], result, index); |
- if (octets[2]) index = URIAddEncodedOctetToBuffer(octets[2], result, index); |
- if (octets[3]) index = URIAddEncodedOctetToBuffer(octets[3], result, index); |
- return index; |
-} |
- |
-function URIEncodeSingle(cc, result, index) { |
- var x = (cc >> 12) & 0xF; |
- var y = (cc >> 6) & 63; |
- var z = cc & 63; |
- var octets = new InternalArray(3); |
- if (cc <= 0x007F) { |
- octets[0] = cc; |
- } else if (cc <= 0x07FF) { |
- octets[0] = y + 192; |
- octets[1] = z + 128; |
- } else { |
- octets[0] = x + 224; |
- octets[1] = y + 128; |
- octets[2] = z + 128; |
- } |
- return URIEncodeOctets(octets, result, index); |
-} |
- |
-function URIEncodePair(cc1 , cc2, result, index) { |
- var u = ((cc1 >> 6) & 0xF) + 1; |
- var w = (cc1 >> 2) & 0xF; |
- var x = cc1 & 3; |
- var y = (cc2 >> 6) & 0xF; |
- var z = cc2 & 63; |
- var octets = new InternalArray(4); |
- octets[0] = (u >> 2) + 240; |
- octets[1] = (((u & 3) << 4) | w) + 128; |
- octets[2] = ((x << 4) | y) + 128; |
- octets[3] = z + 128; |
- return URIEncodeOctets(octets, result, index); |
-} |
- |
function URIHexCharsToCharCode(highChar, lowChar) { |
var highCode = HexValueOf(highChar); |
var lowCode = HexValueOf(lowChar); |
@@ -168,37 +102,6 @@ function URIDecodeOctets(octets, result, index) { |
} |
// ECMA-262, section 15.1.3 |
-function Encode(uri, unescape) { |
- uri = TO_STRING(uri); |
- var uriLength = uri.length; |
- var array = new InternalArray(uriLength); |
- var index = 0; |
- for (var k = 0; k < uriLength; k++) { |
- var cc1 = %_StringCharCodeAt(uri, k); |
- if (unescape(cc1)) { |
- array[index++] = cc1; |
- } else { |
- if (cc1 >= 0xDC00 && cc1 <= 0xDFFF) throw MakeURIError(); |
- if (cc1 < 0xD800 || cc1 > 0xDBFF) { |
- index = URIEncodeSingle(cc1, array, index); |
- } else { |
- k++; |
- if (k == uriLength) throw MakeURIError(); |
- var cc2 = %_StringCharCodeAt(uri, k); |
- if (cc2 < 0xDC00 || cc2 > 0xDFFF) throw MakeURIError(); |
- index = URIEncodePair(cc1, cc2, array, index); |
- } |
- } |
- } |
- |
- var result = %NewString(array.length, NEW_ONE_BYTE_STRING); |
- for (var i = 0; i < array.length; i++) { |
- %_OneByteSeqStringSetChar(i, array[i], result); |
- } |
- return result; |
-} |
- |
-// ECMA-262, section 15.1.3 |
function Decode(uri, reserved) { |
uri = TO_STRING(uri); |
var uriLength = uri.length; |
@@ -318,48 +221,14 @@ function URIDecodeComponent(component) { |
// ECMA-262 - 15.1.3.3. |
function URIEncode(uri) { |
- var unescapePredicate = function(cc) { |
- if (isAlphaNumeric(cc)) return true; |
- // ! |
- if (cc == 33) return true; |
- // #$ |
- if (35 <= cc && cc <= 36) return true; |
- // &'()*+,-./ |
- if (38 <= cc && cc <= 47) return true; |
- // :; |
- if (58 <= cc && cc <= 59) return true; |
- // = |
- if (cc == 61) return true; |
- // ?@ |
- if (63 <= cc && cc <= 64) return true; |
- // _ |
- if (cc == 95) return true; |
- // ~ |
- if (cc == 126) return true; |
- |
- return false; |
- }; |
- return Encode(uri, unescapePredicate); |
+ uri = TO_STRING(uri); |
+ return %URIEncode(uri, true); |
} |
// ECMA-262 - 15.1.3.4 |
function URIEncodeComponent(component) { |
- var unescapePredicate = function(cc) { |
- if (isAlphaNumeric(cc)) return true; |
- // ! |
- if (cc == 33) return true; |
- // '()* |
- if (39 <= cc && cc <= 42) return true; |
- // -. |
- if (45 <= cc && cc <= 46) return true; |
- // _ |
- if (cc == 95) return true; |
- // ~ |
- if (cc == 126) return true; |
- |
- return false; |
- }; |
- return Encode(component, unescapePredicate); |
+ component = TO_STRING(component); |
+ return %URIEncode(component, false); |
} |
// ------------------------------------------------------------------- |