summaryrefslogtreecommitdiffstats
path: root/base/string_split.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/string_split.cc')
-rw-r--r--base/string_split.cc19
1 files changed, 8 insertions, 11 deletions
diff --git a/base/string_split.cc b/base/string_split.cc
index cdf708b..ea694d5 100644
--- a/base/string_split.cc
+++ b/base/string_split.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -17,19 +17,16 @@ static void SplitStringT(const STR& str,
bool trim_whitespace,
std::vector<STR>* r) {
size_t last = 0;
- size_t i;
size_t c = str.size();
- for (i = 0; i <= c; ++i) {
+ for (size_t i = 0; i <= c; ++i) {
if (i == c || str[i] == s) {
- size_t len = i - last;
- STR tmp = str.substr(last, len);
- if (trim_whitespace) {
- STR t_tmp;
- TrimWhitespace(tmp, TRIM_ALL, &t_tmp);
- r->push_back(t_tmp);
- } else {
+ STR tmp(str, last, i - last);
+ if (trim_whitespace)
+ TrimWhitespace(tmp, TRIM_ALL, &tmp);
+ // Avoid converting an empty or all-whitespace source string into a vector
+ // of one empty string.
+ if (i != c || !r->empty() || !tmp.empty())
r->push_back(tmp);
- }
last = i + 1;
}
}