summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/mime_util_xdg.cc5
-rw-r--r--base/string_split.cc49
-rw-r--r--base/string_split.h19
-rw-r--r--base/string_split_unittest.cc18
-rw-r--r--base/string_util.cc22
-rw-r--r--base/string_util.h11
-rw-r--r--base/string_util_unittest.cc14
-rw-r--r--chrome/plugin/chrome_plugin_host.cc5
-rw-r--r--chrome/renderer/extensions/bindings_utils.cc5
-rw-r--r--chrome/renderer/safe_browsing/phishing_url_feature_extractor.cc4
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy_backend.cc3
-rw-r--r--net/websockets/websocket_handshake_unittest.cc3
-rw-r--r--net/websockets/websocket_net_log_params.h3
-rw-r--r--webkit/glue/dom_operations.cc3
14 files changed, 108 insertions, 56 deletions
diff --git a/base/mime_util_xdg.cc b/base/mime_util_xdg.cc
index d00a568..5dc4960 100644
--- a/base/mime_util_xdg.cc
+++ b/base/mime_util_xdg.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -18,6 +18,7 @@
#include "base/message_loop.h"
#include "base/scoped_ptr.h"
#include "base/singleton.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "base/third_party/xdg_mime/xdgmime.h"
@@ -272,7 +273,7 @@ bool IconTheme::LoadIndexTheme(const FilePath& file) {
std::string key, value;
std::vector<std::string> r;
- SplitStringDontTrim(entry, '=', &r);
+ base::SplitStringDontTrim(entry, '=', &r);
if (r.size() < 2)
continue;
diff --git a/base/string_split.cc b/base/string_split.cc
index b2b70ea..646b4de 100644
--- a/base/string_split.cc
+++ b/base/string_split.cc
@@ -6,6 +6,8 @@
#include "base/logging.h"
#include "base/string_util.h"
+#include "base/third_party/icu/icu_utf.h"
+#include "base/utf_string_conversions.h"
namespace base {
@@ -105,4 +107,51 @@ void SplitStringUsingSubstr(const std::string& str,
SplitStringUsingSubstrT(str, s, r);
}
+template<typename STR>
+static void SplitStringT(const STR& str,
+ const typename STR::value_type s,
+ 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) {
+ 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 {
+ r->push_back(tmp);
+ }
+ last = i + 1;
+ }
+ }
+}
+
+void SplitStringDontTrim(const std::wstring& str,
+ wchar_t c,
+ std::vector<std::wstring>* r) {
+ SplitStringT(str, c, false, r);
+}
+
+#if !defined(WCHAR_T_IS_UTF16)
+void SplitStringDontTrim(const string16& str,
+ char16 c,
+ std::vector<string16>* r) {
+ DCHECK(CBU16_IS_SINGLE(c));
+ SplitStringT(str, c, false, r);
+}
+#endif
+
+void SplitStringDontTrim(const std::string& str,
+ char c,
+ std::vector<std::string>* r) {
+ DCHECK(IsStringUTF8(str));
+ DCHECK(c < 0x7F);
+ SplitStringT(str, c, false, r);
+}
+
} // namespace base
diff --git a/base/string_split.h b/base/string_split.h
index 4ded704..d47337c 100644
--- a/base/string_split.h
+++ b/base/string_split.h
@@ -33,6 +33,25 @@ void SplitStringUsingSubstr(const std::string& str,
const std::string& s,
std::vector<std::string>* r);
+// The same as SplitString, but don't trim white space.
+// Where wchar_t is char16 (i.e. Windows), |c| must be in BMP
+// (Basic Multilingual Plane). Elsewhere (Linux/Mac), wchar_t
+// should be a valid Unicode code point (32-bit).
+void SplitStringDontTrim(const std::wstring& str,
+ wchar_t c,
+ std::vector<std::wstring>* r);
+// NOTE: |c| must be in BMP (Basic Multilingual Plane)
+void SplitStringDontTrim(const string16& str,
+ char16 c,
+ std::vector<string16>* r);
+// |str| should not be in a multi-byte encoding like Shift-JIS or GBK in which
+// the trailing byte of a multi-byte character can be in the ASCII range.
+// UTF-8, and other single/multi-byte ASCII-compatible encodings are OK.
+// Note: |c| must be in the ASCII range.
+void SplitStringDontTrim(const std::string& str,
+ char c,
+ std::vector<std::string>* r);
+
} // namespace base
#endif // BASE_STRING_SPLIT_H
diff --git a/base/string_split_unittest.cc b/base/string_split_unittest.cc
index f696480b..f3a929d 100644
--- a/base/string_split_unittest.cc
+++ b/base/string_split_unittest.cc
@@ -177,4 +177,22 @@ TEST(SplitStringUsingSubstrTest, TrailingDelimitersSkipped) {
results, ElementsAre("un", "deux", "trois", "quatre", "", "", ""));
}
+TEST(StringSplitTest, StringSplitDontTrim) {
+ std::vector<std::wstring> r;
+
+ SplitStringDontTrim(L"\t\ta\t", L'\t', &r);
+ ASSERT_EQ(4U, r.size());
+ EXPECT_EQ(r[0], L"");
+ EXPECT_EQ(r[1], L"");
+ EXPECT_EQ(r[2], L"a");
+ EXPECT_EQ(r[3], L"");
+ r.clear();
+
+ SplitStringDontTrim(L"\ta\t\nb\tcc", L'\n', &r);
+ ASSERT_EQ(2U, r.size());
+ EXPECT_EQ(r[0], L"\ta\t");
+ EXPECT_EQ(r[1], L"b\tcc");
+ r.clear();
+}
+
} // namespace base
diff --git a/base/string_util.cc b/base/string_util.cc
index 68f3d91..ba9108b 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -757,6 +757,8 @@ void ReplaceSubstringsAfterOffset(std::string* str,
true); // replace all instances
}
+// TODO(tfarina): Remove this when finish moving SplitString functions to
+// string_split.[cc/h].
template<typename STR>
static void SplitStringT(const STR& str,
const typename STR::value_type s,
@@ -801,26 +803,6 @@ void SplitString(const std::string& str,
SplitStringT(str, s, true, r);
}
-void SplitStringDontTrim(const std::wstring& str,
- wchar_t s,
- std::vector<std::wstring>* r) {
- SplitStringT(str, s, false, r);
-}
-
-#if !defined(WCHAR_T_IS_UTF16)
-void SplitStringDontTrim(const string16& str,
- char16 s,
- std::vector<string16>* r) {
- SplitStringT(str, s, false, r);
-}
-#endif
-
-void SplitStringDontTrim(const std::string& str,
- char s,
- std::vector<std::string>* r) {
- SplitStringT(str, s, false, r);
-}
-
template<typename STR>
static size_t TokenizeT(const STR& str,
const STR& delimiters,
diff --git a/base/string_util.h b/base/string_util.h
index a0067d3..b1cb828 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -523,17 +523,6 @@ void SplitString(const std::string& str,
char s,
std::vector<std::string>* r);
-// The same as SplitString, but don't trim white space.
-void SplitStringDontTrim(const std::wstring& str,
- wchar_t s,
- std::vector<std::wstring>* r);
-void SplitStringDontTrim(const string16& str,
- char16 s,
- std::vector<string16>* r);
-void SplitStringDontTrim(const std::string& str,
- char s,
- std::vector<std::string>* r);
-
// Splits a string into its fields delimited by any of the characters in
// |delimiters|. Each field is added to the |tokens| vector. Returns the
// number of tokens found.
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc
index 23b1f53..c4fd5ae 100644
--- a/base/string_util_unittest.cc
+++ b/base/string_util_unittest.cc
@@ -762,25 +762,11 @@ TEST(StringUtilTest, SplitString) {
EXPECT_EQ(r[3], L"");
r.clear();
- SplitStringDontTrim(L"\t\ta\t", L'\t', &r);
- ASSERT_EQ(4U, r.size());
- EXPECT_EQ(r[0], L"");
- EXPECT_EQ(r[1], L"");
- EXPECT_EQ(r[2], L"a");
- EXPECT_EQ(r[3], L"");
- r.clear();
-
SplitString(L"\ta\t\nb\tcc", L'\n', &r);
ASSERT_EQ(2U, r.size());
EXPECT_EQ(r[0], L"a");
EXPECT_EQ(r[1], L"b\tcc");
r.clear();
-
- SplitStringDontTrim(L"\ta\t\nb\tcc", L'\n', &r);
- ASSERT_EQ(2U, r.size());
- EXPECT_EQ(r[0], L"\ta\t");
- EXPECT_EQ(r[1], L"b\tcc");
- r.clear();
}
// Test for Tokenize
diff --git a/chrome/plugin/chrome_plugin_host.cc b/chrome/plugin/chrome_plugin_host.cc
index 74fd341..a3f66d4 100644
--- a/chrome/plugin/chrome_plugin_host.cc
+++ b/chrome/plugin/chrome_plugin_host.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -9,6 +9,7 @@
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/process_util.h"
+#include "base/string_split.h"
#include "chrome/common/child_process.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_plugin_lib.h"
@@ -383,7 +384,7 @@ CPError STDCALL CPB_AllowFileDrop(
static const char kDelimiter('\b');
std::vector<std::string> files;
- SplitStringDontTrim(file_drag_data, kDelimiter, &files);
+ base::SplitStringDontTrim(file_drag_data, kDelimiter, &files);
bool allowed = false;
if (!PluginThread::current()->Send(
diff --git a/chrome/renderer/extensions/bindings_utils.cc b/chrome/renderer/extensions/bindings_utils.cc
index d3fdb28..2ddbefa 100644
--- a/chrome/renderer/extensions/bindings_utils.cc
+++ b/chrome/renderer/extensions/bindings_utils.cc
@@ -1,9 +1,10 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
#include "chrome/renderer/extensions/bindings_utils.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "chrome/renderer/render_view.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
@@ -127,7 +128,7 @@ v8::Handle<v8::Value> CallFunctionInContext(v8::Handle<v8::Context> context,
v8::Local<v8::Value> value =
context->Global()->GetHiddenValue(v8::String::New(kChromeHidden));
std::vector<std::string> components;
- SplitStringDontTrim(function_name, '.', &components);
+ base::SplitStringDontTrim(function_name, '.', &components);
for (size_t i = 0; i < components.size(); ++i) {
if (!value.IsEmpty() && value->IsObject())
value = value->ToObject()->Get(v8::String::New(components[i].c_str()));
diff --git a/chrome/renderer/safe_browsing/phishing_url_feature_extractor.cc b/chrome/renderer/safe_browsing/phishing_url_feature_extractor.cc
index 7937cea..4686a41 100644
--- a/chrome/renderer/safe_browsing/phishing_url_feature_extractor.cc
+++ b/chrome/renderer/safe_browsing/phishing_url_feature_extractor.cc
@@ -7,9 +7,11 @@
#include <algorithm>
#include <string>
#include <vector>
+
#include "base/histogram.h"
#include "base/logging.h"
#include "base/perftimer.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "googleurl/src/gurl.h"
@@ -54,7 +56,7 @@ bool PhishingUrlFeatureExtractor::ExtractFeatures(const GURL& url,
// Pull off the TLD and the preceeding dot.
host.erase(tld_start - 1);
std::vector<std::string> host_tokens;
- SplitStringDontTrim(host, '.', &host_tokens);
+ base::SplitStringDontTrim(host, '.', &host_tokens);
// Get rid of any empty components.
std::vector<std::string>::iterator new_end =
std::remove(host_tokens.begin(), host_tokens.end(), "");
diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
index 993605f..4505a7d 100644
--- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc
+++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/md5.h"
#include "base/rand_util.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
@@ -630,7 +631,7 @@ void CloudPrintProxyBackend::Core::InitJobHandlerForPrinter(
tags_list->GetString(index, &tag);
if (StartsWithASCII(tag, kTagsHashTagName, false)) {
std::vector<std::string> tag_parts;
- SplitStringDontTrim(tag, '=', &tag_parts);
+ base::SplitStringDontTrim(tag, '=', &tag_parts);
DCHECK(tag_parts.size() == 2);
if (tag_parts.size() == 2) {
printer_info_cloud.tags_hash = tag_parts[1];
diff --git a/net/websockets/websocket_handshake_unittest.cc b/net/websockets/websocket_handshake_unittest.cc
index f688554..e392cfc 100644
--- a/net/websockets/websocket_handshake_unittest.cc
+++ b/net/websockets/websocket_handshake_unittest.cc
@@ -6,6 +6,7 @@
#include <vector>
#include "base/scoped_ptr.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "net/websockets/websocket_handshake.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -140,7 +141,7 @@ TEST_F(WebSocketHandshakeTest, Connect) {
"\r\n"
"\x30\x73\x74\x33\x52\x6C\x26\x71\x2D\x32\x5A\x55\x5E\x77\x65\x75";
std::vector<std::string> response_lines;
- SplitStringDontTrim(kResponse, '\n', &response_lines);
+ base::SplitStringDontTrim(kResponse, '\n', &response_lines);
EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
// too short
diff --git a/net/websockets/websocket_net_log_params.h b/net/websockets/websocket_net_log_params.h
index 780cb3b..b11cefd 100644
--- a/net/websockets/websocket_net_log_params.h
+++ b/net/websockets/websocket_net_log_params.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/ref_counted.h"
+#include "base/string_split.h"
#include "base/string_util.h"
#include "base/values.h"
#include "net/base/net_log.h"
@@ -27,7 +28,7 @@ class NetLogWebSocketHandshakeParameter : public NetLog::EventParameters {
DictionaryValue* dict = new DictionaryValue();
ListValue* headers = new ListValue();
std::vector<std::string> lines;
- SplitStringDontTrim(headers_, '\n', &lines);
+ base::SplitStringDontTrim(headers_, '\n', &lines);
for (size_t i = 0; i < lines.size(); ++i) {
if (lines[i] == "\r") {
headers->Append(new StringValue(""));
diff --git a/webkit/glue/dom_operations.cc b/webkit/glue/dom_operations.cc
index 724e200..f9868b2 100644
--- a/webkit/glue/dom_operations.cc
+++ b/webkit/glue/dom_operations.cc
@@ -8,6 +8,7 @@
#include "base/compiler_specific.h"
#include "base/string_number_conversions.h"
+#include "base/string_split.h"
#include "third_party/WebKit/WebKit/chromium/public/WebAnimationController.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
@@ -416,7 +417,7 @@ static int ParseSingleIconSize(const string16& text) {
// If the input couldn't be parsed, a size with a width/height < 0 is returned.
static gfx::Size ParseIconSize(const string16& text) {
std::vector<string16> sizes;
- SplitStringDontTrim(text, L'x', &sizes);
+ base::SplitStringDontTrim(text, L'x', &sizes);
if (sizes.size() != 2)
return gfx::Size();