Index: lib/core/core_patch.dart |
diff --git a/lib/core/core_patch.dart b/lib/core/core_patch.dart |
index e9bd06128e0971b90600888de29a19ef38858147..32e2faec900d20442c0e7e989b2074ab0dca898e 100644 |
--- a/lib/core/core_patch.dart |
+++ b/lib/core/core_patch.dart |
@@ -5,6 +5,8 @@ |
library dart.core_patch; |
import 'dart:fletch._system' as fletch; |
+import 'dart:fletch._system' show patch; |
+import 'dart:collection' show LinkedHashMap, UnmodifiableMapView; |
part 'bigint.dart'; |
part 'case.dart'; |
@@ -13,8 +15,6 @@ part 'int.dart'; |
part 'regexp.dart'; |
part 'string.dart'; |
-const patch = "patch"; |
- |
@patch external bool identical(Object a, Object b); |
@patch int identityHashCode(Object object) { |
@@ -236,6 +236,18 @@ const patch = "patch"; |
} |
return list; |
} |
+ |
+ @patch factory List.unmodifiable(Iterable elements) { |
+ return new UnmodifiableListView(new List.from(elements)); |
+ } |
+} |
+ |
+@patch class Map<K, V> { |
+ @patch factory Map() = LinkedHashMap<K, V>; |
+ |
+ @patch factory Map.unmodifiable(Map other) { |
+ return new UnmodifiableMapView<K, V>(new Map<K, V>.from(other)); |
+ } |
} |
@patch class NoSuchMethodError { |
@@ -658,4 +670,36 @@ const patch = "patch"; |
@fletch.native static String _base() { |
throw new RangeError("The Uri.base path is too large"); |
} |
+ |
+ /// Encodes all characters in the string [text] except for those |
+ /// that appear in [canonicalTable], and returns the escaped string. |
+ @patch static String _uriEncode( |
+ List<int> canonicalTable, |
+ String text, |
+ Encoding encoding, |
+ bool spaceToPlus) { |
+ byteToHex(byte, buffer) { |
+ const String hex = '0123456789ABCDEF'; |
+ buffer.writeCharCode(hex.codeUnitAt(byte >> 4)); |
+ buffer.writeCharCode(hex.codeUnitAt(byte & 0x0f)); |
+ } |
+ |
+ // Encode the string into bytes then generate an ASCII only string |
+ // by percent encoding selected bytes. |
+ StringBuffer result = new StringBuffer(); |
+ var bytes = encoding.encode(text); |
+ for (int i = 0; i < bytes.length; i++) { |
+ int byte = bytes[i]; |
+ if (byte < 128 && |
+ ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) { |
+ result.writeCharCode(byte); |
+ } else if (spaceToPlus && byte == _SPACE) { |
+ result.writeCharCode(_PLUS); |
+ } else { |
+ result.writeCharCode(_PERCENT); |
+ byteToHex(byte, result); |
+ } |
+ } |
+ return result.toString(); |
+ } |
} |