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 /** | 5 /** |
6 * Javascript-like URI encode/decode functions. | 6 * Javascript-like URI encode/decode functions. |
7 * The documentation here borrows heavily from the original Javascript | 7 * The documentation here borrows heavily from the original Javascript |
8 * doumentation on MDN at: | 8 * doumentation on MDN at: |
9 * https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects | 9 * https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects |
10 */ | 10 */ |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 return result.toString(); | 101 return result.toString(); |
102 } | 102 } |
103 | 103 |
104 /** | 104 /** |
105 * Convert a byte (2 character hex sequence) in string [s] starting | 105 * Convert a byte (2 character hex sequence) in string [s] starting |
106 * at position [pos] to its ordinal value | 106 * at position [pos] to its ordinal value |
107 */ | 107 */ |
108 | 108 |
109 int _hexCharPairToByte(String s, int pos) { | 109 int _hexCharPairToByte(String s, int pos) { |
110 // An alternative to calling parseInt twice would be to take a | 110 // An alternative to calling [int.parse] twice would be to take a |
111 // two character substring and call it once, but that may be less | 111 // two character substring and call it once, but that may be less |
112 // efficient. | 112 // efficient. |
113 int d1 = parseInt("0x${s[pos]}"); | 113 // TODO(lrn): I fail to see how that could possibly be slower than this. |
114 int d2 = parseInt("0x${s[pos+1]}"); | 114 int d1 = int.parse("0x${s[pos]}"); |
| 115 int d2 = int.parse("0x${s[pos+1]}"); |
115 return d1 * 16 + d2; | 116 return d1 * 16 + d2; |
116 } | 117 } |
117 | 118 |
118 /** | 119 /** |
119 * A JavaScript-like decodeURI function. It unescapes the string [text] and | 120 * A JavaScript-like decodeURI function. It unescapes the string [text] and |
120 * returns the unescaped string. | 121 * returns the unescaped string. |
121 */ | 122 */ |
122 String _uriDecode(String text) { | 123 String _uriDecode(String text) { |
123 StringBuffer result = new StringBuffer(); | 124 StringBuffer result = new StringBuffer(); |
124 List<int> codepoints = new List<int>(); | 125 List<int> codepoints = new List<int>(); |
(...skipping 13 matching lines...) Expand all Loading... |
138 if (i == text.length) | 139 if (i == text.length) |
139 break; | 140 break; |
140 ch = text[i]; | 141 ch = text[i]; |
141 } | 142 } |
142 result.add(decodeUtf8(codepoints)); | 143 result.add(decodeUtf8(codepoints)); |
143 } | 144 } |
144 } | 145 } |
145 return result.toString(); | 146 return result.toString(); |
146 } | 147 } |
147 | 148 |
OLD | NEW |