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

Side by Side Diff: base/i18n/rtl.cc

Issue 1254933002: Support XCode's "Right to Left Pseudolanguage" on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | base/ios/ios_util.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/i18n/rtl.h" 5 #include "base/i18n/rtl.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "third_party/icu/source/common/unicode/locid.h" 12 #include "third_party/icu/source/common/unicode/locid.h"
13 #include "third_party/icu/source/common/unicode/uchar.h" 13 #include "third_party/icu/source/common/unicode/uchar.h"
14 #include "third_party/icu/source/common/unicode/uscript.h" 14 #include "third_party/icu/source/common/unicode/uscript.h"
15 #include "third_party/icu/source/i18n/unicode/coll.h" 15 #include "third_party/icu/source/i18n/unicode/coll.h"
16 16
17 #if defined(OS_IOS)
18 #include "base/ios/ios_util.h"
19 #endif
20
17 namespace { 21 namespace {
18 22
19 // Extract language, country and variant, but ignore keywords. For example, 23 // Extract language, country and variant, but ignore keywords. For example,
20 // en-US, ca@valencia, ca-ES@valencia. 24 // en-US, ca@valencia, ca-ES@valencia.
21 std::string GetLocaleString(const icu::Locale& locale) { 25 std::string GetLocaleString(const icu::Locale& locale) {
22 const char* language = locale.getLanguage(); 26 const char* language = locale.getLanguage();
23 const char* country = locale.getCountry(); 27 const char* country = locale.getCountry();
24 const char* variant = locale.getVariant(); 28 const char* variant = locale.getVariant();
25 29
26 std::string result = 30 std::string result =
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 128
125 bool ICUIsRTL() { 129 bool ICUIsRTL() {
126 if (g_icu_text_direction == UNKNOWN_DIRECTION) { 130 if (g_icu_text_direction == UNKNOWN_DIRECTION) {
127 const icu::Locale& locale = icu::Locale::getDefault(); 131 const icu::Locale& locale = icu::Locale::getDefault();
128 g_icu_text_direction = GetTextDirectionForLocale(locale.getName()); 132 g_icu_text_direction = GetTextDirectionForLocale(locale.getName());
129 } 133 }
130 return g_icu_text_direction == RIGHT_TO_LEFT; 134 return g_icu_text_direction == RIGHT_TO_LEFT;
131 } 135 }
132 136
133 TextDirection GetTextDirectionForLocale(const char* locale_name) { 137 TextDirection GetTextDirectionForLocale(const char* locale_name) {
138 // On iOS, check for RTL forcing.
139 #if defined(OS_IOS)
140 if (ios::IsForcingRTL())
jungshik at Google 2015/08/07 17:32:22 nit: How about IsInForcedRTL ?
marq (ping after 24h) 2015/08/10 07:28:37 Done.
141 return RIGHT_TO_LEFT;
142 #endif
134 UErrorCode status = U_ZERO_ERROR; 143 UErrorCode status = U_ZERO_ERROR;
135 ULayoutType layout_dir = uloc_getCharacterOrientation(locale_name, &status); 144 ULayoutType layout_dir = uloc_getCharacterOrientation(locale_name, &status);
136 DCHECK(U_SUCCESS(status)); 145 DCHECK(U_SUCCESS(status));
137 // Treat anything other than RTL as LTR. 146 // Treat anything other than RTL as LTR.
138 return (layout_dir != ULOC_LAYOUT_RTL) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT; 147 return (layout_dir != ULOC_LAYOUT_RTL) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT;
139 } 148 }
140 149
141 TextDirection GetFirstStrongCharacterDirection(const string16& text) { 150 TextDirection GetFirstStrongCharacterDirection(const string16& text) {
142 const UChar* string = text.c_str(); 151 const UChar* string = text.c_str();
143 size_t length = text.length(); 152 size_t length = text.length();
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 begin == kRightToLeftOverride) 394 begin == kRightToLeftOverride)
386 ++begin_index; 395 ++begin_index;
387 size_t end_index = text.length() - 1; 396 size_t end_index = text.length() - 1;
388 if (text[end_index] == kPopDirectionalFormatting) 397 if (text[end_index] == kPopDirectionalFormatting)
389 --end_index; 398 --end_index;
390 return text.substr(begin_index, end_index - begin_index + 1); 399 return text.substr(begin_index, end_index - begin_index + 1);
391 } 400 }
392 401
393 } // namespace i18n 402 } // namespace i18n
394 } // namespace base 403 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/ios/ios_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698