summaryrefslogtreecommitdiffstats
path: root/base/string_util.cc
diff options
context:
space:
mode:
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());