OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library services.src.correction.strings; | 5 library services.src.correction.strings; |
6 | 6 |
7 | 7 |
8 /** | 8 /** |
9 * "$" | 9 * "$" |
10 */ | 10 */ |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 | 120 |
121 String repeat(String s, int n) { | 121 String repeat(String s, int n) { |
122 StringBuffer sb = new StringBuffer(); | 122 StringBuffer sb = new StringBuffer(); |
123 for (int i = 0; i < n; i++) { | 123 for (int i = 0; i < n; i++) { |
124 sb.write(s); | 124 sb.write(s); |
125 } | 125 } |
126 return sb.toString(); | 126 return sb.toString(); |
127 } | 127 } |
| 128 |
| 129 |
| 130 /** |
| 131 * Gets the substring after the last occurrence of a separator. |
| 132 * The separator is not returned. |
| 133 */ |
| 134 String substringAfterLast(String str, String separator) { |
| 135 if (isEmpty(str)) { |
| 136 return str; |
| 137 } |
| 138 if (isEmpty(separator)) { |
| 139 return ''; |
| 140 } |
| 141 int pos = str.lastIndexOf(separator); |
| 142 if (pos == -1) { |
| 143 return str; |
| 144 } |
| 145 return str.substring(pos + separator.length); |
| 146 } |
OLD | NEW |