| 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 patch class String { | 5 patch class String { |
| 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { | 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { |
| 7 return _StringBase.createFromCharCodes(charCodes); | 7 return _StringBase.createFromCharCodes(charCodes); |
| 8 } | 8 } |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 150 } |
| 151 if ((endIndex < 0) || (endIndex > this.length)) { | 151 if ((endIndex < 0) || (endIndex > this.length)) { |
| 152 throw new RangeError.value(endIndex); | 152 throw new RangeError.value(endIndex); |
| 153 } | 153 } |
| 154 if (startIndex > endIndex) { | 154 if (startIndex > endIndex) { |
| 155 throw new RangeError.value(startIndex); | 155 throw new RangeError.value(startIndex); |
| 156 } | 156 } |
| 157 return _substringUnchecked(startIndex, endIndex); | 157 return _substringUnchecked(startIndex, endIndex); |
| 158 } | 158 } |
| 159 | 159 |
| 160 String slice([int startIndex, int endIndex]) { | |
| 161 int start, end; | |
| 162 if (startIndex == null) { | |
| 163 start = 0; | |
| 164 } else if (startIndex is! int) { | |
| 165 throw new ArgumentError("startIndex is not int"); | |
| 166 } else if (startIndex >= 0) { | |
| 167 start = startIndex; | |
| 168 } else { | |
| 169 start = this.length + startIndex; | |
| 170 } | |
| 171 if (start < 0 || start > this.length) { | |
| 172 throw new RangeError( | |
| 173 "startIndex out of range: $startIndex (length: $length)"); | |
| 174 } | |
| 175 if (endIndex == null) { | |
| 176 end = this.length; | |
| 177 } else if (endIndex is! int) { | |
| 178 throw new ArgumentError("endIndex is not int"); | |
| 179 } else if (endIndex >= 0) { | |
| 180 end = endIndex; | |
| 181 } else { | |
| 182 end = this.length + endIndex; | |
| 183 } | |
| 184 if (end < 0 || end > this.length) { | |
| 185 throw new RangeError( | |
| 186 "endIndex out of range: $endIndex (length: $length)"); | |
| 187 } | |
| 188 if (end < start) { | |
| 189 throw new ArgumentError( | |
| 190 "End before start: $endIndex < $startIndex (length: $length)"); | |
| 191 } | |
| 192 return _substringUnchecked(start, end); | |
| 193 } | |
| 194 | |
| 195 String _substringUnchecked(int startIndex, int endIndex) { | 160 String _substringUnchecked(int startIndex, int endIndex) { |
| 196 assert(endIndex != null); | 161 assert(endIndex != null); |
| 197 assert((startIndex >= 0) && (startIndex <= this.length)); | 162 assert((startIndex >= 0) && (startIndex <= this.length)); |
| 198 assert((endIndex >= 0) && (endIndex <= this.length)); | 163 assert((endIndex >= 0) && (endIndex <= this.length)); |
| 199 assert(startIndex <= endIndex); | 164 assert(startIndex <= endIndex); |
| 200 | 165 |
| 201 if (startIndex == endIndex) { | 166 if (startIndex == endIndex) { |
| 202 return ""; | 167 return ""; |
| 203 } | 168 } |
| 204 if ((startIndex + 1) == endIndex) { | 169 if ((startIndex + 1) == endIndex) { |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 class _CodeUnits extends Object with ListMixin<int>, | 585 class _CodeUnits extends Object with ListMixin<int>, |
| 621 UnmodifiableListMixin<int> { | 586 UnmodifiableListMixin<int> { |
| 622 /** The string that this is the code units of. */ | 587 /** The string that this is the code units of. */ |
| 623 String _string; | 588 String _string; |
| 624 | 589 |
| 625 _CodeUnits(this._string); | 590 _CodeUnits(this._string); |
| 626 | 591 |
| 627 int get length => _string.length; | 592 int get length => _string.length; |
| 628 int operator[](int i) => _string.codeUnitAt(i); | 593 int operator[](int i) => _string.codeUnitAt(i); |
| 629 } | 594 } |
| OLD | NEW |