Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3016)

Unified Diff: base/string_util.cc

Issue 119199: add CollapseWhitespaceASCII (Closed)
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/string_util.h ('k') | base/string_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_util.cc
diff --git a/base/string_util.cc b/base/string_util.cc
index 1cdbd7b7507a86dc5e26f8848bffcfe04537cd56..5812ceca40ddb12a4cf0421f499995eeafe64d6c 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 (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());
« no previous file with comments | « base/string_util.h ('k') | base/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698