OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // +, | 237 // +, |
238 if (43 <= cc && cc <= 44) return true; | 238 if (43 <= cc && cc <= 44) return true; |
239 // / | 239 // / |
240 if (cc == 47) return true; | 240 if (cc == 47) return true; |
241 // :; | 241 // :; |
242 if (58 <= cc && cc <= 59) return true; | 242 if (58 <= cc && cc <= 59) return true; |
243 // = | 243 // = |
244 if (cc == 61) return true; | 244 if (cc == 61) return true; |
245 // ?@ | 245 // ?@ |
246 if (63 <= cc && cc <= 64) return true; | 246 if (63 <= cc && cc <= 64) return true; |
247 | 247 |
248 return false; | 248 return false; |
249 }; | 249 }; |
250 var string = ToString(uri); | 250 var string = ToString(uri); |
251 return Decode(string, reservedPredicate); | 251 return Decode(string, reservedPredicate); |
252 } | 252 } |
253 | 253 |
254 | 254 |
255 // ECMA-262 - 15.1.3.2. | 255 // ECMA-262 - 15.1.3.2. |
256 function URIDecodeComponent(component) { | 256 function URIDecodeComponent(component) { |
257 function reservedPredicate(cc) { return false; }; | 257 function reservedPredicate(cc) { return false; }; |
258 var string = ToString(component); | 258 var string = ToString(component); |
259 return Decode(string, reservedPredicate); | 259 return Decode(string, reservedPredicate); |
260 } | 260 } |
261 | 261 |
262 | 262 |
263 // Does the char code correspond to an alpha-numeric char. | 263 // Does the char code correspond to an alpha-numeric char. |
264 function isAlphaNumeric(cc) { | 264 function isAlphaNumeric(cc) { |
265 // a - z | 265 // a - z |
266 if (97 <= cc && cc <= 122) return true; | 266 if (97 <= cc && cc <= 122) return true; |
267 // A - Z | 267 // A - Z |
268 if (65 <= cc && cc <= 90) return true; | 268 if (65 <= cc && cc <= 90) return true; |
269 // 0 - 9 | 269 // 0 - 9 |
270 if (48 <= cc && cc <= 57) return true; | 270 if (48 <= cc && cc <= 57) return true; |
271 | 271 |
272 return false; | 272 return false; |
273 } | 273 } |
274 | 274 |
275 | 275 |
276 // ECMA-262 - 15.1.3.3. | 276 // ECMA-262 - 15.1.3.3. |
277 function URIEncode(uri) { | 277 function URIEncode(uri) { |
278 function unescapePredicate(cc) { | 278 function unescapePredicate(cc) { |
279 if (isAlphaNumeric(cc)) return true; | 279 if (isAlphaNumeric(cc)) return true; |
280 // ! | 280 // ! |
281 if (cc == 33) return true; | 281 if (cc == 33) return true; |
282 // #$ | 282 // #$ |
283 if (35 <= cc && cc <= 36) return true; | 283 if (35 <= cc && cc <= 36) return true; |
284 // &'()*+,-./ | 284 // &'()*+,-./ |
285 if (38 <= cc && cc <= 47) return true; | 285 if (38 <= cc && cc <= 47) return true; |
286 // :; | 286 // :; |
287 if (58 <= cc && cc <= 59) return true; | 287 if (58 <= cc && cc <= 59) return true; |
288 // = | 288 // = |
289 if (cc == 61) return true; | 289 if (cc == 61) return true; |
290 // ?@ | 290 // ?@ |
291 if (63 <= cc && cc <= 64) return true; | 291 if (63 <= cc && cc <= 64) return true; |
292 // _ | 292 // _ |
293 if (cc == 95) return true; | 293 if (cc == 95) return true; |
294 // ~ | 294 // ~ |
295 if (cc == 126) return true; | 295 if (cc == 126) return true; |
296 | 296 |
297 return false; | 297 return false; |
298 }; | 298 }; |
299 | 299 |
300 var string = ToString(uri); | 300 var string = ToString(uri); |
301 return Encode(string, unescapePredicate); | 301 return Encode(string, unescapePredicate); |
302 } | 302 } |
303 | 303 |
304 | 304 |
305 // ECMA-262 - 15.1.3.4 | 305 // ECMA-262 - 15.1.3.4 |
306 function URIEncodeComponent(component) { | 306 function URIEncodeComponent(component) { |
307 function unescapePredicate(cc) { | 307 function unescapePredicate(cc) { |
308 if (isAlphaNumeric(cc)) return true; | 308 if (isAlphaNumeric(cc)) return true; |
309 // ! | 309 // ! |
310 if (cc == 33) return true; | 310 if (cc == 33) return true; |
311 // '()* | 311 // '()* |
312 if (39 <= cc && cc <= 42) return true; | 312 if (39 <= cc && cc <= 42) return true; |
313 // -. | 313 // -. |
314 if (45 <= cc && cc <= 46) return true; | 314 if (45 <= cc && cc <= 46) return true; |
315 // _ | 315 // _ |
316 if (cc == 95) return true; | 316 if (cc == 95) return true; |
317 // ~ | 317 // ~ |
318 if (cc == 126) return true; | 318 if (cc == 126) return true; |
319 | 319 |
320 return false; | 320 return false; |
321 }; | 321 }; |
322 | 322 |
323 var string = ToString(component); | 323 var string = ToString(component); |
324 return Encode(string, unescapePredicate); | 324 return Encode(string, unescapePredicate); |
325 } | 325 } |
326 | 326 |
327 | 327 |
328 function HexValueOf(c) { | 328 function HexValueOf(c) { |
329 var code = c.charCodeAt(0); | 329 var code = c.charCodeAt(0); |
330 | 330 |
331 // 0-9 | 331 // 0-9 |
332 if (code >= 48 && code <= 57) return code - 48; | 332 if (code >= 48 && code <= 57) return code - 48; |
333 // A-F | 333 // A-F |
334 if (code >= 65 && code <= 70) return code - 55; | 334 if (code >= 65 && code <= 70) return code - 55; |
335 // a-f | 335 // a-f |
336 if (code >= 97 && code <= 102) return code - 87; | 336 if (code >= 97 && code <= 102) return code - 87; |
337 | 337 |
338 return -1; | 338 return -1; |
339 } | 339 } |
340 | 340 |
341 | 341 |
342 // Convert a character code to 4-digit hex string representation | 342 // Convert a character code to 4-digit hex string representation |
343 // 64 -> 0040, 62234 -> F31A. | 343 // 64 -> 0040, 62234 -> F31A. |
344 function CharCodeToHex4Str(cc) { | 344 function CharCodeToHex4Str(cc) { |
345 var r = ""; | 345 var r = ""; |
346 if (hexCharArray === 0) { | 346 if (hexCharArray === 0) { |
347 hexCharArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", | 347 hexCharArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 "unescape", URIUnescape, | 406 "unescape", URIUnescape, |
407 "decodeURI", URIDecode, | 407 "decodeURI", URIDecode, |
408 "decodeURIComponent", URIDecodeComponent, | 408 "decodeURIComponent", URIDecodeComponent, |
409 "encodeURI", URIEncode, | 409 "encodeURI", URIEncode, |
410 "encodeURIComponent", URIEncodeComponent | 410 "encodeURIComponent", URIEncodeComponent |
411 )); | 411 )); |
412 } | 412 } |
413 | 413 |
414 SetupURI(); | 414 SetupURI(); |
415 | 415 |
OLD | NEW |