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

Unified Diff: pkg/shelf/lib/src/string_scanner.dart

Issue 222843003: Convert shelf to use the string_scanner package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/shelf/lib/src/media_type.dart ('k') | pkg/shelf/lib/src/util.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/shelf/lib/src/string_scanner.dart
diff --git a/pkg/shelf/lib/src/string_scanner.dart b/pkg/shelf/lib/src/string_scanner.dart
deleted file mode 100644
index 834c2d433c53a7289510caa9647b5f068e2827c6..0000000000000000000000000000000000000000
--- a/pkg/shelf/lib/src/string_scanner.dart
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright (c) 2014, 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.
-
-library shelf.string_scanner;
-
-/// A class that scans through a string using [Pattern]s.
-class StringScanner {
- /// The string being scanned through.
- final String string;
-
- /// The current position of the scanner in the string, in characters.
- int get position => _position;
- set position(int position) {
- if (position < 0 || position > string.length) {
- throw new ArgumentError("Invalid position $position");
- }
-
- _position = position;
- }
- int _position = 0;
-
- /// The data about the previous match made by the scanner.
- ///
- /// If the last match failed, this will be `null`.
- Match get lastMatch => _lastMatch;
- Match _lastMatch;
-
- /// The portion of the string that hasn't yet been scanned.
- String get rest => string.substring(position);
-
- /// Whether the scanner has completely consumed [string].
- bool get isDone => position == string.length;
-
- /// Creates a new [StringScanner] that starts scanning from [position].
- ///
- /// [position] defaults to 0, the beginning of the string.
- StringScanner(this.string, {int position}) {
- if (position != null) this.position = position;
- }
-
- /// If [pattern] matches at the current position of the string, scans forward
- /// until the end of the match.
- ///
- /// Returns whether or not [pattern] matched.
- bool scan(Pattern pattern) {
- var success = matches(pattern);
- if (success) _position = _lastMatch.end;
- return success;
- }
-
- /// If [pattern] matches at the current position of the string, scans forward
- /// until the end of the match.
- ///
- /// If [pattern] did not match, throws a [FormatException] with [message].
- void expect(Pattern pattern, String message) {
- if (scan(pattern)) return;
- throw new FormatException(message);
- }
-
- /// Returns whether or not [pattern] matches at the current position of the
- /// string.
- ///
- /// This doesn't move the scan pointer forward.
- bool matches(Pattern pattern) {
- _lastMatch = pattern.matchAsPrefix(string, position);
- return _lastMatch != null;
- }
-}
« no previous file with comments | « pkg/shelf/lib/src/media_type.dart ('k') | pkg/shelf/lib/src/util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698