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

Unified Diff: lib/src/percent.dart

Issue 1393003003: Add a percent-encoding converter. (Closed) Base URL: git@github.com:dart-lang/convert.git@master
Patch Set: Code review changes Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/hex/encoder.dart ('k') | lib/src/percent/decoder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/percent.dart
diff --git a/lib/src/percent.dart b/lib/src/percent.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3bb3da141d60beb76f08523143bdcf24701c9003
--- /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. Also add an option for custom sets of unreserved characters.
+/// 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._();
+}
« no previous file with comments | « lib/src/hex/encoder.dart ('k') | lib/src/percent/decoder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698