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

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

Issue 10989013: Change IllegalArgumentException to ArgumentError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated co19 test expectations. Created 8 years, 2 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
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 /** 5 /**
6 * [StringBase] contains common methods used by concrete String implementations, 6 * [StringBase] contains common methods used by concrete String implementations,
7 * e.g., OneByteString. 7 * e.g., OneByteString.
8 */ 8 */
9 class StringBase { 9 class StringBase {
10 10
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 187
188 bool contains(Pattern pattern, [int startIndex = 0]) { 188 bool contains(Pattern pattern, [int startIndex = 0]) {
189 if (pattern is String) { 189 if (pattern is String) {
190 return indexOf(pattern, startIndex) >= 0; 190 return indexOf(pattern, startIndex) >= 0;
191 } 191 }
192 return pattern.allMatches(this.substring(startIndex)).iterator().hasNext(); 192 return pattern.allMatches(this.substring(startIndex)).iterator().hasNext();
193 } 193 }
194 194
195 String replaceFirst(Pattern pattern, String replacement) { 195 String replaceFirst(Pattern pattern, String replacement) {
196 if (pattern is! Pattern) { 196 if (pattern is! Pattern) {
197 throw new IllegalArgumentException("${pattern} is not a Pattern"); 197 throw new ArgumentError("${pattern} is not a Pattern");
198 } 198 }
199 if (replacement is! String) { 199 if (replacement is! String) {
200 throw new IllegalArgumentException("${replacement} is not a String"); 200 throw new ArgumentError("${replacement} is not a String");
201 } 201 }
202 StringBuffer buffer = new StringBuffer(); 202 StringBuffer buffer = new StringBuffer();
203 int startIndex = 0; 203 int startIndex = 0;
204 Iterator iterator = pattern.allMatches(this).iterator(); 204 Iterator iterator = pattern.allMatches(this).iterator();
205 if (iterator.hasNext()) { 205 if (iterator.hasNext()) {
206 Match match = iterator.next(); 206 Match match = iterator.next();
207 buffer.add(this.substring(startIndex, match.start())).add(replacement); 207 buffer.add(this.substring(startIndex, match.start())).add(replacement);
208 startIndex = match.end(); 208 startIndex = match.end();
209 } 209 }
210 return buffer.add(this.substring(startIndex)).toString(); 210 return buffer.add(this.substring(startIndex)).toString();
211 } 211 }
212 212
213 String replaceAll(Pattern pattern, String replacement) { 213 String replaceAll(Pattern pattern, String replacement) {
214 if (pattern is! Pattern) { 214 if (pattern is! Pattern) {
215 throw new IllegalArgumentException("${pattern} is not a Pattern"); 215 throw new ArgumentError("${pattern} is not a Pattern");
216 } 216 }
217 if (replacement is! String) { 217 if (replacement is! String) {
218 throw new IllegalArgumentException("${replacement} is not a String"); 218 throw new ArgumentError("${replacement} is not a String");
219 } 219 }
220 StringBuffer buffer = new StringBuffer(); 220 StringBuffer buffer = new StringBuffer();
221 int startIndex = 0; 221 int startIndex = 0;
222 for (Match match in pattern.allMatches(this)) { 222 for (Match match in pattern.allMatches(this)) {
223 buffer.add(this.substring(startIndex, match.start())).add(replacement); 223 buffer.add(this.substring(startIndex, match.start())).add(replacement);
224 startIndex = match.end(); 224 startIndex = match.end();
225 } 225 }
226 return buffer.add(this.substring(startIndex)).toString(); 226 return buffer.add(this.substring(startIndex)).toString();
227 } 227 }
228 228
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 for (int g in groups) { 479 for (int g in groups) {
480 result.add(group(g)); 480 result.add(group(g));
481 } 481 }
482 return result; 482 return result;
483 } 483 }
484 484
485 final int _start; 485 final int _start;
486 final String str; 486 final String str;
487 final String pattern; 487 final String pattern;
488 } 488 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698