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

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

Issue 10914093: Cleanup in http_utils.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | « no previous file | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 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 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 class _HttpUtils { 5 class _HttpUtils {
6 static String decodeUrlEncodedString(String urlEncoded) { 6 static String decodeUrlEncodedString(String urlEncoded) {
7 // First check the string for any encoding. 7 // First check the string for any encoding.
8 int index = 0; 8 int index = 0;
9 bool encoded = false; 9 bool encoded = false;
10 while (!encoded && index < urlEncoded.length) { 10 while (!encoded && index < urlEncoded.length) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // wkday = "Mon" | "Tue" | "Wed" 87 // wkday = "Mon" | "Tue" | "Wed"
88 // | "Thu" | "Fri" | "Sat" | "Sun" 88 // | "Thu" | "Fri" | "Sat" | "Sun"
89 // weekday = "Monday" | "Tuesday" | "Wednesday" 89 // weekday = "Monday" | "Tuesday" | "Wednesday"
90 // | "Thursday" | "Friday" | "Saturday" | "Sunday" 90 // | "Thursday" | "Friday" | "Saturday" | "Sunday"
91 // month = "Jan" | "Feb" | "Mar" | "Apr" 91 // month = "Jan" | "Feb" | "Mar" | "Apr"
92 // | "May" | "Jun" | "Jul" | "Aug" 92 // | "May" | "Jun" | "Jul" | "Aug"
93 // | "Sep" | "Oct" | "Nov" | "Dec" 93 // | "Sep" | "Oct" | "Nov" | "Dec"
94 94
95 // Format as RFC 1123 date. 95 // Format as RFC 1123 date.
96 static String formatDate(Date date) { 96 static String formatDate(Date date) {
97 List wkday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; 97 List wkday = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
Mads Ager (google) 2012/09/05 08:52:51 Mark the wkday as const as well? const List wkday
Anders Johnsen 2012/09/05 09:09:46 Got'ya, done.
98 List month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", 98 List month = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
99 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; 99 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
100 100
101 Date d = date.toUtc(); 101 Date d = date.toUtc();
102 StringBuffer sb = new StringBuffer(); 102 StringBuffer sb = new StringBuffer();
103 sb.add(wkday[d.weekday - 1]); 103 sb.add(wkday[d.weekday - 1]);
104 sb.add(", "); 104 sb.add(", ");
105 sb.add(d.day.toString()); 105 sb.add(d.day.toString());
106 sb.add(" "); 106 sb.add(" ");
107 sb.add(month[d.month - 1]); 107 sb.add(month[d.month - 1]);
108 sb.add(" "); 108 sb.add(" ");
109 sb.add(d.year.toString()); 109 sb.add(d.year.toString());
110 d.hour < 9 ? sb.add(" 0") : sb.add(" "); 110 d.hour < 9 ? sb.add(" 0") : sb.add(" ");
111 sb.add(d.hour.toString()); 111 sb.add(d.hour.toString());
112 d.minute < 9 ? sb.add(":0") : sb.add(":"); 112 d.minute < 9 ? sb.add(":0") : sb.add(":");
113 sb.add(d.minute.toString()); 113 sb.add(d.minute.toString());
114 d.second < 9 ? sb.add(":0") : sb.add(":"); 114 d.second < 9 ? sb.add(":0") : sb.add(":");
115 sb.add(d.second.toString()); 115 sb.add(d.second.toString());
116 sb.add(" GMT"); 116 sb.add(" GMT");
117 return sb.toString(); 117 return sb.toString();
118 } 118 }
119 119
120 static Date parseDate(String date) { 120 static Date parseDate(String date) {
121 final int SP = 32; 121 final int SP = 32;
122 List wkdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; 122 List wkdays = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
123 List weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", 123 List weekdays = const ["Monday", "Tuesday", "Wednesday", "Thursday",
124 "Friday", "Saturday", "Sunday"]; 124 "Friday", "Saturday", "Sunday"];
125 List months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", 125 List months = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
126 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; 126 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
127 List wkdaysLowerCase = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]; 127 List wkdaysLowerCase =
128 List weekdaysLowerCase = ["monday", "tuesday", "wednesday", "thursday", 128 const ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
129 "friday", "saturday", "sunday"]; 129 List weekdaysLowerCase = const ["monday", "tuesday", "wednesday",
130 List monthsLowerCase = ["jan", "feb", "mar", "apr", "may", "jun", 130 "thursday", "friday", "saturday", "sunday"];
131 "jul", "aug", "sep", "oct", "nov", "dec"]; 131 List monthsLowerCase = const ["jan", "feb", "mar", "apr", "may", "jun",
132 "jul", "aug", "sep", "oct", "nov", "dec"];
132 133
133 final int formatRfc1123 = 0; 134 final int formatRfc1123 = 0;
134 final int formatRfc850 = 1; 135 final int formatRfc850 = 1;
135 final int formatAsctime = 2; 136 final int formatAsctime = 2;
136 137
137 int index = 0; 138 int index = 0;
138 String tmp; 139 String tmp;
139 int format; 140 int format;
140 141
141 void expect(String s) { 142 void expect(String s) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 minutes = expectNum(":"); 238 minutes = expectNum(":");
238 seconds = expectNum(" "); 239 seconds = expectNum(" ");
239 expect("GMT"); 240 expect("GMT");
240 } 241 }
241 expectEnd(); 242 expectEnd();
242 return new Date( 243 return new Date(
243 year, month + 1, day, hours, minutes, seconds, 0, isUtc: true); 244 year, month + 1, day, hours, minutes, seconds, 0, isUtc: true);
244 } 245 }
245 246
246 static Date parseCookieDate(String date) { 247 static Date parseCookieDate(String date) {
247 List monthsLowerCase = ["jan", "feb", "mar", "apr", "may", "jun", 248 List monthsLowerCase = const ["jan", "feb", "mar", "apr", "may", "jun",
248 "jul", "aug", "sep", "oct", "nov", "dec"]; 249 "jul", "aug", "sep", "oct", "nov", "dec"];
249 250
250 int position = 0; 251 int position = 0;
251 252
252 void error() { 253 void error() {
253 throw new HttpException("Invalid cookie date $date"); 254 throw new HttpException("Invalid cookie date $date");
254 } 255 }
255 256
256 bool isEnd() { 257 bool isEnd() {
257 return position == date.length; 258 return position == date.length;
258 } 259 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 dayOfMonthStr = token; 320 dayOfMonthStr = token;
320 } else if (monthStr === null && getMonth(token) >= 0) { 321 } else if (monthStr === null && getMonth(token) >= 0) {
321 monthStr = token; 322 monthStr = token;
322 } else if (yearStr === null && token.length >= 2 && 323 } else if (yearStr === null && token.length >= 2 &&
323 isDigit(token[0]) && isDigit(token[1])) { 324 isDigit(token[0]) && isDigit(token[1])) {
324 yearStr = token; 325 yearStr = token;
325 } 326 }
326 } 327 }
327 328
328 if (timeStr === null || dayOfMonthStr === null || 329 if (timeStr === null || dayOfMonthStr === null ||
329 monthStr === null || yearStr === null) error(); 330 monthStr === null || yearStr === null) {
331 error();
332 }
330 333
331 int year = toInt(yearStr); 334 int year = toInt(yearStr);
332 if (year >= 70 && year <= 99) year += 1900; 335 if (year >= 70 && year <= 99) year += 1900;
333 else if (year >= 0 && year <= 69) year += 2000; 336 else if (year >= 0 && year <= 69) year += 2000;
334 if (year < 1601) error(); 337 if (year < 1601) error();
335 338
336 int dayOfMonth = toInt(dayOfMonthStr); 339 int dayOfMonth = toInt(dayOfMonthStr);
337 if (dayOfMonth < 1 || dayOfMonth > 31) error(); 340 if (dayOfMonth < 1 || dayOfMonth > 31) error();
338 341
339 int month = getMonth(monthStr) + 1; 342 int month = getMonth(monthStr) + 1;
340 343
341 var timeList = timeStr.split(":"); 344 var timeList = timeStr.split(":");
342 if (timeList.length !== 3) error(); 345 if (timeList.length !== 3) error();
343 int hour = toInt(timeList[0]); 346 int hour = toInt(timeList[0]);
344 int minute = toInt(timeList[1]); 347 int minute = toInt(timeList[1]);
345 int second = toInt(timeList[2]); 348 int second = toInt(timeList[2]);
346 if (hour > 23) error(); 349 if (hour > 23) error();
347 if (minute > 59) error(); 350 if (minute > 59) error();
348 if (second > 59) error(); 351 if (second > 59) error();
349 352
350 return new Date(year, month, dayOfMonth, hour, minute, second, 0, true); 353 return new Date(year, month, dayOfMonth, hour, minute, second, 0, true);
351 } 354 }
352 } 355 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698