summaryrefslogtreecommitdiffstats
path: root/base/string_util.cc
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 23:10:39 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 23:10:39 +0000
commit46878fb99cebcc06936428a4cf04586734856fe0 (patch)
tree60d0107ef6b2b1d4074037fe4e865c8a201d9af0 /base/string_util.cc
parent8b6c1e3833d5030da152ef816ba0f6673082c25a (diff)
downloadchromium_src-46878fb99cebcc06936428a4cf04586734856fe0.zip
chromium_src-46878fb99cebcc06936428a4cf04586734856fe0.tar.gz
chromium_src-46878fb99cebcc06936428a4cf04586734856fe0.tar.bz2
add CollapseWhitespaceASCII
R=erikkay Review URL: http://codereview.chromium.org/119199 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util.cc')
-rw-r--r--base/string_util.cc19
1 files changed, 15 insertions, 4 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index 1cdbd7b..2998d2b 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -420,9 +420,10 @@ TrimPositions TrimWhitespace(const std::string& input,
return TrimWhitespaceASCII(input, positions, output);
}
-std::wstring CollapseWhitespace(const std::wstring& text,
- bool trim_sequences_with_line_breaks) {
- std::wstring result;
+template<typename STR>
+STR CollapseWhitespaceT(const STR& text,
+ bool trim_sequences_with_line_breaks) {
+ STR result;
result.resize(text.size());
// Set flags to pretend we're already in a trimmed whitespace sequence, so we
@@ -431,7 +432,7 @@ std::wstring CollapseWhitespace(const std::wstring& text,
bool already_trimmed = true;
int chars_written = 0;
- for (std::wstring::const_iterator i(text.begin()); i != text.end(); ++i) {
+ for (typename STR::const_iterator i(text.begin()); i != text.end(); ++i) {
if (IsWhitespace(*i)) {
if (!in_whitespace) {
// Reduce all whitespace sequences to a single space.
@@ -461,6 +462,16 @@ std::wstring CollapseWhitespace(const std::wstring& text,
return result;
}
+std::wstring CollapseWhitespace(const std::wstring& text,
+ bool trim_sequences_with_line_breaks) {
+ return CollapseWhitespaceT(text, trim_sequences_with_line_breaks);
+}
+
+std::string CollapseWhitespaceASCII(const std::string& text,
+ bool trim_sequences_with_line_breaks) {
+ return CollapseWhitespaceT(text, trim_sequences_with_line_breaks);
+}
+
std::string WideToASCII(const std::wstring& wide) {
DCHECK(IsStringASCII(wide));
return std::string(wide.begin(), wide.end());