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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/http_parser.dart ('k') | runtime/bin/io_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/http_utils.dart
diff --git a/runtime/bin/http_utils.dart b/runtime/bin/http_utils.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1e5d84c0d12e176d24731f9da713456c0f829563
--- /dev/null
+++ b/runtime/bin/http_utils.dart
@@ -0,0 +1,62 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class _HttpUtils {
+ static String decodeUrlEncodedString(String urlEncoded) {
+ void invalidEscape() {
+ // TODO(sgjesse): Handle the error.
+ }
+
+ StringBuffer result = new StringBuffer();
+ for (int ii = 0; urlEncoded.length > ii; ++ii) {
+ if ('+' == urlEncoded[ii]) {
+ result.add(' ');
+ } else if ('%' == urlEncoded[ii] &&
+ urlEncoded.length - 2 > ii) {
+ try {
+ int charCode =
+ Math.parseInt('0x' + urlEncoded.substring(ii + 1, ii + 3));
+ if (charCode <= 0x7f) {
+ result.add(new String.fromCharCodes([charCode]));
+ ii += 2;
+ } else {
+ invalidEscape();
+ return '';
+ }
+ } catch (BadNumberFormatException ignored) {
+ invalidEscape();
+ return '';
+ }
+ } else {
+ result.add(urlEncoded[ii]);
+ }
+ }
+ return result.toString();
+ }
+
+ static Map<String, String> splitQueryString(String queryString) {
+ Map<String, String> result = new Map<String, String>();
+ int currentPosition = 0;
+ while (currentPosition < queryString.length) {
+ int position = queryString.indexOf("=", currentPosition);
+ if (position == -1) {
+ break;
+ }
+ String name = queryString.substring(currentPosition, position);
+ currentPosition = position + 1;
+ position = queryString.indexOf("&", currentPosition);
+ String value;
+ if (position == -1) {
+ value = queryString.substring(currentPosition);
+ currentPosition = queryString.length;
+ } else {
+ value = queryString.substring(currentPosition, position);
+ currentPosition = position + 1;
+ }
+ result[_HttpUtils.decodeUrlEncodedString(name)] =
+ _HttpUtils.decodeUrlEncodedString(value);
+ }
+ return result;
+ }
+}
« 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