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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 return isSpace(c) || c == 0x0D || c == 0x0A; | 100 return isSpace(c) || c == 0x0D || c == 0x0A; |
101 } | 101 } |
102 | 102 |
103 String remove(String str, String remove) { | 103 String remove(String str, String remove) { |
104 if (isEmpty(str) || isEmpty(remove)) { | 104 if (isEmpty(str) || isEmpty(remove)) { |
105 return str; | 105 return str; |
106 } | 106 } |
107 return str.replaceAll(remove, ''); | 107 return str.replaceAll(remove, ''); |
108 } | 108 } |
109 | 109 |
| 110 String removeEnd(String str, String remove) { |
| 111 if (isEmpty(str) || isEmpty(remove)) { |
| 112 return str; |
| 113 } |
| 114 if (str.endsWith(remove)) { |
| 115 return str.substring(0, str.length - remove.length); |
| 116 } |
| 117 return str; |
| 118 } |
| 119 |
110 String removeStart(String str, String remove) { | 120 String removeStart(String str, String remove) { |
111 if (isEmpty(str) || isEmpty(remove)) { | 121 if (isEmpty(str) || isEmpty(remove)) { |
112 return str; | 122 return str; |
113 } | 123 } |
114 if (str.startsWith(remove)) { | 124 if (str.startsWith(remove)) { |
115 return str.substring(remove.length); | 125 return str.substring(remove.length); |
116 } | 126 } |
117 return str; | 127 return str; |
118 } | 128 } |
119 | 129 |
(...skipping 17 matching lines...) Expand all Loading... |
137 } | 147 } |
138 if (isEmpty(separator)) { | 148 if (isEmpty(separator)) { |
139 return ''; | 149 return ''; |
140 } | 150 } |
141 int pos = str.lastIndexOf(separator); | 151 int pos = str.lastIndexOf(separator); |
142 if (pos == -1) { | 152 if (pos == -1) { |
143 return str; | 153 return str; |
144 } | 154 } |
145 return str.substring(pos + separator.length); | 155 return str.substring(pos + separator.length); |
146 } | 156 } |
OLD | NEW |