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

Side by Side Diff: sdk/lib/convert/base64.dart

Issue 2764943002: Fix some strong mode issues in the core libraries. (Closed)
Patch Set: Rebase Created 3 years, 7 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 | « sdk/lib/convert/ascii.dart ('k') | sdk/lib/convert/chunked_conversion.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 part of dart.convert; 5 part of dart.convert;
6 6
7 /** 7 /**
8 * A [base64](https://tools.ietf.org/html/rfc4648) encoder and decoder. 8 * A [base64](https://tools.ietf.org/html/rfc4648) encoder and decoder.
9 * 9 *
10 * It encodes using the default base64 alphabet, 10 * It encodes using the default base64 alphabet,
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // Encoder 198 // Encoder
199 // ------------------------------------------------------------------------ 199 // ------------------------------------------------------------------------
200 200
201 /** 201 /**
202 * Base64 and base64url encoding converter. 202 * Base64 and base64url encoding converter.
203 * 203 *
204 * Encodes lists of bytes using base64 or base64url encoding. 204 * Encodes lists of bytes using base64 or base64url encoding.
205 * 205 *
206 * The results are ASCII strings using a restricted alphabet. 206 * The results are ASCII strings using a restricted alphabet.
207 */ 207 */
208 class Base64Encoder extends Converter<List<int>, String> 208 class Base64Encoder extends Converter<List<int>, String> {
209 implements ChunkedConverter<List<int>, String, List<int>, String> {
210 final bool _urlSafe; 209 final bool _urlSafe;
211 210
212 const Base64Encoder() : _urlSafe = false; 211 const Base64Encoder() : _urlSafe = false;
213 const Base64Encoder.urlSafe() : _urlSafe = true; 212 const Base64Encoder.urlSafe() : _urlSafe = true;
214 213
215 String convert(List<int> input) { 214 String convert(List<int> input) {
216 if (input.isEmpty) return ""; 215 if (input.isEmpty) return "";
217 var encoder = new _Base64Encoder(_urlSafe); 216 var encoder = new _Base64Encoder(_urlSafe);
218 Uint8List buffer = encoder.encode(input, 0, input.length, true); 217 Uint8List buffer = encoder.encode(input, 0, input.length, true);
219 return new String.fromCharCodes(buffer); 218 return new String.fromCharCodes(buffer);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // Decoder 457 // Decoder
459 // ------------------------------------------------------------------------ 458 // ------------------------------------------------------------------------
460 459
461 /** 460 /**
462 * Decoder for base64 encoded data. 461 * Decoder for base64 encoded data.
463 * 462 *
464 * This decoder accepts both base64 and base64url ("url-safe") encodings. 463 * This decoder accepts both base64 and base64url ("url-safe") encodings.
465 * 464 *
466 * The encoding is required to be properly padded. 465 * The encoding is required to be properly padded.
467 */ 466 */
468 class Base64Decoder extends Converter<String, List<int>> 467 class Base64Decoder extends Converter<String, List<int>> {
469 implements ChunkedConverter<String, List<int>, String, List<int>> {
470 const Base64Decoder(); 468 const Base64Decoder();
471 469
472 List<int> convert(String input, [int start = 0, int end]) { 470 List<int> convert(String input, [int start = 0, int end]) {
473 end = RangeError.checkValidRange(start, end, input.length); 471 end = RangeError.checkValidRange(start, end, input.length);
474 if (start == end) return new Uint8List(0); 472 if (start == end) return new Uint8List(0);
475 var decoder = new _Base64Decoder(); 473 var decoder = new _Base64Decoder();
476 Uint8List buffer = decoder.decode(input, start, end); 474 Uint8List buffer = decoder.decode(input, start, end);
477 decoder.close(input, end); 475 decoder.close(input, end);
478 return buffer; 476 return buffer;
479 } 477 }
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 end = RangeError.checkValidRange(start, end, string.length); 862 end = RangeError.checkValidRange(start, end, string.length);
865 if (start == end) return; 863 if (start == end) return;
866 Uint8List buffer = _decoder.decode(string, start, end); 864 Uint8List buffer = _decoder.decode(string, start, end);
867 if (buffer != null) _sink.add(buffer); 865 if (buffer != null) _sink.add(buffer);
868 if (isLast) { 866 if (isLast) {
869 _decoder.close(string, end); 867 _decoder.close(string, end);
870 _sink.close(); 868 _sink.close();
871 } 869 }
872 } 870 }
873 } 871 }
OLDNEW
« no previous file with comments | « sdk/lib/convert/ascii.dart ('k') | sdk/lib/convert/chunked_conversion.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698