Chromium Code Reviews| Index: lib/src/percent.dart |
| diff --git a/lib/src/percent.dart b/lib/src/percent.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0d63f6c8209668a810ec199204deb107da0e4ebf |
| --- /dev/null |
| +++ b/lib/src/percent.dart |
| @@ -0,0 +1,38 @@ |
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library convert.percent; |
| + |
| +import 'dart:convert'; |
| + |
| +import 'percent/encoder.dart'; |
| +import 'percent/decoder.dart'; |
| + |
| +export 'percent/encoder.dart' hide percentEncoder; |
| +export 'percent/decoder.dart' hide percentDecoder; |
| + |
| +/// The canonical instance of [PercentCodec]. |
| +const percent = const PercentCodec._(); |
| + |
| +// TODO(nweiz): Add flags to support generating and interpreting "+" as a space |
| +// character. |
|
Lasse Reichstein Nielsen
2015/10/08 10:30:36
That's not plain percent-encoding. It's www-form-u
|
| +/// A codec that converts byte arrays to and from percent-encoded (also known as |
| +/// URL-encoded) strings according to [RFC 3986][rfc]. |
| +/// |
| +/// [rfc]: https://tools.ietf.org/html/rfc3986#section-2.1 |
| +/// |
| +/// [encoder] encodes all bytes other than ASCII letters, decimal digits, or one |
| +/// of `-._~`. This matches the behavior of [Uri.encodeQueryComponent] except |
| +/// that it doesn't encode `0x20` bytes to the `+` character. |
| +/// |
| +/// To be maximally flexible, [decoder] will decode any percent-encoded byte and |
| +/// will allow any non-percent-encoded byte other than `%`. By default, it |
| +/// interprets `+` as `0x2B` rather than `0x20` as emitted by |
| +/// [Uri.encodeQueryComponent]. |
| +class PercentCodec extends Codec<List<int>, String> { |
| + PercentEncoder get encoder => percentEncoder; |
| + PercentDecoder get decoder => percentDecoder; |
| + |
| + const PercentCodec._(); |
| +} |