| 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 part of _interceptors; | 5 part of _interceptors; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The interceptor class for [String]. The compiler recognizes this | 8 * The interceptor class for [String]. The compiler recognizes this |
| 9 * class as an interceptor, and changes references to [:this:] to | 9 * class as an interceptor, and changes references to [:this:] to |
| 10 * actually use the receiver of the method, which is generated as an extra | 10 * actually use the receiver of the method, which is generated as an extra |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 if (delta <= 0) return this; | 376 if (delta <= 0) return this; |
| 377 return this + padding * delta; | 377 return this + padding * delta; |
| 378 } | 378 } |
| 379 | 379 |
| 380 List<int> get codeUnits => new CodeUnits(this); | 380 List<int> get codeUnits => new CodeUnits(this); |
| 381 | 381 |
| 382 Runes get runes => new Runes(this); | 382 Runes get runes => new Runes(this); |
| 383 | 383 |
| 384 int indexOf(Pattern pattern, [int start = 0]) { | 384 int indexOf(Pattern pattern, [int start = 0]) { |
| 385 checkNull(pattern); | 385 checkNull(pattern); |
| 386 if (start is! int) throw new ArgumentError(start); | 386 if (start is! int) throw argumentErrorValue(start); |
| 387 if (start < 0 || start > this.length) { | 387 if (start < 0 || start > this.length) { |
| 388 throw new RangeError.range(start, 0, this.length); | 388 throw new RangeError.range(start, 0, this.length); |
| 389 } | 389 } |
| 390 if (pattern is String) { | 390 if (pattern is String) { |
| 391 return stringIndexOfStringUnchecked(this, pattern, start); | 391 return stringIndexOfStringUnchecked(this, pattern, start); |
| 392 } | 392 } |
| 393 if (pattern is JSSyntaxRegExp) { | 393 if (pattern is JSSyntaxRegExp) { |
| 394 JSSyntaxRegExp re = pattern; | 394 JSSyntaxRegExp re = pattern; |
| 395 Match match = firstMatchAfter(re, this, start); | 395 Match match = firstMatchAfter(re, this, start); |
| 396 return (match == null) ? -1 : match.start; | 396 return (match == null) ? -1 : match.start; |
| 397 } | 397 } |
| 398 for (int i = start; i <= this.length; i++) { | 398 for (int i = start; i <= this.length; i++) { |
| 399 if (pattern.matchAsPrefix(this, i) != null) return i; | 399 if (pattern.matchAsPrefix(this, i) != null) return i; |
| 400 } | 400 } |
| 401 return -1; | 401 return -1; |
| 402 } | 402 } |
| 403 | 403 |
| 404 int lastIndexOf(Pattern pattern, [int start]) { | 404 int lastIndexOf(Pattern pattern, [int start]) { |
| 405 checkNull(pattern); | 405 checkNull(pattern); |
| 406 if (start == null) { | 406 if (start == null) { |
| 407 start = length; | 407 start = length; |
| 408 } else if (start is! int) { | 408 } else if (start is! int) { |
| 409 throw new ArgumentError(start); | 409 throw argumentErrorValue(start); |
| 410 } else if (start < 0 || start > this.length) { | 410 } else if (start < 0 || start > this.length) { |
| 411 throw new RangeError.range(start, 0, this.length); | 411 throw new RangeError.range(start, 0, this.length); |
| 412 } | 412 } |
| 413 if (pattern is String) { | 413 if (pattern is String) { |
| 414 String other = pattern; | 414 String other = pattern; |
| 415 if (start + other.length > this.length) { | 415 if (start + other.length > this.length) { |
| 416 start = this.length - other.length; | 416 start = this.length - other.length; |
| 417 } | 417 } |
| 418 return stringLastIndexOfUnchecked(this, other, start); | 418 return stringLastIndexOfUnchecked(this, other, start); |
| 419 } | 419 } |
| 420 for (int i = start; i >= 0; i--) { | 420 for (int i = start; i >= 0; i--) { |
| 421 if (pattern.matchAsPrefix(this, i) != null) return i; | 421 if (pattern.matchAsPrefix(this, i) != null) return i; |
| 422 } | 422 } |
| 423 return -1; | 423 return -1; |
| 424 } | 424 } |
| 425 | 425 |
| 426 bool contains(Pattern other, [int startIndex = 0]) { | 426 bool contains(Pattern other, [int startIndex = 0]) { |
| 427 checkNull(other); | 427 checkNull(other); |
| 428 if (startIndex < 0 || startIndex > this.length) { | 428 if (startIndex < 0 || startIndex > this.length) { |
| 429 throw new RangeError.range(startIndex, 0, this.length); | 429 throw new RangeError.range(startIndex, 0, this.length); |
| 430 } | 430 } |
| 431 return stringContainsUnchecked(this, other, startIndex); | 431 return stringContainsUnchecked(this, other, startIndex); |
| 432 } | 432 } |
| 433 | 433 |
| 434 bool get isEmpty => length == 0; | 434 bool get isEmpty => length == 0; |
| 435 | 435 |
| 436 bool get isNotEmpty => !isEmpty; | 436 bool get isNotEmpty => !isEmpty; |
| 437 | 437 |
| 438 int compareTo(String other) { | 438 int compareTo(String other) { |
| 439 if (other is !String) throw new ArgumentError(other); | 439 if (other is !String) throw argumentErrorValue(other); |
| 440 return this == other ? 0 | 440 return this == other ? 0 |
| 441 : JS('bool', r'# < #', this, other) ? -1 : 1; | 441 : JS('bool', r'# < #', this, other) ? -1 : 1; |
| 442 } | 442 } |
| 443 | 443 |
| 444 // Note: if you change this, also change the function [S]. | 444 // Note: if you change this, also change the function [S]. |
| 445 String toString() => this; | 445 String toString() => this; |
| 446 | 446 |
| 447 /** | 447 /** |
| 448 * This is the [Jenkins hash function][1] but using masking to keep | 448 * This is the [Jenkins hash function][1] but using masking to keep |
| 449 * values in SMI range. | 449 * values in SMI range. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 467 Type get runtimeType => String; | 467 Type get runtimeType => String; |
| 468 | 468 |
| 469 int get length => JS('int', r'#.length', this); | 469 int get length => JS('int', r'#.length', this); |
| 470 | 470 |
| 471 String operator [](int index) { | 471 String operator [](int index) { |
| 472 if (index is !int) throw diagnoseIndexError(this, index); | 472 if (index is !int) throw diagnoseIndexError(this, index); |
| 473 if (index >= length || index < 0) throw diagnoseIndexError(this, index); | 473 if (index >= length || index < 0) throw diagnoseIndexError(this, index); |
| 474 return JS('String', '#[#]', this, index); | 474 return JS('String', '#[#]', this, index); |
| 475 } | 475 } |
| 476 } | 476 } |
| OLD | NEW |