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

Unified Diff: pkg/csslib/lib/src/property.dart

Issue 651823002: Rewrite csslib's hexToInt (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | « no previous file | pkg/csslib/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/csslib/lib/src/property.dart
diff --git a/pkg/csslib/lib/src/property.dart b/pkg/csslib/lib/src/property.dart
index 8dc4dcb41d38abfc5ee40d1f02c49fa52d1eb501..777288a67bf2fa2e4404911eb5039fc02e8c5663 100644
--- a/pkg/csslib/lib/src/property.dart
+++ b/pkg/csslib/lib/src/property.dart
@@ -291,34 +291,7 @@ class Color implements _StyleProperty, ColorBase {
}
}
- /**
- * [hex] hexadecimal string to convert to scalar.
- * returns hexadecimal number as an integer.
- * throws BadNumberFormatException if [hex] isn't a valid hexadecimal number.
- */
- // TODO(terry): Should be part of Dart standard library see bug
- // <http://code.google.com/p/dart/issues/detail?id=2624>
- static int hexToInt(String hex) {
- int val = 0;
-
- int len = hex.length;
- for (int i = 0; i < len; i++) {
- int hexDigit = hex.codeUnitAt(i);
- if (hexDigit >= 48 && hexDigit <= 57) {
- val += (hexDigit - 48) * (1 << (4 * (len - 1 - i)));
- } else if (hexDigit >= 65 && hexDigit <= 70) {
- // A..F
- val += (hexDigit - 55) * (1 << (4 * (len - 1 - i)));
- } else if (hexDigit >= 97 && hexDigit <= 102) {
- // a..f
- val += (hexDigit - 87) * (1 << (4 * (len - 1 - i)));
- } else {
- throw throw new FormatException("Bad hexadecimal value");
- }
- }
-
- return val;
- }
+ static int hexToInt(String hex) => int.parse(hex, radix: 16);
static String convertToHexString(int r, int g, int b, [num a]) {
String rHex = Color._numAs2DigitHex(Color._clamp(r, 0, 255));
« no previous file with comments | « no previous file | pkg/csslib/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698