| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of html; | 5 part of html; |
| 6 | 6 |
| 7 abstract class _AttributeMap implements Map<String, String> { | 7 abstract class _AttributeMap implements Map<String, String> { |
| 8 final Element _element; | 8 final Element _element; |
| 9 | 9 |
| 10 _AttributeMap(this._element); | 10 _AttributeMap(this._element); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 int get length => keys.length; | 219 int get length => keys.length; |
| 220 | 220 |
| 221 // TODO: Use lazy iterator when it is available on Map. | 221 // TODO: Use lazy iterator when it is available on Map. |
| 222 bool get isEmpty => length == 0; | 222 bool get isEmpty => length == 0; |
| 223 | 223 |
| 224 bool get isNotEmpty => !isEmpty; | 224 bool get isNotEmpty => !isEmpty; |
| 225 | 225 |
| 226 // Helpers. | 226 // Helpers. |
| 227 String _attr(String key) => 'data-$key'; | 227 String _attr(String key) => 'data-${_toHyphenedName(key)}'; |
| 228 bool _matches(String key) => key.startsWith('data-'); | 228 bool _matches(String key) => key.startsWith('data-'); |
| 229 String _strip(String key) => key.substring(5); | 229 String _strip(String key) => _toCamelCase(key.substring(5)); |
| 230 |
| 231 /** |
| 232 * Converts a string name with hyphens into an identifier, by removing hyphens |
| 233 * and capitalizing the following letter. Optionally [startUppercase] to |
| 234 * captialize the first letter. |
| 235 */ |
| 236 String _toCamelCase(String hyphenedName, {bool startUppercase: false}) { |
| 237 var segments = hyphenedName.split('-'); |
| 238 int start = startUppercase ? 0 : 1; |
| 239 for (int i = start; i < segments.length; i++) { |
| 240 var segment = segments[i]; |
| 241 if (segment.length > 0) { |
| 242 // Character between 'a'..'z' mapped to 'A'..'Z' |
| 243 segments[i] = '${segment[0].toUpperCase()}${segment.substring(1)}'; |
| 244 } |
| 245 } |
| 246 return segments.join(''); |
| 247 } |
| 248 |
| 249 /** Reverse of [toCamelCase]. */ |
| 250 String _toHyphenedName(String word) { |
| 251 var sb = new StringBuffer(); |
| 252 for (int i = 0; i < word.length; i++) { |
| 253 var lower = word[i].toLowerCase(); |
| 254 if (word[i] != lower && i > 0) sb.write('-'); |
| 255 sb.write(lower); |
| 256 } |
| 257 return sb.toString(); |
| 258 } |
| 230 } | 259 } |
| OLD | NEW |