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

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

Issue 1964953003: Make dart:convert strong mode clean. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove unnecessary dynamics. Created 4 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Encoder 63 // Encoder
64 // ------------------------------------------------------------------------ 64 // ------------------------------------------------------------------------
65 65
66 /** 66 /**
67 * Base64 and base64url encoding converter. 67 * Base64 and base64url encoding converter.
68 * 68 *
69 * Encodes lists of bytes using base64 or base64url encoding. 69 * Encodes lists of bytes using base64 or base64url encoding.
70 * 70 *
71 * The results are ASCII strings using a restricted alphabet. 71 * The results are ASCII strings using a restricted alphabet.
72 */ 72 */
73 class Base64Encoder extends 73 class Base64Encoder extends Converter<List<int>, String> {
74 ChunkedConverter<List<int>, String, List<int>, String> {
75 final bool _urlSafe; 74 final bool _urlSafe;
76 75
77 const Base64Encoder() : _urlSafe = false; 76 const Base64Encoder() : _urlSafe = false;
78 const Base64Encoder.urlSafe() : _urlSafe = true; 77 const Base64Encoder.urlSafe() : _urlSafe = true;
79 78
80 String convert(List<int> input) { 79 String convert(List<int> input) {
81 if (input.isEmpty) return ""; 80 if (input.isEmpty) return "";
82 var encoder = new _Base64Encoder(_urlSafe); 81 var encoder = new _Base64Encoder(_urlSafe);
83 Uint8List buffer = encoder.encode(input, 0, input.length, true); 82 Uint8List buffer = encoder.encode(input, 0, input.length, true);
84 return new String.fromCharCodes(buffer); 83 return new String.fromCharCodes(buffer);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // Decoder 333 // Decoder
335 // ------------------------------------------------------------------------ 334 // ------------------------------------------------------------------------
336 335
337 /** 336 /**
338 * Decoder for base64 encoded data. 337 * Decoder for base64 encoded data.
339 * 338 *
340 * This decoder accepts both base64 and base64url ("url-safe") encodings. 339 * This decoder accepts both base64 and base64url ("url-safe") encodings.
341 * 340 *
342 * The encoding is required to be properly padded. 341 * The encoding is required to be properly padded.
343 */ 342 */
344 class Base64Decoder extends 343 class Base64Decoder extends Converter<String, List<int>> {
345 ChunkedConverter<String, List<int>, String, List<int>> {
346 344
347 const Base64Decoder(); 345 const Base64Decoder();
348 346
349 List<int> convert(String input, [int start = 0, int end]) { 347 List<int> convert(String input, [int start = 0, int end]) {
350 end = RangeError.checkValidRange(start, end, input.length); 348 end = RangeError.checkValidRange(start, end, input.length);
351 if (start == end) return new Uint8List(0); 349 if (start == end) return new Uint8List(0);
352 var decoder = new _Base64Decoder(); 350 var decoder = new _Base64Decoder();
353 Uint8List buffer = decoder.decode(input, start, end); 351 Uint8List buffer = decoder.decode(input, start, end);
354 decoder.close(input, end); 352 decoder.close(input, end);
355 return buffer; 353 return buffer;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 end = RangeError.checkValidRange(start, end, string.length); 741 end = RangeError.checkValidRange(start, end, string.length);
744 if (start == end) return; 742 if (start == end) return;
745 Uint8List buffer = _decoder.decode(string, start, end); 743 Uint8List buffer = _decoder.decode(string, start, end);
746 if (buffer != null) _sink.add(buffer); 744 if (buffer != null) _sink.add(buffer);
747 if (isLast) { 745 if (isLast) {
748 _decoder.close(string, end); 746 _decoder.close(string, end);
749 _sink.close(); 747 _sink.close();
750 } 748 }
751 } 749 }
752 } 750 }
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