OLD | NEW |
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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 int expectNum(String separator) { | 203 int expectNum(String separator) { |
204 int pos; | 204 int pos; |
205 if (separator.length > 0) { | 205 if (separator.length > 0) { |
206 pos = date.indexOf(separator, index); | 206 pos = date.indexOf(separator, index); |
207 } else { | 207 } else { |
208 pos = date.length; | 208 pos = date.length; |
209 } | 209 } |
210 String tmp = date.substring(index, pos); | 210 String tmp = date.substring(index, pos); |
211 index = pos + separator.length; | 211 index = pos + separator.length; |
212 try { | 212 try { |
213 int value = Math.parseInt(tmp); | 213 int value = parseInt(tmp); |
214 return value; | 214 return value; |
215 } catch (FormatException e) { | 215 } catch (FormatException e) { |
216 throw new HttpException("Invalid HTTP date $date"); | 216 throw new HttpException("Invalid HTTP date $date"); |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 void expectEnd() { | 220 void expectEnd() { |
221 if (index != date.length) { | 221 if (index != date.length) { |
222 throw new HttpException("Invalid HTTP date $date"); | 222 throw new HttpException("Invalid HTTP date $date"); |
223 } | 223 } |
(...skipping 22 matching lines...) Expand all Loading... |
246 hours = expectNum(":"); | 246 hours = expectNum(":"); |
247 minutes = expectNum(":"); | 247 minutes = expectNum(":"); |
248 seconds = expectNum(" "); | 248 seconds = expectNum(" "); |
249 expect("GMT"); | 249 expect("GMT"); |
250 } | 250 } |
251 expectEnd(); | 251 expectEnd(); |
252 return new Date( | 252 return new Date( |
253 year, month + 1, day, hours, minutes, seconds, 0, isUtc: true); | 253 year, month + 1, day, hours, minutes, seconds, 0, isUtc: true); |
254 } | 254 } |
255 } | 255 } |
OLD | NEW |