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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 class _HttpUtils { | 7 class _HttpUtils { |
8 static String decodeUrlEncodedString(String urlEncoded) { | 8 static String decodeUrlEncodedString(String urlEncoded) { |
9 // First check the string for any encoding. | 9 // First check the string for any encoding. |
10 int index = 0; | 10 int index = 0; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 if (timeList.length != 3) error(); | 351 if (timeList.length != 3) error(); |
352 int hour = toInt(timeList[0]); | 352 int hour = toInt(timeList[0]); |
353 int minute = toInt(timeList[1]); | 353 int minute = toInt(timeList[1]); |
354 int second = toInt(timeList[2]); | 354 int second = toInt(timeList[2]); |
355 if (hour > 23) error(); | 355 if (hour > 23) error(); |
356 if (minute > 59) error(); | 356 if (minute > 59) error(); |
357 if (second > 59) error(); | 357 if (second > 59) error(); |
358 | 358 |
359 return new DateTime.utc(year, month, dayOfMonth, hour, minute, second, 0); | 359 return new DateTime.utc(year, month, dayOfMonth, hour, minute, second, 0); |
360 } | 360 } |
| 361 |
| 362 // Parse a string with HTTP entities. Returns null if the string ends in the |
| 363 // middle of a http entity. |
| 364 static String parseHttpEntityString(String input) { |
| 365 int amp = input.lastIndexOf('&'); |
| 366 if (amp < 0) return input; |
| 367 int end = input.lastIndexOf(';'); |
| 368 if (end < amp) return null; |
| 369 |
| 370 var buffer = new StringBuffer(); |
| 371 int offset = 0; |
| 372 |
| 373 parse(amp, end) { |
| 374 switch (input[amp + 1]) { |
| 375 case '#': |
| 376 if (input[amp + 2] == 'x') { |
| 377 buffer.writeCharCode( |
| 378 int.parse(input.substring(amp + 3, end), radix: 16)); |
| 379 } else { |
| 380 buffer.writeCharCode(int.parse(input.substring(amp + 2, end))); |
| 381 } |
| 382 break; |
| 383 |
| 384 default: |
| 385 throw new HttpException('Unhandled HTTP entity token'); |
| 386 } |
| 387 } |
| 388 |
| 389 while ((amp = input.indexOf('&', offset)) >= 0) { |
| 390 buffer.write(input.substring(offset, amp)); |
| 391 int end = input.indexOf(';', amp); |
| 392 parse(amp, end); |
| 393 offset = end + 1; |
| 394 } |
| 395 buffer.write(input.substring(offset)); |
| 396 return buffer.toString(); |
| 397 } |
361 } | 398 } |
OLD | NEW |