OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library convert.percent; |
| 6 |
| 7 import 'dart:convert'; |
| 8 |
| 9 import 'percent/encoder.dart'; |
| 10 import 'percent/decoder.dart'; |
| 11 |
| 12 export 'percent/encoder.dart' hide percentEncoder; |
| 13 export 'percent/decoder.dart' hide percentDecoder; |
| 14 |
| 15 /// The canonical instance of [PercentCodec]. |
| 16 const percent = const PercentCodec._(); |
| 17 |
| 18 // TODO(nweiz): Add flags to support generating and interpreting "+" as a space |
| 19 // character. Also add an option for custom sets of unreserved characters. |
| 20 /// A codec that converts byte arrays to and from percent-encoded (also known as |
| 21 /// URL-encoded) strings according to [RFC 3986][rfc]. |
| 22 /// |
| 23 /// [rfc]: https://tools.ietf.org/html/rfc3986#section-2.1 |
| 24 /// |
| 25 /// [encoder] encodes all bytes other than ASCII letters, decimal digits, or one |
| 26 /// of `-._~`. This matches the behavior of [Uri.encodeQueryComponent] except |
| 27 /// that it doesn't encode `0x20` bytes to the `+` character. |
| 28 /// |
| 29 /// To be maximally flexible, [decoder] will decode any percent-encoded byte and |
| 30 /// will allow any non-percent-encoded byte other than `%`. By default, it |
| 31 /// interprets `+` as `0x2B` rather than `0x20` as emitted by |
| 32 /// [Uri.encodeQueryComponent]. |
| 33 class PercentCodec extends Codec<List<int>, String> { |
| 34 PercentEncoder get encoder => percentEncoder; |
| 35 PercentDecoder get decoder => percentDecoder; |
| 36 |
| 37 const PercentCodec._(); |
| 38 } |
OLD | NEW |