summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/string_split.cc3
-rw-r--r--base/string_split.h8
-rw-r--r--base/string_split_unittest.cc3
3 files changed, 7 insertions, 7 deletions
diff --git a/base/string_split.cc b/base/string_split.cc
index ea694d5..e5befcf 100644
--- a/base/string_split.cc
+++ b/base/string_split.cc
@@ -16,6 +16,7 @@ static void SplitStringT(const STR& str,
const typename STR::value_type s,
bool trim_whitespace,
std::vector<STR>* r) {
+ r->clear();
size_t last = 0;
size_t c = str.size();
for (size_t i = 0; i <= c; ++i) {
@@ -115,6 +116,7 @@ template <typename STR>
static void SplitStringUsingSubstrT(const STR& str,
const STR& s,
std::vector<STR>* r) {
+ r->clear();
typename STR::size_type begin_index = 0;
while (true) {
const typename STR::size_type end_index = str.find(s, begin_index);
@@ -165,6 +167,7 @@ void SplitStringDontTrim(const std::string& str,
template<typename STR>
void SplitStringAlongWhitespaceT(const STR& str, std::vector<STR>* result) {
+ result->clear();
const size_t length = str.length();
if (!length)
return;
diff --git a/base/string_split.h b/base/string_split.h
index 6c7895d..32f6d8d 100644
--- a/base/string_split.h
+++ b/base/string_split.h
@@ -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.
@@ -15,9 +15,9 @@
namespace base {
-// Splits |str| into a vector of strings delimited by |s|. Append the results
-// into |r| as they appear. If several instances of |s| are contiguous, or if
-// |str| begins with or ends with |s|, then an empty string is inserted.
+// Splits |str| into a vector of strings delimited by |s|, placing the results
+// in |r|. If several instances of |s| are contiguous, or if |str| begins with
+// or ends with |s|, then an empty string is inserted.
//
// Every substring is trimmed of any leading or trailing white space.
// NOTE: |c| must be in BMP (Basic Multilingual Plane)
diff --git a/base/string_split_unittest.cc b/base/string_split_unittest.cc
index 5d4dafe..a4412e4 100644
--- a/base/string_split_unittest.cc
+++ b/base/string_split_unittest.cc
@@ -267,7 +267,6 @@ TEST(StringSplitTest, StringSplitDontTrim) {
SplitStringDontTrim(" ", '*', &r);
ASSERT_EQ(1U, r.size());
EXPECT_EQ(r[0], " ");
- r.clear();
SplitStringDontTrim("\t \ta\t ", '\t', &r);
ASSERT_EQ(4U, r.size());
@@ -275,13 +274,11 @@ TEST(StringSplitTest, StringSplitDontTrim) {
EXPECT_EQ(r[1], " ");
EXPECT_EQ(r[2], "a");
EXPECT_EQ(r[3], " ");
- r.clear();
SplitStringDontTrim("\ta\t\nb\tcc", '\n', &r);
ASSERT_EQ(2U, r.size());
EXPECT_EQ(r[0], "\ta\t");
EXPECT_EQ(r[1], "b\tcc");
- r.clear();
}
TEST(StringSplitTest, SplitStringAlongWhitespace) {