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

Side by Side Diff: chrome/common/l10n_util.cc

Issue 20484: Adds a method to sort the elements of a vector by invoking a method on... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/l10n_util.h ('k') | chrome/common/l10n_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/common/l10n_util.h" 7 #include "chrome/common/l10n_util.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/string_piece.h" 15 #include "base/string_piece.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/sys_string_conversions.h" 17 #include "base/sys_string_conversions.h"
18 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/gfx/chrome_canvas.h" 20 #include "chrome/common/gfx/chrome_canvas.h"
21 #if defined(OS_WIN) || defined(OS_LINUX) 21 #if defined(OS_WIN) || defined(OS_LINUX)
22 // TODO(port): re-enable. 22 // TODO(port): re-enable.
23 #include "chrome/common/resource_bundle.h" 23 #include "chrome/common/resource_bundle.h"
24 #endif 24 #endif
25 #if defined(OS_WIN) 25 #if defined(OS_WIN)
26 #include "chrome/views/view.h" 26 #include "chrome/views/view.h"
27 #endif // defined(OS_WIN) 27 #endif // defined(OS_WIN)
28 #include "unicode/rbbi.h"
29 #include "unicode/uchar.h"
30 28
31 // TODO(playmobil): remove this undef once SkPostConfig.h is fixed. 29 // TODO(playmobil): remove this undef once SkPostConfig.h is fixed.
32 // skia/include/corecg/SkPostConfig.h #defines strcasecmp() so we can't use 30 // skia/include/corecg/SkPostConfig.h #defines strcasecmp() so we can't use
33 // base::strcasecmp() without #undefing it here. 31 // base::strcasecmp() without #undefing it here.
34 #undef strcasecmp 32 #undef strcasecmp
35 33
36 namespace { 34 namespace {
37 35
38 // Added to the end of strings that are too big in TrucateString. 36 // Added to the end of strings that are too big in TrucateString.
39 static const wchar_t* const kElideString = L"\x2026"; 37 static const wchar_t* const kElideString = L"\x2026";
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 std::string ret; 201 std::string ret;
204 if (!language.empty()) 202 if (!language.empty())
205 ret.append(language); 203 ret.append(language);
206 if (!region.empty()) { 204 if (!region.empty()) {
207 ret.append("-"); 205 ret.append("-");
208 ret.append(region); 206 ret.append(region);
209 } 207 }
210 return ASCIIToWide(ret); 208 return ASCIIToWide(ret);
211 } 209 }
212 210
213 // Compares the character data stored in two different strings by specified
214 // Collator instance.
215 UCollationResult CompareStringWithCollator(const Collator* collator,
216 const std::wstring& lhs,
217 const std::wstring& rhs) {
218 DCHECK(collator);
219 UErrorCode error = U_ZERO_ERROR;
220 #if defined(WCHAR_T_IS_UTF32)
221 // Need to convert to UTF-16 to be compatible with UnicodeString's
222 // constructor.
223 string16 lhs_utf16 = WideToUTF16(lhs);
224 string16 rhs_utf16 = WideToUTF16(rhs);
225
226 UCollationResult result = collator->compare(
227 static_cast<const UChar*>(lhs_utf16.c_str()),
228 static_cast<int>(lhs_utf16.length()),
229 static_cast<const UChar*>(rhs_utf16.c_str()),
230 static_cast<int>(rhs_utf16.length()),
231 error);
232 #else
233 UCollationResult result = collator->compare(
234 static_cast<const UChar*>(lhs.c_str()), static_cast<int>(lhs.length()),
235 static_cast<const UChar*>(rhs.c_str()), static_cast<int>(rhs.length()),
236 error);
237 #endif
238 DCHECK(U_SUCCESS(error));
239 return result;
240 }
241
242 } // namespace 211 } // namespace
243 212
244 namespace l10n_util { 213 namespace l10n_util {
245 214
246 // Represents the locale-specific text direction. 215 // Represents the locale-specific text direction.
247 static TextDirection g_text_direction = UNKNOWN_DIRECTION; 216 static TextDirection g_text_direction = UNKNOWN_DIRECTION;
248 217
249 std::wstring GetApplicationLocale(const std::wstring& pref_locale) { 218 std::wstring GetApplicationLocale(const std::wstring& pref_locale) {
250 std::wstring locale_path; 219 std::wstring locale_path;
251 PathService::Get(chrome::DIR_LOCALES, &locale_path); 220 PathService::Get(chrome::DIR_LOCALES, &locale_path);
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style); 633 ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
665 634
666 // Right-to-left layout changes are not applied to the window immediately 635 // Right-to-left layout changes are not applied to the window immediately
667 // so we should make sure a WM_PAINT is sent to the window by invalidating 636 // so we should make sure a WM_PAINT is sent to the window by invalidating
668 // the entire window rect. 637 // the entire window rect.
669 ::InvalidateRect(hwnd, NULL, true); 638 ::InvalidateRect(hwnd, NULL, true);
670 } 639 }
671 } 640 }
672 #endif // defined(OS_WIN) 641 #endif // defined(OS_WIN)
673 642
643 // Compares the character data stored in two different strings by specified
644 // Collator instance.
645 UCollationResult CompareStringWithCollator(const Collator* collator,
646 const std::wstring& lhs,
647 const std::wstring& rhs) {
648 DCHECK(collator);
649 UErrorCode error = U_ZERO_ERROR;
650 #if defined(WCHAR_T_IS_UTF32)
651 // Need to convert to UTF-16 to be compatible with UnicodeString's
652 // constructor.
653 string16 lhs_utf16 = WideToUTF16(lhs);
654 string16 rhs_utf16 = WideToUTF16(rhs);
655
656 UCollationResult result = collator->compare(
657 static_cast<const UChar*>(lhs_utf16.c_str()),
658 static_cast<int>(lhs_utf16.length()),
659 static_cast<const UChar*>(rhs_utf16.c_str()),
660 static_cast<int>(rhs_utf16.length()),
661 error);
662 #else
663 UCollationResult result = collator->compare(
664 static_cast<const UChar*>(lhs.c_str()), static_cast<int>(lhs.length()),
665 static_cast<const UChar*>(rhs.c_str()), static_cast<int>(rhs.length()),
666 error);
667 #endif
668 DCHECK(U_SUCCESS(error));
669 return result;
670 }
671
674 // Specialization of operator() method for std::wstring version. 672 // Specialization of operator() method for std::wstring version.
675 template <> 673 template <>
676 bool StringComparator<std::wstring>::operator()(const std::wstring& lhs, 674 bool StringComparator<std::wstring>::operator()(const std::wstring& lhs,
677 const std::wstring& rhs) { 675 const std::wstring& rhs) {
678 // If we can not get collator instance for specified locale, just do simple 676 // If we can not get collator instance for specified locale, just do simple
679 // string compare. 677 // string compare.
680 if (!collator_) 678 if (!collator_)
681 return lhs < rhs; 679 return lhs < rhs;
682 return CompareStringWithCollator(collator_, lhs, rhs) == UCOL_LESS; 680 return CompareStringWithCollator(collator_, lhs, rhs) == UCOL_LESS;
683 }; 681 };
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 } 756 }
759 757
760 void BiDiLineIterator::GetLogicalRun(int start, 758 void BiDiLineIterator::GetLogicalRun(int start,
761 int* end, 759 int* end,
762 UBiDiLevel* level) { 760 UBiDiLevel* level) {
763 DCHECK(bidi_ != NULL); 761 DCHECK(bidi_ != NULL);
764 ubidi_getLogicalRun(bidi_, start, end, level); 762 ubidi_getLogicalRun(bidi_, start, end, level);
765 } 763 }
766 764
767 } 765 }
OLDNEW
« no previous file with comments | « chrome/common/l10n_util.h ('k') | chrome/common/l10n_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698