Chromium Code Reviews| Index: runtime/lib/string_patch.dart |
| diff --git a/runtime/lib/string_patch.dart b/runtime/lib/string_patch.dart |
| index 1bececf5b3965a666d8fd2f99cd2e6c6884e39bb..8f8baf204c563b9383d59e84427445de2a924a22 100644 |
| --- a/runtime/lib/string_patch.dart |
| +++ b/runtime/lib/string_patch.dart |
| @@ -297,9 +297,48 @@ class _StringBase { |
| // Returns this string if it does not have leading or trailing |
| // whitespaces. |
| return this; |
| - } else { |
| - return _substringUnchecked(first, last + 1); |
| } |
| + return _substringUnchecked(first, last + 1); |
| + } |
| + |
| + String trimLeft() { |
| + final len = this.length; |
| + int first = 0; |
| + for (; first < len; first++) { |
| + if (!_isWhitespace(this.codeUnitAt(first))) { |
| + break; |
| + } |
| + } |
| + if (len == first) { |
| + // String contains only whitespaces. |
| + return ""; |
| + } |
| + if (first == 0) { |
| + // Returns this string if it does not have leading or trailing |
|
Søren Gjesse
2014/03/10 16:50:03
if -> as
Lasse Reichstein Nielsen
2014/03/11 10:36:29
Rewritten.
|
| + // whitespaces. |
| + return this; |
| + } |
| + return _substringUnchecked(first, len); |
| + } |
| + |
| + String trimRight() { |
| + final len = this.length; |
| + int last = len - 1; |
| + for (; last >= 0; last--) { |
| + if (!_isWhitespace(this.codeUnitAt(last))) { |
| + break; |
| + } |
| + } |
| + if (last == -1) { |
| + // String contains only whitespaces. |
| + return ""; |
| + } |
| + if (last == (len - 1)) { |
| + // Returns this string if it does not have trailing |
|
Søren Gjesse
2014/03/10 16:50:03
ditto.
Lasse Reichstein Nielsen
2014/03/11 10:36:29
Done.
|
| + // whitespaces. |
| + return this; |
| + } |
| + return _substringUnchecked(0, last + 1); |
| } |
| String operator*(int times) { |