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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 return false; | 122 return false; |
123 } | 123 } |
124 } | 124 } |
125 return true; | 125 return true; |
126 } | 126 } |
127 | 127 |
128 bool endsWith(String other) { | 128 bool endsWith(String other) { |
129 return _substringMatches(this.length - other.length, other); | 129 return _substringMatches(this.length - other.length, other); |
130 } | 130 } |
131 | 131 |
132 bool startsWith(Pattern pattern) { | 132 bool startsWith(Pattern pattern, [int index = 0]) { |
| 133 if (index < 0 || index > this.length) { |
| 134 throw new RangeError.range(index, 0, this.length); |
| 135 } |
133 if (pattern is String) { | 136 if (pattern is String) { |
134 return _substringMatches(0, pattern); | 137 return _substringMatches(index, pattern); |
135 } | 138 } |
136 return pattern.matchAsPrefix(this, 0) != null; | 139 return pattern.matchAsPrefix(this, index) != null; |
137 } | 140 } |
138 | 141 |
139 int indexOf(Pattern pattern, [int start = 0]) { | 142 int indexOf(Pattern pattern, [int start = 0]) { |
140 if (start < 0 || start > this.length) { | 143 if (start < 0 || start > this.length) { |
141 throw new RangeError.range(start, 0, this.length); | 144 throw new RangeError.range(start, 0, this.length); |
142 } | 145 } |
143 if (pattern is String) { | 146 if (pattern is String) { |
144 String other = pattern; | 147 String other = pattern; |
145 int maxIndex = this.length - other.length; | 148 int maxIndex = this.length - other.length; |
146 // TODO: Use an efficient string search (e.g. BMH). | 149 // TODO: Use an efficient string search (e.g. BMH). |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 class _CodeUnits extends Object with ListMixin<int>, | 633 class _CodeUnits extends Object with ListMixin<int>, |
631 UnmodifiableListMixin<int> { | 634 UnmodifiableListMixin<int> { |
632 /** The string that this is the code units of. */ | 635 /** The string that this is the code units of. */ |
633 String _string; | 636 String _string; |
634 | 637 |
635 _CodeUnits(this._string); | 638 _CodeUnits(this._string); |
636 | 639 |
637 int get length => _string.length; | 640 int get length => _string.length; |
638 int operator[](int i) => _string.codeUnitAt(i); | 641 int operator[](int i) => _string.codeUnitAt(i); |
639 } | 642 } |
OLD | NEW |