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

Side by Side Diff: pkg/http_parser/lib/http_parser.dart

Issue 223023003: Extract an http_parser package from shelf. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 8 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 | « pkg/http_parser/README.md ('k') | pkg/http_parser/lib/src/media_type.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library shelf.util; 5 library http_parser;
6 6
7 import 'dart:async';
8
9 import 'package:stack_trace/stack_trace.dart';
10 import 'package:string_scanner/string_scanner.dart'; 7 import 'package:string_scanner/string_scanner.dart';
11 8
12 /// Like [Future.sync], but wraps the Future in [Chain.track] as well. 9 export 'src/media_type.dart';
13 Future syncFuture(callback()) => Chain.track(new Future.sync(callback));
14 10
15 const _WEEKDAYS = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; 11 const _WEEKDAYS = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
16 const _MONTHS = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", 12 const _MONTHS = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
17 "Sep", "Oct", "Nov", "Dec"]; 13 "Sep", "Oct", "Nov", "Dec"];
18 14
19 final _shortWeekdayRegExp = new RegExp(r"Mon|Tue|Wed|Thu|Fri|Sat|Sun"); 15 final _shortWeekdayRegExp = new RegExp(r"Mon|Tue|Wed|Thu|Fri|Sat|Sun");
20 final _longWeekdayRegExp = 16 final _longWeekdayRegExp =
21 new RegExp(r"Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday"); 17 new RegExp(r"Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday");
22 final _monthRegExp = 18 final _monthRegExp =
23 new RegExp(r"Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec"); 19 new RegExp(r"Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec");
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 scanner.expect(_monthRegExp); 111 scanner.expect(_monthRegExp);
116 // DateTime uses 1-indexed months. 112 // DateTime uses 1-indexed months.
117 return _MONTHS.indexOf(scanner.lastMatch[0]) + 1; 113 return _MONTHS.indexOf(scanner.lastMatch[0]) + 1;
118 } 114 }
119 115
120 /// Parses an int an enforces that it has exactly [digits] digits. 116 /// Parses an int an enforces that it has exactly [digits] digits.
121 int _parseInt(StringScanner scanner, int digits) { 117 int _parseInt(StringScanner scanner, int digits) {
122 scanner.expect(_digitRegExp); 118 scanner.expect(_digitRegExp);
123 if (scanner.lastMatch[0].length != digits) { 119 if (scanner.lastMatch[0].length != digits) {
124 scanner.error("expected a $digits-digit number."); 120 scanner.error("expected a $digits-digit number.");
125 } else {
126 return int.parse(scanner.lastMatch[0]);
127 } 121 }
122
123 return int.parse(scanner.lastMatch[0]);
128 } 124 }
129 125
130 /// Parses an timestamp of the form "HH:MM:SS" on a 24-hour clock. 126 /// Parses an timestamp of the form "HH:MM:SS" on a 24-hour clock.
131 DateTime _parseTime(StringScanner scanner) { 127 DateTime _parseTime(StringScanner scanner) {
132 var hours = _parseInt(scanner, 2); 128 var hours = _parseInt(scanner, 2);
133 if (hours >= 24) scanner.error("hours may not be greater than 24."); 129 if (hours >= 24) scanner.error("hours may not be greater than 24.");
134 scanner.expect(':'); 130 scanner.expect(':');
135 131
136 var minutes = _parseInt(scanner, 2); 132 var minutes = _parseInt(scanner, 2);
137 if (minutes >= 60) scanner.error("minutes may not be greater than 60."); 133 if (minutes >= 60) scanner.error("minutes may not be greater than 60.");
(...skipping 12 matching lines...) Expand all
150 DateTime _makeDateTime(int year, int month, int day, DateTime time) { 146 DateTime _makeDateTime(int year, int month, int day, DateTime time) {
151 var dateTime = new DateTime.utc( 147 var dateTime = new DateTime.utc(
152 year, month, day, time.hour, time.minute, time.second); 148 year, month, day, time.hour, time.minute, time.second);
153 149
154 // If [day] was too large, it will cause [month] to overflow. 150 // If [day] was too large, it will cause [month] to overflow.
155 if (dateTime.month != month) { 151 if (dateTime.month != month) {
156 throw new FormatException("invalid day '$day' for month '$month'."); 152 throw new FormatException("invalid day '$day' for month '$month'.");
157 } 153 }
158 return dateTime; 154 return dateTime;
159 } 155 }
OLDNEW
« no previous file with comments | « pkg/http_parser/README.md ('k') | pkg/http_parser/lib/src/media_type.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698