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

Side by Side Diff: lib/src/percent/decoder.dart

Issue 2031873006: Stop implementing ChunkedConverter. (Closed) Base URL: git@github.com:dart-lang/convert.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « lib/src/hex/encoder.dart ('k') | lib/src/percent/encoder.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 convert.percent.decoder; 5 library convert.percent.decoder;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:charcode/ascii.dart'; 9 import 'package:charcode/ascii.dart';
10 import 'package:typed_data/typed_data.dart'; 10 import 'package:typed_data/typed_data.dart';
11 11
12 import '../utils.dart'; 12 import '../utils.dart';
13 13
14 /// The canonical instance of [PercentDecoder]. 14 /// The canonical instance of [PercentDecoder].
15 const percentDecoder = const PercentDecoder._(); 15 const percentDecoder = const PercentDecoder._();
16 16
17 const _lastPercent = -1; 17 const _lastPercent = -1;
18 18
19 /// A converter that decodes percent-encoded strings into byte arrays. 19 /// A converter that decodes percent-encoded strings into byte arrays.
20 /// 20 ///
21 /// To be maximally flexible, this will decode any percent-encoded byte and 21 /// To be maximally flexible, this will decode any percent-encoded byte and
22 /// will allow any non-percent-encoded byte other than `%`. By default, it 22 /// will allow any non-percent-encoded byte other than `%`. By default, it
23 /// interprets `+` as `0x2B` rather than `0x20` as emitted by 23 /// interprets `+` as `0x2B` rather than `0x20` as emitted by
24 /// [Uri.encodeQueryComponent]. 24 /// [Uri.encodeQueryComponent].
25 /// 25 ///
26 /// This will throw a [FormatException] if the input string has an incomplete 26 /// This will throw a [FormatException] if the input string has an incomplete
27 /// percent-encoding, or if it contains non-ASCII code units. 27 /// percent-encoding, or if it contains non-ASCII code units.
28 class PercentDecoder 28 class PercentDecoder extends Converter<String, List<int>> {
29 extends ChunkedConverter<String, List<int>, String, List<int>> {
30 const PercentDecoder._(); 29 const PercentDecoder._();
31 30
32 List<int> convert(String string) { 31 List<int> convert(String string) {
33 var buffer = new Uint8Buffer(); 32 var buffer = new Uint8Buffer();
34 var lastDigit = _decode(string.codeUnits, 0, string.length, buffer); 33 var lastDigit = _decode(string.codeUnits, 0, string.length, buffer);
35 34
36 if (lastDigit != null) { 35 if (lastDigit != null) {
37 throw new FormatException( 36 throw new FormatException(
38 "Input ended with incomplete encoded byte.", 37 "Input ended with incomplete encoded byte.",
39 string, string.length); 38 string, string.length);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 235
237 for (var i = start; i < end; i++) { 236 for (var i = start; i < end; i++) {
238 var codeUnit = codeUnits[i]; 237 var codeUnit = codeUnits[i];
239 if (codeUnit >= 0 && codeUnit <= 0x7f) continue; 238 if (codeUnit >= 0 && codeUnit <= 0x7f) continue;
240 throw new FormatException( 239 throw new FormatException(
241 "Non-ASCII code unit " 240 "Non-ASCII code unit "
242 "U+${codeUnit.toRadixString(16).padLeft(4, '0')}", 241 "U+${codeUnit.toRadixString(16).padLeft(4, '0')}",
243 codeUnits, i); 242 codeUnits, i);
244 } 243 }
245 } 244 }
OLDNEW
« no previous file with comments | « lib/src/hex/encoder.dart ('k') | lib/src/percent/encoder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698