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/encoder.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/percent/decoder.dart ('k') | pubspec.yaml » ('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.encoder; 5 library convert.percent.encoder;
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 10
11 /// The canonical instance of [PercentEncoder]. 11 /// The canonical instance of [PercentEncoder].
12 const percentEncoder = const PercentEncoder._(); 12 const percentEncoder = const PercentEncoder._();
13 13
14 /// A converter that encodes byte arrays into percent-encoded strings. 14 /// A converter that encodes byte arrays into percent-encoded strings.
15 /// 15 ///
16 /// [encoder] encodes all bytes other than ASCII letters, decimal digits, or one 16 /// [encoder] encodes all bytes other than ASCII letters, decimal digits, or one
17 /// of `-._~`. This matches the behavior of [Uri.encodeQueryComponent] except 17 /// of `-._~`. This matches the behavior of [Uri.encodeQueryComponent] except
18 /// that it doesn't encode `0x20` bytes to the `+` character. 18 /// that it doesn't encode `0x20` bytes to the `+` character.
19 /// 19 ///
20 /// This will throw a [RangeError] if the byte array has any digits that don't 20 /// This will throw a [RangeError] if the byte array has any digits that don't
21 /// fit in the gamut of a byte. 21 /// fit in the gamut of a byte.
22 class PercentEncoder 22 class PercentEncoder extends Converter<List<int>, String> {
23 extends ChunkedConverter<List<int>, String, List<int>, String> {
24 const PercentEncoder._(); 23 const PercentEncoder._();
25 24
26 String convert(List<int> bytes) => _convert(bytes, 0, bytes.length); 25 String convert(List<int> bytes) => _convert(bytes, 0, bytes.length);
27 26
28 ByteConversionSink startChunkedConversion(Sink<String> sink) => 27 ByteConversionSink startChunkedConversion(Sink<String> sink) =>
29 new _PercentEncoderSink(sink); 28 new _PercentEncoderSink(sink);
30 } 29 }
31 30
32 /// A conversion sink for chunked percentadecimal encoding. 31 /// A conversion sink for chunked percentadecimal encoding.
33 class _PercentEncoderSink extends ByteConversionSinkBase { 32 class _PercentEncoderSink extends ByteConversionSinkBase {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 "Invalid byte ${byte < 0 ? "-" : ""}0x${byte.abs().toRadixString(16)}.", 95 "Invalid byte ${byte < 0 ? "-" : ""}0x${byte.abs().toRadixString(16)}.",
97 bytes, i); 96 bytes, i);
98 } 97 }
99 98
100 throw 'unreachable'; 99 throw 'unreachable';
101 } 100 }
102 101
103 /// Returns the ASCII/Unicode code unit corresponding to the hexadecimal digit 102 /// Returns the ASCII/Unicode code unit corresponding to the hexadecimal digit
104 /// [digit]. 103 /// [digit].
105 int _codeUnitForDigit(int digit) => digit < 10 ? digit + $0 : digit + $A - 10; 104 int _codeUnitForDigit(int digit) => digit < 10 ? digit + $0 : digit + $A - 10;
OLDNEW
« no previous file with comments | « lib/src/percent/decoder.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698