Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: runtime/lib/string.dart

Issue 8510066: Fix String.trim implementation (follow spec). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « corelib/src/implementation/queue.dart ('k') | runtime/lib/string_buffer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string.dart
===================================================================
--- runtime/lib/string.dart (revision 1520)
+++ runtime/lib/string.dart (working copy)
@@ -160,7 +160,7 @@
}
String trim() {
- int len = this.length;
+ final int len = this.length;
int first = 0;
for (; first < len; first++) {
if (!_isWhitespace(this.charCodeAt(first))) {
@@ -172,12 +172,18 @@
return "";
}
int last = len - 1;
- for (int i = last; last >= first; last--) {
+ for (; last >= first; last--) {
if (!_isWhitespace(this.charCodeAt(last))) {
break;
}
}
- return substringUnchecked_(first, last + 1);
+ if ((first == 0) && (last == (len - 1))) {
+ // Returns this string if it does not have leading or trailing
+ // whitespaces.
+ return this;
+ } else {
+ return substringUnchecked_(first, last + 1);
+ }
}
bool contains(Pattern other, [int startIndex = 0]) {
« no previous file with comments | « corelib/src/implementation/queue.dart ('k') | runtime/lib/string_buffer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698