OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // VM implementation of Uri. | 5 // VM implementation of Uri. |
6 typedef Uri _UriBaseClosure(); | 6 typedef Uri _UriBaseClosure(); |
7 | 7 |
8 Uri _unsupportedUriBase() { | 8 Uri _unsupportedUriBase() { |
9 throw new UnsupportedError("'Uri.base' is not supported"); | 9 throw new UnsupportedError("'Uri.base' is not supported"); |
10 } | 10 } |
11 | 11 |
12 // _uriBaseClosure can be overwritten by the embedder to supply a different | 12 // _uriBaseClosure can be overwritten by the embedder to supply a different |
13 // value for Uri.base. | 13 // value for Uri.base. |
14 _UriBaseClosure _uriBaseClosure = _unsupportedUriBase; | 14 _UriBaseClosure _uriBaseClosure = _unsupportedUriBase; |
15 | 15 |
16 @patch class Uri { | 16 @patch |
17 @patch static Uri get base => _uriBaseClosure(); | 17 class Uri { |
| 18 @patch |
| 19 static Uri get base => _uriBaseClosure(); |
18 } | 20 } |
19 | 21 |
20 @patch class _Uri { | 22 @patch |
| 23 class _Uri { |
21 static final bool _isWindowsCached = _isWindowsPlatform; | 24 static final bool _isWindowsCached = _isWindowsPlatform; |
22 | 25 |
23 static bool get _isWindowsPlatform native "Uri_isWindowsPlatform"; | 26 static bool get _isWindowsPlatform native "Uri_isWindowsPlatform"; |
24 | 27 |
25 @patch static bool get _isWindows => _isWindowsCached; | 28 @patch |
| 29 static bool get _isWindows => _isWindowsCached; |
26 | 30 |
27 @patch static String _uriEncode(List<int> canonicalTable, | 31 @patch |
28 String text, | 32 static String _uriEncode(List<int> canonicalTable, String text, |
29 Encoding encoding, | 33 Encoding encoding, bool spaceToPlus) { |
30 bool spaceToPlus) { | |
31 // First check if the text will be changed by encoding. | 34 // First check if the text will be changed by encoding. |
32 int i = 0; | 35 int i = 0; |
33 if (identical(encoding, UTF8) || | 36 if (identical(encoding, UTF8) || |
34 identical(encoding, LATIN1) || | 37 identical(encoding, LATIN1) || |
35 identical(encoding, ASCII)) { | 38 identical(encoding, ASCII)) { |
36 // Encoding is compatible with the original string. | 39 // Encoding is compatible with the original string. |
37 // Find first character that needs encoding. | 40 // Find first character that needs encoding. |
38 for (; i < text.length; i++) { | 41 for (; i < text.length; i++) { |
39 var char = text.codeUnitAt(i); | 42 var char = text.codeUnitAt(i); |
40 if (char >= 128 || | 43 if (char >= 128 || |
(...skipping 15 matching lines...) Expand all Loading... |
56 var bytes = encoding.encode(text); | 59 var bytes = encoding.encode(text); |
57 for (; i < bytes.length; i++) { | 60 for (; i < bytes.length; i++) { |
58 int byte = bytes[i]; | 61 int byte = bytes[i]; |
59 if (byte < 128 && | 62 if (byte < 128 && |
60 ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) { | 63 ((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) { |
61 result.writeCharCode(byte); | 64 result.writeCharCode(byte); |
62 } else if (spaceToPlus && byte == _SPACE) { | 65 } else if (spaceToPlus && byte == _SPACE) { |
63 result.writeCharCode(_PLUS); | 66 result.writeCharCode(_PLUS); |
64 } else { | 67 } else { |
65 const String hexDigits = '0123456789ABCDEF'; | 68 const String hexDigits = '0123456789ABCDEF'; |
66 result..writeCharCode(_PERCENT) | 69 result |
67 ..writeCharCode(hexDigits.codeUnitAt(byte >> 4)) | 70 ..writeCharCode(_PERCENT) |
68 ..writeCharCode(hexDigits.codeUnitAt(byte & 0x0f)); | 71 ..writeCharCode(hexDigits.codeUnitAt(byte >> 4)) |
| 72 ..writeCharCode(hexDigits.codeUnitAt(byte & 0x0f)); |
69 } | 73 } |
70 } | 74 } |
71 return result.toString(); | 75 return result.toString(); |
72 } | 76 } |
73 } | 77 } |
OLD | NEW |