diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-10 19:06:21 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-10 19:06:21 +0000 |
commit | 52fcf3c789f31c2538fc94240d269f0e56ff6087 (patch) | |
tree | 7debd5844f9edda7fa456824d100714006293cad /app/l10n_util.cc | |
parent | a08e94a424db1cecf68845f5052fc9924ccc3b6a (diff) | |
download | chromium_src-52fcf3c789f31c2538fc94240d269f0e56ff6087.zip chromium_src-52fcf3c789f31c2538fc94240d269f0e56ff6087.tar.gz chromium_src-52fcf3c789f31c2538fc94240d269f0e56ff6087.tar.bz2 |
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
Diffstat (limited to 'app/l10n_util.cc')
-rw-r--r-- | app/l10n_util.cc | 21 |
1 files changed, 8 insertions, 13 deletions
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<icu::RuleBasedBreakIterator> 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<int32_t>(max)); if (index == icu::BreakIterator::DONE) { index = static_cast<int32_t>(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. |