diff options
-rw-r--r-- | base/string_util.cc | 8 | ||||
-rw-r--r-- | base/string_util.h | 3 | ||||
-rw-r--r-- | base/string_util_unittest.cc | 17 | ||||
-rw-r--r-- | chrome/browser/net/url_fixer_upper.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/views/download/download_item_view.cc | 17 |
5 files changed, 22 insertions, 33 deletions
diff --git a/base/string_util.cc b/base/string_util.cc index 1ad9abe..4a191b4 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -292,19 +292,11 @@ void TruncateUTF8ToByteSize(const std::string& input, output->clear(); } -TrimPositions TrimWhitespace(const std::wstring& input, - TrimPositions positions, - std::wstring* output) { - return TrimStringT(input, kWhitespaceWide, positions, output); -} - -#if !defined(WCHAR_T_IS_UTF16) TrimPositions TrimWhitespace(const string16& input, TrimPositions positions, string16* output) { return TrimStringT(input, kWhitespaceUTF16, positions, output); } -#endif TrimPositions TrimWhitespaceASCII(const std::string& input, TrimPositions positions, diff --git a/base/string_util.h b/base/string_util.h index 9864137..0b52ac0 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -221,9 +221,6 @@ enum TrimPositions { TRIM_TRAILING = 1 << 1, TRIM_ALL = TRIM_LEADING | TRIM_TRAILING, }; -BASE_API TrimPositions TrimWhitespace(const std::wstring& input, - TrimPositions positions, - std::wstring* output); BASE_API TrimPositions TrimWhitespace(const string16& input, TrimPositions positions, string16* output); diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index cd45642..3731d4c 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -225,23 +225,24 @@ TEST(StringUtilTest, TruncateUTF8ToByteSize) { } TEST(StringUtilTest, TrimWhitespace) { - std::wstring output; // Allow contents to carry over to next testcase + string16 output; // Allow contents to carry over to next testcase for (size_t i = 0; i < arraysize(trim_cases); ++i) { const trim_case& value = trim_cases[i]; EXPECT_EQ(value.return_value, - TrimWhitespace(value.input, value.positions, &output)); - EXPECT_EQ(value.output, output); + TrimWhitespace(WideToUTF16(value.input), value.positions, + &output)); + EXPECT_EQ(WideToUTF16(value.output), output); } // Test that TrimWhitespace() can take the same string for input and output - output = L" This is a test \r\n"; + output = ASCIIToUTF16(" This is a test \r\n"); EXPECT_EQ(TRIM_ALL, TrimWhitespace(output, TRIM_ALL, &output)); - EXPECT_EQ(L"This is a test", output); + EXPECT_EQ(ASCIIToUTF16("This is a test"), output); // Once more, but with a string of whitespace - output = L" \r\n"; + output = ASCIIToUTF16(" \r\n"); EXPECT_EQ(TRIM_ALL, TrimWhitespace(output, TRIM_ALL, &output)); - EXPECT_EQ(L"", output); + EXPECT_EQ(ASCIIToUTF16(""), output); std::string output_ascii; for (size_t i = 0; i < arraysize(trim_cases_ascii); ++i) { diff --git a/chrome/browser/net/url_fixer_upper.cc b/chrome/browser/net/url_fixer_upper.cc index 9111d8a..10d930b 100644 --- a/chrome/browser/net/url_fixer_upper.cc +++ b/chrome/browser/net/url_fixer_upper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -80,10 +80,10 @@ TrimPositions TrimWhitespaceUTF8(const std::string& input, // twice. Please feel free to file a bug if this function hurts the // performance of Chrome. DCHECK(IsStringUTF8(input)); - std::wstring input_wide = UTF8ToWide(input); - std::wstring output_wide; - TrimPositions result = TrimWhitespace(input_wide, positions, &output_wide); - *output = WideToUTF8(output_wide); + string16 input16 = UTF8ToUTF16(input); + string16 output16; + TrimPositions result = TrimWhitespace(input16, positions, &output16); + *output = UTF16ToUTF8(output16); return result; } diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc index 36fc0e1..b33048c 100644 --- a/chrome/browser/ui/views/download/download_item_view.cc +++ b/chrome/browser/ui/views/download/download_item_view.cc @@ -1065,9 +1065,9 @@ void DownloadItemView::SizeLabelToMinWidth() { if (dangerous_download_label_sized_) return; - std::wstring text = dangerous_download_label_->GetText(); + string16 text = WideToUTF16(dangerous_download_label_->GetText()); TrimWhitespace(text, TRIM_ALL, &text); - DCHECK_EQ(std::wstring::npos, text.find(L"\n")); + DCHECK_EQ(string16::npos, text.find('\n')); // Make the label big so that GetPreferredSize() is not constrained by the // current width. @@ -1075,24 +1075,23 @@ void DownloadItemView::SizeLabelToMinWidth() { gfx::Size size; int min_width = -1; - string16 text16 = WideToUTF16(text); // Using BREAK_WORD can work in most cases, but it can also break // lines where it should not. Using BREAK_LINE is safer although // slower for Chinese/Japanese. This is not perf-critical at all, though. - base::BreakIterator iter(&text16, base::BreakIterator::BREAK_LINE); + base::BreakIterator iter(&text, base::BreakIterator::BREAK_LINE); bool status = iter.Init(); DCHECK(status); - string16 current_text = text16; - string16 prev_text = text16; + string16 current_text = text; + string16 prev_text = text; while (iter.Advance()) { size_t pos = iter.pos(); - if (pos >= text16.length()) + if (pos >= text.length()) break; // This can be a low surrogate codepoint, but u_isUWhiteSpace will // return false and inserting a new line after a surrogate pair // is perfectly ok. - char16 line_end_char = text16[pos - 1]; + char16 line_end_char = text[pos - 1]; if (u_isUWhiteSpace(line_end_char)) current_text.replace(pos - 1, 1, 1, char16('\n')); else @@ -1113,7 +1112,7 @@ void DownloadItemView::SizeLabelToMinWidth() { // Restore the string. prev_text = current_text; - current_text = text16; + current_text = text; } // If we have a line with no line breaking opportunity (which is very |