Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Side by Side Diff: runtime/lib/string_patch.dart

Issue 17281002: Make String.startsWith take an optional start index. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/js_string.dart » ('j') | sdk/lib/core/string.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/js_string.dart » ('j') | sdk/lib/core/string.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698