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

Unified Diff: tools/dom/src/AttributeMap.dart

Issue 26917002: Convert keys in dataSet to camelCase instead of dasherized. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
« tests/html/htmlelement_test.dart ('K') | « tests/html/htmlelement_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/AttributeMap.dart
diff --git a/tools/dom/src/AttributeMap.dart b/tools/dom/src/AttributeMap.dart
index 82e998e4e5ff18d2efbc5f646fe243c46d04bf35..b74110b2e3393bd192243d350653d458cf1e5dc8 100644
--- a/tools/dom/src/AttributeMap.dart
+++ b/tools/dom/src/AttributeMap.dart
@@ -224,7 +224,36 @@ class _DataAttributeMap implements Map<String, String> {
bool get isNotEmpty => !isEmpty;
// Helpers.
- String _attr(String key) => 'data-$key';
+ String _attr(String key) => 'data-${_toHyphenedName(key)}';
bool _matches(String key) => key.startsWith('data-');
- String _strip(String key) => key.substring(5);
+ String _strip(String key) => _toCamelCase(key.substring(5));
+
+ /**
+ * Converts a string name with hyphens into an identifier, by removing hyphens
+ * and capitalizing the following letter. Optionally [startUppercase] to
+ * captialize the first letter.
+ */
+ String _toCamelCase(String hyphenedName, {bool startUppercase: false}) {
+ var segments = hyphenedName.split('-');
+ int start = startUppercase ? 0 : 1;
+ for (int i = start; i < segments.length; i++) {
+ var segment = segments[i];
+ if (segment.length > 0) {
+ // Character between 'a'..'z' mapped to 'A'..'Z'
+ segments[i] = '${segment[0].toUpperCase()}${segment.substring(1)}';
+ }
+ }
+ return segments.join('');
+ }
+
+ /** Reverse of [toCamelCase]. */
+ String _toHyphenedName(String word) {
+ var sb = new StringBuffer();
+ for (int i = 0; i < word.length; i++) {
+ var lower = word[i].toLowerCase();
+ if (word[i] != lower && i > 0) sb.write('-');
+ sb.write(lower);
+ }
+ return sb.toString();
+ }
}
« tests/html/htmlelement_test.dart ('K') | « tests/html/htmlelement_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698