| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
| 6 | 6 |
| 7 #if defined(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
| 8 #include <glib/gutils.h> | 8 #include <glib/gutils.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
| 42 static const FilePath::CharType kLocaleFileExtension[] = L".dll"; | 42 static const FilePath::CharType kLocaleFileExtension[] = L".dll"; |
| 43 #elif defined(OS_POSIX) | 43 #elif defined(OS_POSIX) |
| 44 static const FilePath::CharType kLocaleFileExtension[] = ".pak"; | 44 static const FilePath::CharType kLocaleFileExtension[] = ".pak"; |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 // Added to the end of strings that are too big in TrucateString. | |
| 48 static const wchar_t* const kElideString = L"\x2026"; | |
| 49 | |
| 50 static const char* const kAcceptLanguageList[] = { | 47 static const char* const kAcceptLanguageList[] = { |
| 51 "af", // Afrikaans | 48 "af", // Afrikaans |
| 52 "am", // Amharic | 49 "am", // Amharic |
| 53 "ar", // Arabic | 50 "ar", // Arabic |
| 54 "az", // Azerbaijani | 51 "az", // Azerbaijani |
| 55 "be", // Belarusian | 52 "be", // Belarusian |
| 56 "bg", // Bulgarian | 53 "bg", // Bulgarian |
| 57 "bh", // Bihari | 54 "bh", // Bihari |
| 58 "bn", // Bengali | 55 "bn", // Bengali |
| 59 "br", // Breton | 56 "br", // Breton |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 } | 671 } |
| 675 | 672 |
| 676 std::wstring GetStringF(int message_id, int a) { | 673 std::wstring GetStringF(int message_id, int a) { |
| 677 return GetStringF(message_id, UTF8ToWide(base::IntToString(a))); | 674 return GetStringF(message_id, UTF8ToWide(base::IntToString(a))); |
| 678 } | 675 } |
| 679 | 676 |
| 680 std::wstring GetStringF(int message_id, int64 a) { | 677 std::wstring GetStringF(int message_id, int64 a) { |
| 681 return GetStringF(message_id, UTF8ToWide(base::Int64ToString(a))); | 678 return GetStringF(message_id, UTF8ToWide(base::Int64ToString(a))); |
| 682 } | 679 } |
| 683 | 680 |
| 684 std::wstring TruncateString(const std::wstring& string, size_t length) { | 681 string16 TruncateString(const string16& string, size_t length) { |
| 685 if (string.size() <= length) | 682 if (string.size() <= length) |
| 686 // String fits, return it. | 683 // String fits, return it. |
| 687 return string; | 684 return string; |
| 688 | 685 |
| 689 if (length == 0) { | 686 if (length == 0) { |
| 690 // No room for the ellide string, return an empty string. | 687 // No room for the elide string, return an empty string. |
| 691 return std::wstring(L""); | 688 return string16(); |
| 692 } | 689 } |
| 693 size_t max = length - 1; | 690 size_t max = length - 1; |
| 694 | 691 |
| 692 // Added to the end of strings that are too big. |
| 693 static const char16 kElideString[] = { 0x2026, 0 }; |
| 694 |
| 695 if (max == 0) { | 695 if (max == 0) { |
| 696 // Just enough room for the elide string. | 696 // Just enough room for the elide string. |
| 697 return kElideString; | 697 return kElideString; |
| 698 } | 698 } |
| 699 | 699 |
| 700 #if defined(WCHAR_T_IS_UTF32) | |
| 701 const string16 string_utf16 = WideToUTF16(string); | |
| 702 #else | |
| 703 const std::wstring &string_utf16 = string; | |
| 704 #endif | |
| 705 // Use a line iterator to find the first boundary. | 700 // Use a line iterator to find the first boundary. |
| 706 UErrorCode status = U_ZERO_ERROR; | 701 UErrorCode status = U_ZERO_ERROR; |
| 707 scoped_ptr<icu::RuleBasedBreakIterator> bi( | 702 scoped_ptr<icu::RuleBasedBreakIterator> bi( |
| 708 static_cast<icu::RuleBasedBreakIterator*>( | 703 static_cast<icu::RuleBasedBreakIterator*>( |
| 709 icu::RuleBasedBreakIterator::createLineInstance( | 704 icu::RuleBasedBreakIterator::createLineInstance( |
| 710 icu::Locale::getDefault(), status))); | 705 icu::Locale::getDefault(), status))); |
| 711 if (U_FAILURE(status)) | 706 if (U_FAILURE(status)) |
| 712 return string.substr(0, max) + kElideString; | 707 return string.substr(0, max) + kElideString; |
| 713 bi->setText(string_utf16.c_str()); | 708 bi->setText(string.c_str()); |
| 714 int32_t index = bi->preceding(static_cast<int32_t>(max)); | 709 int32_t index = bi->preceding(static_cast<int32_t>(max)); |
| 715 if (index == icu::BreakIterator::DONE) { | 710 if (index == icu::BreakIterator::DONE) { |
| 716 index = static_cast<int32_t>(max); | 711 index = static_cast<int32_t>(max); |
| 717 } else { | 712 } else { |
| 718 // Found a valid break (may be the beginning of the string). Now use | 713 // Found a valid break (may be the beginning of the string). Now use |
| 719 // a character iterator to find the previous non-whitespace character. | 714 // a character iterator to find the previous non-whitespace character. |
| 720 icu::StringCharacterIterator char_iterator(string_utf16.c_str()); | 715 icu::StringCharacterIterator char_iterator(string.c_str()); |
| 721 if (index == 0) { | 716 if (index == 0) { |
| 722 // No valid line breaks. Start at the end again. This ensures we break | 717 // No valid line breaks. Start at the end again. This ensures we break |
| 723 // on a valid character boundary. | 718 // on a valid character boundary. |
| 724 index = static_cast<int32_t>(max); | 719 index = static_cast<int32_t>(max); |
| 725 } | 720 } |
| 726 char_iterator.setIndex(index); | 721 char_iterator.setIndex(index); |
| 727 while (char_iterator.hasPrevious()) { | 722 while (char_iterator.hasPrevious()) { |
| 728 char_iterator.previous(); | 723 char_iterator.previous(); |
| 729 if (!(u_isspace(char_iterator.current()) || | 724 if (!(u_isspace(char_iterator.current()) || |
| 730 u_charType(char_iterator.current()) == U_CONTROL_CHAR || | 725 u_charType(char_iterator.current()) == U_CONTROL_CHAR || |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 867 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { |
| 873 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) | 868 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) |
| 874 // TODO(jungshik) : Put them at the of the list with language codes | 869 // TODO(jungshik) : Put them at the of the list with language codes |
| 875 // enclosed by brackets instead of skipping. | 870 // enclosed by brackets instead of skipping. |
| 876 continue; | 871 continue; |
| 877 locale_codes->push_back(kAcceptLanguageList[i]); | 872 locale_codes->push_back(kAcceptLanguageList[i]); |
| 878 } | 873 } |
| 879 } | 874 } |
| 880 | 875 |
| 881 } // namespace l10n_util | 876 } // namespace l10n_util |
| OLD | NEW |