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

Unified Diff: lib/src/scan.dart

Issue 1307353003: Add an AuthenticationChallenge class. (Closed) Base URL: git@github.com:dart-lang/http_parser@master
Patch Set: Code review changes Created 5 years, 4 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 | « lib/src/media_type.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/scan.dart
diff --git a/lib/src/scan.dart b/lib/src/scan.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d675b8b41c9e033c3aafdb339e31a59ac8d17832
--- /dev/null
+++ b/lib/src/scan.dart
@@ -0,0 +1,77 @@
+// Copyright (c) 2015, 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.
+
+/// A library for broadly-useful functions and regular expressions for scanning
+/// HTTP entities.
+///
+/// Many of the regular expressions come from [section 2.2 of the HTTP
+/// spec][spec].
+///
+/// [spec]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html
+library http_parser.scan;
+
+import 'package:string_scanner/string_scanner.dart';
+
+/// An HTTP token.
+final token = new RegExp(r'[^()<>@,;:"\\/[\]?={} \t\x00-\x1F\x7F]+');
+
+/// Linear whitespace.
+final _lws = new RegExp(r"(?:\r\n)?[ \t]+");
+
+/// A quoted string.
+final _quotedString = new RegExp(r'"(?:[^"\x00-\x1F\x7F]|\\.)*"');
+
+/// A quoted pair.
+final _quotedPair = new RegExp(r'\\(.)');
+
+/// A character that is *not* a valid HTTP token.
+final nonToken = new RegExp(r'[()<>@,;:"\\/\[\]?={} \t\x00-\x1F\x7F]');
+
+/// A regular expression matching any number of [_lws] productions in a row.
+final whitespace = new RegExp("(?:${_lws.pattern})*");
+
+/// Parses a list of elements, as in `1#element` in the HTTP spec.
+///
+/// [scanner] is used to parse the elements, and [parseElement] is used to parse
+/// each one individually. The values returned by [parseElement] are collected
+/// in a list and returned.
+///
+/// Once this is finished, [scanner] will be at the next non-LWS character in
+/// the string, or the end of the string.
+List parseList(StringScanner scanner, parseElement()) {
+ var result = [];
+
+ // Consume initial empty values.
+ while (scanner.scan(",")) {
+ scanner.scan(whitespace);
+ }
+
+ result.add(parseElement());
+ scanner.scan(whitespace);
+
+ while (scanner.scan(",")) {
+ scanner.scan(whitespace);
+
+ // Empty elements are allowed, but excluded from the results.
+ if (scanner.matches(",") || scanner.isDone) continue;
+
+ result.add(parseElement());
+ scanner.scan(whitespace);
+ }
+
+ return result;
+}
+
+/// Parses a single quoted string, and returns its contents.
+///
+/// If [name] is passed, it's used to describe the expected value if it's not
+/// found.
+String expectQuotedString(StringScanner scanner, {String name}) {
+ if (name == null) name = "quoted string";
+ scanner.expect(_quotedString, name: name);
+ var string = scanner.lastMatch[0];
+ return string
+ .substring(1, string.length - 1)
+ .replaceAllMapped(_quotedPair, (match) => match[1]);
+}
« no previous file with comments | « lib/src/media_type.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698