From 52fcf3c789f31c2538fc94240d269f0e56ff6087 Mon Sep 17 00:00:00 2001 From: "evan@chromium.org" Date: Fri, 10 Dec 2010 19:06:21 +0000 Subject: wstrings: make l10n_util::TruncateString use string16 BUG=23581 Review URL: http://codereview.chromium.org/5742006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68875 0039d316-1c4b-4281-b951-d872f2087c98 --- app/l10n_util.cc | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'app/l10n_util.cc') diff --git a/app/l10n_util.cc b/app/l10n_util.cc index a77af25..148151d 100644 --- a/app/l10n_util.cc +++ b/app/l10n_util.cc @@ -44,9 +44,6 @@ static const FilePath::CharType kLocaleFileExtension[] = L".dll"; static const FilePath::CharType kLocaleFileExtension[] = ".pak"; #endif -// Added to the end of strings that are too big in TrucateString. -static const wchar_t* const kElideString = L"\x2026"; - static const char* const kAcceptLanguageList[] = { "af", // Afrikaans "am", // Amharic @@ -681,27 +678,25 @@ std::wstring GetStringF(int message_id, int64 a) { return GetStringF(message_id, UTF8ToWide(base::Int64ToString(a))); } -std::wstring TruncateString(const std::wstring& string, size_t length) { +string16 TruncateString(const string16& string, size_t length) { if (string.size() <= length) // String fits, return it. return string; if (length == 0) { - // No room for the ellide string, return an empty string. - return std::wstring(L""); + // No room for the elide string, return an empty string. + return string16(); } size_t max = length - 1; + // Added to the end of strings that are too big. + static const char16 kElideString[] = { 0x2026, 0 }; + if (max == 0) { // Just enough room for the elide string. return kElideString; } -#if defined(WCHAR_T_IS_UTF32) - const string16 string_utf16 = WideToUTF16(string); -#else - const std::wstring &string_utf16 = string; -#endif // Use a line iterator to find the first boundary. UErrorCode status = U_ZERO_ERROR; scoped_ptr bi( @@ -710,14 +705,14 @@ std::wstring TruncateString(const std::wstring& string, size_t length) { icu::Locale::getDefault(), status))); if (U_FAILURE(status)) return string.substr(0, max) + kElideString; - bi->setText(string_utf16.c_str()); + bi->setText(string.c_str()); int32_t index = bi->preceding(static_cast(max)); if (index == icu::BreakIterator::DONE) { index = static_cast(max); } else { // Found a valid break (may be the beginning of the string). Now use // a character iterator to find the previous non-whitespace character. - icu::StringCharacterIterator char_iterator(string_utf16.c_str()); + icu::StringCharacterIterator char_iterator(string.c_str()); if (index == 0) { // No valid line breaks. Start at the end again. This ensures we break // on a valid character boundary. -- cgit v1.1