Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 class _HttpUtils { | 7 class _HttpUtils { |
| 8 static String decodeUrlEncodedString(String urlEncoded) { | 8 static String decodeUrlEncodedString(String urlEncoded) { |
| 9 // First check the string for any encoding. | 9 // First check the string for any encoding. |
| 10 int index = 0; | 10 int index = 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 } else { | 46 } else { |
| 47 bytes.add(urlEncoded.codeUnitAt(i)); | 47 bytes.add(urlEncoded.codeUnitAt(i)); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 return decodeUtf8(bytes); | 50 return decodeUtf8(bytes); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static Map<String, String> splitQueryString(String queryString) { | 53 static Map<String, String> splitQueryString(String queryString) { |
| 54 Map<String, String> result = new Map<String, String>(); | 54 Map<String, String> result = new Map<String, String>(); |
| 55 int currentPosition = 0; | 55 int currentPosition = 0; |
| 56 while (currentPosition < queryString.length) { | 56 int length = queryString.length; |
| 57 int position = queryString.indexOf("=", currentPosition); | 57 |
| 58 if (position == -1) { | 58 while (currentPosition < length) { |
| 59 break; | 59 |
| 60 // Find the first equals character between current position and | |
| 61 // the provided end. | |
| 62 int indexOfEquals(int end) { | |
| 63 int index = currentPosition; | |
| 64 while (index < end) { | |
| 65 if (queryString.codeUnitAt(index) == _CharCode.EQUAL) return index; | |
| 66 index++; | |
| 67 } | |
| 68 return -1; | |
| 60 } | 69 } |
| 61 String name = queryString.substring(currentPosition, position); | 70 |
| 62 currentPosition = position + 1; | 71 // Find the next separator (either & or ;), see |
| 63 position = queryString.indexOf("&", currentPosition); | 72 // http://www.w3.org/TR/REC-html40/appendix/notes.html#ampersands-in-uris |
| 73 // relating the ; separator. If no separator is found returns | |
| 74 // the length of the quesy string. | |
|
Mads Ager (google)
2013/05/15 09:17:35
query
Søren Gjesse
2013/05/15 09:22:18
Done.
| |
| 75 int indexOfSeparator() { | |
| 76 int end = length; | |
| 77 int index = currentPosition; | |
| 78 while (index < end) { | |
| 79 int codeUnit = queryString.codeUnitAt(index); | |
| 80 if (codeUnit == _CharCode.AMPERSAND || | |
| 81 codeUnit == _CharCode.SEMI_COLON) { | |
| 82 return index; | |
| 83 } | |
| 84 index++; | |
| 85 } | |
| 86 return end; | |
| 87 } | |
| 88 | |
| 89 int seppos = indexOfSeparator(); | |
| 90 int equalspos = indexOfEquals(seppos); | |
| 91 String name; | |
| 64 String value; | 92 String value; |
| 65 if (position == -1) { | 93 if (equalspos == -1) { |
| 66 value = queryString.substring(currentPosition); | 94 name = queryString.substring(currentPosition, seppos); |
| 67 currentPosition = queryString.length; | 95 value = ''; |
| 68 } else { | 96 } else { |
| 69 value = queryString.substring(currentPosition, position); | 97 name = queryString.substring(currentPosition, equalspos); |
| 70 currentPosition = position + 1; | 98 value = queryString.substring(equalspos + 1, seppos); |
| 71 } | 99 } |
| 100 currentPosition = seppos + 1; // This also works when seppos == length. | |
| 101 if (name == '') continue; | |
| 72 result[_HttpUtils.decodeUrlEncodedString(name)] = | 102 result[_HttpUtils.decodeUrlEncodedString(name)] = |
| 73 _HttpUtils.decodeUrlEncodedString(value); | 103 _HttpUtils.decodeUrlEncodedString(value); |
| 74 } | 104 } |
| 75 return result; | 105 return result; |
| 76 } | 106 } |
| 77 | 107 |
| 78 // From RFC 2616 section "3.3.1 Full Date" | 108 // From RFC 2616 section "3.3.1 Full Date" |
| 79 // HTTP-date = rfc1123-date | rfc850-date | asctime-date | 109 // HTTP-date = rfc1123-date | rfc850-date | asctime-date |
| 80 // rfc1123-date = wkday "," SP date1 SP time SP "GMT" | 110 // rfc1123-date = wkday "," SP date1 SP time SP "GMT" |
| 81 // rfc850-date = weekday "," SP date2 SP time SP "GMT" | 111 // rfc850-date = weekday "," SP date2 SP time SP "GMT" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 while ((amp = input.indexOf('&', offset)) >= 0) { | 419 while ((amp = input.indexOf('&', offset)) >= 0) { |
| 390 buffer.write(input.substring(offset, amp)); | 420 buffer.write(input.substring(offset, amp)); |
| 391 int end = input.indexOf(';', amp); | 421 int end = input.indexOf(';', amp); |
| 392 parse(amp, end); | 422 parse(amp, end); |
| 393 offset = end + 1; | 423 offset = end + 1; |
| 394 } | 424 } |
| 395 buffer.write(input.substring(offset)); | 425 buffer.write(input.substring(offset)); |
| 396 return buffer.toString(); | 426 return buffer.toString(); |
| 397 } | 427 } |
| 398 } | 428 } |
| OLD | NEW |