| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool endsWith(String other) { | 98 bool endsWith(String other) { |
| 99 return this.substringMatches(this.length - other.length, other); | 99 return this.substringMatches(this.length - other.length, other); |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool startsWith(String other) { | 102 bool startsWith(String other) { |
| 103 return this.substringMatches(0, other); | 103 return this.substringMatches(0, other); |
| 104 } | 104 } |
| 105 | 105 |
| 106 int indexOf(String other, int startIndex) { | 106 int indexOf(String other, [int start = 0]) { |
| 107 if (other.isEmpty()) { | 107 if (other.isEmpty()) { |
| 108 return startIndex < this.length ? startIndex : this.length; | 108 return start < this.length ? start : this.length; |
| 109 } | 109 } |
| 110 if ((startIndex < 0) || (startIndex >= this.length)) { | 110 if ((start < 0) || (start >= this.length)) { |
| 111 return -1; | 111 return -1; |
| 112 } | 112 } |
| 113 int len = this.length - other.length + 1; | 113 int len = this.length - other.length + 1; |
| 114 for (int index = startIndex; index < len; index++) { | 114 for (int index = start; index < len; index++) { |
| 115 if (this.substringMatches(index, other)) { | 115 if (this.substringMatches(index, other)) { |
| 116 return index; | 116 return index; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 return -1; | 119 return -1; |
| 120 } | 120 } |
| 121 | 121 |
| 122 int lastIndexOf(String other, int fromIndex) { | 122 int lastIndexOf(String other, [int start = null]) { |
| 123 if (start == null) start = length - 1; |
| 123 if (other.isEmpty()) { | 124 if (other.isEmpty()) { |
| 124 return Math.min(this.length, fromIndex); | 125 return Math.min(this.length, start); |
| 125 } | 126 } |
| 126 if (fromIndex >= this.length) { | 127 if (start >= this.length) { |
| 127 fromIndex = this.length - 1; | 128 start = this.length - 1; |
| 128 } | 129 } |
| 129 for (int index = fromIndex; index >= 0; index--) { | 130 for (int index = start; index >= 0; index--) { |
| 130 if (this.substringMatches(index, other)) { | 131 if (this.substringMatches(index, other)) { |
| 131 return index; | 132 return index; |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 return -1; | 135 return -1; |
| 135 } | 136 } |
| 136 | 137 |
| 137 String substring(int startIndex, [int endIndex]) { | 138 String substring(int startIndex, [int endIndex]) { |
| 138 if (endIndex === null) endIndex = this.length; | 139 if (endIndex === null) endIndex = this.length; |
| 139 | 140 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 for (int g in groups) { | 436 for (int g in groups) { |
| 436 result.add(group(g)); | 437 result.add(group(g)); |
| 437 } | 438 } |
| 438 return result; | 439 return result; |
| 439 } | 440 } |
| 440 | 441 |
| 441 final int _start; | 442 final int _start; |
| 442 final String str; | 443 final String str; |
| 443 final String pattern; | 444 final String pattern; |
| 444 } | 445 } |
| OLD | NEW |