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

Side by Side Diff: runtime/bin/http_utils.dart

Issue 9581011: Make the HttpParser and HttpUtil classes private (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 | « runtime/bin/http_parser.dart ('k') | runtime/bin/io_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 class _HttpUtils {
6 static String decodeUrlEncodedString(String urlEncoded) {
7 void invalidEscape() {
8 // TODO(sgjesse): Handle the error.
9 }
10
11 StringBuffer result = new StringBuffer();
12 for (int ii = 0; urlEncoded.length > ii; ++ii) {
13 if ('+' == urlEncoded[ii]) {
14 result.add(' ');
15 } else if ('%' == urlEncoded[ii] &&
16 urlEncoded.length - 2 > ii) {
17 try {
18 int charCode =
19 Math.parseInt('0x' + urlEncoded.substring(ii + 1, ii + 3));
20 if (charCode <= 0x7f) {
21 result.add(new String.fromCharCodes([charCode]));
22 ii += 2;
23 } else {
24 invalidEscape();
25 return '';
26 }
27 } catch (BadNumberFormatException ignored) {
28 invalidEscape();
29 return '';
30 }
31 } else {
32 result.add(urlEncoded[ii]);
33 }
34 }
35 return result.toString();
36 }
37
38 static Map<String, String> splitQueryString(String queryString) {
39 Map<String, String> result = new Map<String, String>();
40 int currentPosition = 0;
41 while (currentPosition < queryString.length) {
42 int position = queryString.indexOf("=", currentPosition);
43 if (position == -1) {
44 break;
45 }
46 String name = queryString.substring(currentPosition, position);
47 currentPosition = position + 1;
48 position = queryString.indexOf("&", currentPosition);
49 String value;
50 if (position == -1) {
51 value = queryString.substring(currentPosition);
52 currentPosition = queryString.length;
53 } else {
54 value = queryString.substring(currentPosition, position);
55 currentPosition = position + 1;
56 }
57 result[_HttpUtils.decodeUrlEncodedString(name)] =
58 _HttpUtils.decodeUrlEncodedString(value);
59 }
60 return result;
61 }
62 }
OLDNEW
« no previous file with comments | « runtime/bin/http_parser.dart ('k') | runtime/bin/io_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698