diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-24 04:52:11 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-24 04:52:11 +0000 |
commit | 4e5ae20ff403cdcd14d3b86b18a0d0bcec2f47cc (patch) | |
tree | e224d7b5d871995421ac845db1c9406393b66f67 /base/string_split.cc | |
parent | 915a3abe017a65e6f3bcc76d2968df476efc4a6e (diff) | |
download | chromium_src-4e5ae20ff403cdcd14d3b86b18a0d0bcec2f47cc.zip chromium_src-4e5ae20ff403cdcd14d3b86b18a0d0bcec2f47cc.tar.gz chromium_src-4e5ae20ff403cdcd14d3b86b18a0d0bcec2f47cc.tar.bz2 |
base: Finish moving the SplitString functions from string_util.h to string_split.h
BUG=None
TEST=trybos
Review URL: http://codereview.chromium.org/3447008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60422 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_split.cc')
-rw-r--r-- | base/string_split.cc | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/base/string_split.cc b/base/string_split.cc index 646b4de..ca97954 100644 --- a/base/string_split.cc +++ b/base/string_split.cc @@ -9,6 +9,52 @@ #include "base/third_party/icu/icu_utf.h" #include "base/utf_string_conversions.h" +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 SplitString(const std::wstring& str, + wchar_t c, + std::vector<std::wstring>* r) { + SplitStringT(str, c, true, r); +} + +#if !defined(WCHAR_T_IS_UTF16) +void SplitString(const string16& str, + char16 c, + std::vector<string16>* r) { + DCHECK(CBU16_IS_SINGLE(c)); + SplitStringT(str, c, true, r); +} +#endif + +void SplitString(const std::string& str, + char c, + std::vector<std::string>* r) { + DCHECK(c >= 0 && c < 0x7F); + SplitStringT(str, c, true, r); +} + namespace base { bool SplitStringIntoKeyValues( @@ -107,30 +153,6 @@ 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) { @@ -150,7 +172,7 @@ void SplitStringDontTrim(const std::string& str, char c, std::vector<std::string>* r) { DCHECK(IsStringUTF8(str)); - DCHECK(c < 0x7F); + DCHECK(c >= 0 && c < 0x7F); SplitStringT(str, c, false, r); } |