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

Unified Diff: sdk/lib/internal/internal.dart

Issue 2694373003: Normalize UriData.parse result. (Closed)
Patch Set: Address comments. Fix bug. Created 3 years, 10 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 | « sdk/lib/core/uri.dart ('k') | tests/corelib/data_uri_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/internal/internal.dart
diff --git a/sdk/lib/internal/internal.dart b/sdk/lib/internal/internal.dart
index 0acf068b50b01a90b95843f6ca01893aeaae40b5..2ff80da9c4159781f5968e885dbafdd721ad0cfe 100644
--- a/sdk/lib/internal/internal.dart
+++ b/sdk/lib/internal/internal.dart
@@ -69,3 +69,30 @@ class ExternalName {
final String name;
const ExternalName(this.name);
}
+
+// Shared hex-parsing utilities.
+
+/// Parses a single hex-digit as code unit.
+///
+/// Returns a negative value if the character is not a valid hex-digit.
+int hexDigitValue(int char) {
+ assert(char >= 0 && char <= 0xFFFF);
+ const int digit0 = 0x30;
+ const int a = 0x61;
+ const int f = 0x66;
+ int digit = char ^ digit0;
+ if (digit <= 9) return digit;
+ int letter = (char | 0x20);
+ if (a <= letter && letter <= f) return letter - (a - 10);
+ return -1;
+}
+
+/// Parses two hex digits in a string.
+///
+/// Returns a negative value if either digit isn't valid.
+int parseHexByte(String source, int index) {
+ assert(index + 2 <= source.length);
+ int digit1 = hexDigitValue(source.codeUnitAt(index));
+ int digit2 = hexDigitValue(source.codeUnitAt(index + 1));
+ return digit1 * 16 + digit2 - (digit2 & 256);
+}
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | tests/corelib/data_uri_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698