Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: src/uri.js

Issue 6460038: Version 3.1.3.... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/scanner.cc ('k') | src/v8globals.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 var z = cc2 & 63; 83 var z = cc2 & 63;
84 var octets = new $Array(4); 84 var octets = new $Array(4);
85 octets[0] = (u >> 2) + 240; 85 octets[0] = (u >> 2) + 240;
86 octets[1] = (((u & 3) << 4) | w) + 128; 86 octets[1] = (((u & 3) << 4) | w) + 128;
87 octets[2] = ((x << 4) | y) + 128; 87 octets[2] = ((x << 4) | y) + 128;
88 octets[3] = z + 128; 88 octets[3] = z + 128;
89 return URIEncodeOctets(octets, result, index); 89 return URIEncodeOctets(octets, result, index);
90 } 90 }
91 91
92 92
93 function URIHexCharsToCharCode(ch1, ch2) { 93 function URIHexCharsToCharCode(highChar, lowChar) {
94 if (HexValueOf(ch1) == -1 || HexValueOf(ch2) == -1) { 94 var highCode = HexValueOf(highChar);
95 var lowCode = HexValueOf(lowChar);
96 if (highCode == -1 || lowCode == -1) {
95 throw new $URIError("URI malformed"); 97 throw new $URIError("URI malformed");
96 } 98 }
97 return HexStrToCharCode(ch1 + ch2); 99 return (highCode << 4) | lowCode;
98 } 100 }
99 101
100 102
101 function URIDecodeOctets(octets, result, index) { 103 function URIDecodeOctets(octets, result, index) {
102 var value; 104 var value;
103 var o0 = octets[0]; 105 var o0 = octets[0];
104 if (o0 < 0x80) { 106 if (o0 < 0x80) {
105 value = o0; 107 value = o0;
106 } else if (o0 < 0xc2) { 108 } else if (o0 < 0xc2) {
107 throw new $URIError("URI malformed"); 109 throw new $URIError("URI malformed");
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 191
190 // ECMA-262, section 15.1.3 192 // ECMA-262, section 15.1.3
191 function Decode(uri, reserved) { 193 function Decode(uri, reserved) {
192 var uriLength = uri.length; 194 var uriLength = uri.length;
193 var result = new $Array(uriLength); 195 var result = new $Array(uriLength);
194 var index = 0; 196 var index = 0;
195 for (var k = 0; k < uriLength; k++) { 197 for (var k = 0; k < uriLength; k++) {
196 var ch = uri.charAt(k); 198 var ch = uri.charAt(k);
197 if (ch == '%') { 199 if (ch == '%') {
198 if (k + 2 >= uriLength) throw new $URIError("URI malformed"); 200 if (k + 2 >= uriLength) throw new $URIError("URI malformed");
199 var cc = URIHexCharsToCharCode(uri.charAt(++k), uri.charAt(++k)); 201 var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k));
200 if (cc >> 7) { 202 if (cc >> 7) {
201 var n = 0; 203 var n = 0;
202 while (((cc << ++n) & 0x80) != 0) ; 204 while (((cc << ++n) & 0x80) != 0) ;
203 if (n == 1 || n > 4) throw new $URIError("URI malformed"); 205 if (n == 1 || n > 4) throw new $URIError("URI malformed");
204 var octets = new $Array(n); 206 var octets = new $Array(n);
205 octets[0] = cc; 207 octets[0] = cc;
206 if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed"); 208 if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed");
207 for (var i = 1; i < n; i++) { 209 for (var i = 1; i < n; i++) {
208 if (uri.charAt(++k) != '%') throw new $URIError("URI malformed"); 210 if (uri.charAt(++k) != '%') throw new $URIError("URI malformed");
209 octets[i] = URIHexCharsToCharCode(uri.charAt(++k), uri.charAt(++k)); 211 octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt( ++k));
210 } 212 }
211 index = URIDecodeOctets(octets, result, index); 213 index = URIDecodeOctets(octets, result, index);
212 } else { 214 } else {
213 if (reserved(cc)) { 215 if (reserved(cc)) {
214 result[index++] = 37; // Char code of '%'. 216 result[index++] = 37; // Char code of '%'.
215 result[index++] = uri.charCodeAt(k - 1); 217 result[index++] = uri.charCodeAt(k - 1);
216 result[index++] = uri.charCodeAt(k); 218 result[index++] = uri.charCodeAt(k);
217 } else { 219 } else {
218 result[index++] = cc; 220 result[index++] = cc;
219 } 221 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 if (cc == 126) return true; 320 if (cc == 126) return true;
319 321
320 return false; 322 return false;
321 }; 323 };
322 324
323 var string = ToString(component); 325 var string = ToString(component);
324 return Encode(string, unescapePredicate); 326 return Encode(string, unescapePredicate);
325 } 327 }
326 328
327 329
328 function HexValueOf(c) { 330 function HexValueOf(code) {
329 var code = c.charCodeAt(0);
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",
348 "A", "B", "C", "D", "E", "F"]; 348 "A", "B", "C", "D", "E", "F"];
349 } 349 }
350 for (var i = 0; i < 4; ++i) { 350 for (var i = 0; i < 4; ++i) {
351 var c = hexCharArray[cc & 0x0F]; 351 var c = hexCharArray[cc & 0x0F];
352 r = c + r; 352 r = c + r;
353 cc = cc >>> 4; 353 cc = cc >>> 4;
354 } 354 }
355 return r; 355 return r;
356 } 356 }
357 357
358 358
359 // Converts hex string to char code. Not efficient.
360 function HexStrToCharCode(s) {
361 var m = 0;
362 var r = 0;
363 for (var i = s.length - 1; i >= 0; --i) {
364 r = r + (HexValueOf(s.charAt(i)) << m);
365 m = m + 4;
366 }
367 return r;
368 }
369
370
371 // Returns true if all digits in string s are valid hex numbers 359 // Returns true if all digits in string s are valid hex numbers
372 function IsValidHex(s) { 360 function IsValidHex(s) {
373 for (var i = 0; i < s.length; ++i) { 361 for (var i = 0; i < s.length; ++i) {
374 var cc = s.charCodeAt(i); 362 var cc = s.charCodeAt(i);
375 if ((48 <= cc && cc <= 57) || (65 <= cc && cc <= 70) || (97 <= cc && cc <= 1 02)) { 363 if ((48 <= cc && cc <= 57) || (65 <= cc && cc <= 70) || (97 <= cc && cc <= 1 02)) {
376 // '0'..'9', 'A'..'F' and 'a' .. 'f'. 364 // '0'..'9', 'A'..'F' and 'a' .. 'f'.
377 } else { 365 } else {
378 return false; 366 return false;
379 } 367 }
380 } 368 }
(...skipping 24 matching lines...) Expand all
405 "escape", URIEscape, 393 "escape", URIEscape,
406 "unescape", URIUnescape, 394 "unescape", URIUnescape,
407 "decodeURI", URIDecode, 395 "decodeURI", URIDecode,
408 "decodeURIComponent", URIDecodeComponent, 396 "decodeURIComponent", URIDecodeComponent,
409 "encodeURI", URIEncode, 397 "encodeURI", URIEncode,
410 "encodeURIComponent", URIEncodeComponent 398 "encodeURIComponent", URIEncodeComponent
411 )); 399 ));
412 } 400 }
413 401
414 SetupURI(); 402 SetupURI();
OLDNEW
« no previous file with comments | « src/scanner.cc ('k') | src/v8globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698