OLD | NEW |
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library dart.core_patch; | 5 library dart.core_patch; |
6 | 6 |
7 import 'dart:fletch._system' as fletch; | 7 import 'dart:fletch._system' as fletch; |
| 8 import 'dart:fletch._system' show patch; |
| 9 import 'dart:collection' show LinkedHashMap, UnmodifiableMapView; |
8 | 10 |
9 part 'bigint.dart'; | 11 part 'bigint.dart'; |
10 part 'case.dart'; | 12 part 'case.dart'; |
11 part 'double.dart'; | 13 part 'double.dart'; |
12 part 'int.dart'; | 14 part 'int.dart'; |
13 part 'regexp.dart'; | 15 part 'regexp.dart'; |
14 part 'string.dart'; | 16 part 'string.dart'; |
15 | 17 |
16 const patch = "patch"; | |
17 | |
18 @patch external bool identical(Object a, Object b); | 18 @patch external bool identical(Object a, Object b); |
19 | 19 |
20 @patch int identityHashCode(Object object) { | 20 @patch int identityHashCode(Object object) { |
21 if (object is int) return object; | 21 if (object is int) return object; |
22 return _identityHashCode(object); | 22 return _identityHashCode(object); |
23 } | 23 } |
24 | 24 |
25 @fletch.native external _identityHashCode(Object object); | 25 @fletch.native external _identityHashCode(Object object); |
26 | 26 |
27 @patch class Object { | 27 @patch class Object { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 if (elements is List) { | 229 if (elements is List) { |
230 for (int i = 0; i < length; i++) { | 230 for (int i = 0; i < length; i++) { |
231 list[i] = elements[i]; | 231 list[i] = elements[i]; |
232 } | 232 } |
233 } else { | 233 } else { |
234 int i = 0; | 234 int i = 0; |
235 elements.forEach((e) { list[i++] = e; }); | 235 elements.forEach((e) { list[i++] = e; }); |
236 } | 236 } |
237 return list; | 237 return list; |
238 } | 238 } |
| 239 |
| 240 @patch factory List.unmodifiable(Iterable elements) { |
| 241 return new UnmodifiableListView(new List.from(elements)); |
| 242 } |
| 243 } |
| 244 |
| 245 @patch class Map<K, V> { |
| 246 @patch factory Map() = LinkedHashMap<K, V>; |
| 247 |
| 248 @patch factory Map.unmodifiable(Map other) { |
| 249 return new UnmodifiableMapView<K, V>(new Map<K, V>.from(other)); |
| 250 } |
239 } | 251 } |
240 | 252 |
241 @patch class NoSuchMethodError { | 253 @patch class NoSuchMethodError { |
242 @patch String toString() { | 254 @patch String toString() { |
243 return "NoSuchMethodError: '$_memberName'"; | 255 return "NoSuchMethodError: '$_memberName'"; |
244 } | 256 } |
245 } | 257 } |
246 | 258 |
247 @patch class int { | 259 @patch class int { |
248 @patch static int parse( | 260 @patch static int parse( |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 @patch class Uri { | 663 @patch class Uri { |
652 @patch static Uri get base { | 664 @patch static Uri get base { |
653 return new Uri.file(_base()); | 665 return new Uri.file(_base()); |
654 } | 666 } |
655 | 667 |
656 @patch static bool get _isWindows => false; | 668 @patch static bool get _isWindows => false; |
657 | 669 |
658 @fletch.native static String _base() { | 670 @fletch.native static String _base() { |
659 throw new RangeError("The Uri.base path is too large"); | 671 throw new RangeError("The Uri.base path is too large"); |
660 } | 672 } |
| 673 |
| 674 /// Encodes all characters in the string [text] except for those |
| 675 /// that appear in [canonicalTable], and returns the escaped string. |
| 676 @patch static String _uriEncode( |
| 677 List<int> canonicalTable, |
| 678 String text, |
| 679 Encoding encoding, |
| 680 bool spaceToPlus) { |
| 681 byteToHex(byte, buffer) { |
| 682 const String hex = '0123456789ABCDEF'; |
| 683 buffer.writeCharCode(hex.codeUnitAt(byte >> 4)); |
| 684 buffer.writeCharCode(hex.codeUnitAt(byte & 0x0f)); |
| 685 } |
| 686 |
| 687 // Encode the string into bytes then generate an ASCII only string |
| 688 // by percent encoding selected bytes. |
| 689 StringBuffer result = new StringBuffer(); |
| 690 var bytes = encoding.encode(text); |
| 691 for (int i = 0; i < bytes.length; i++) { |
| 692 int byte = bytes[i]; |
| 693 if (byte < 128 && |
| 694 ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) { |
| 695 result.writeCharCode(byte); |
| 696 } else if (spaceToPlus && byte == _SPACE) { |
| 697 result.writeCharCode(_PLUS); |
| 698 } else { |
| 699 result.writeCharCode(_PERCENT); |
| 700 byteToHex(byte, result); |
| 701 } |
| 702 } |
| 703 return result.toString(); |
| 704 } |
661 } | 705 } |
OLD | NEW |