OLD | NEW |
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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "third_party/icu/source/common/unicode/locid.h" | 13 #include "third_party/icu/source/common/unicode/locid.h" |
14 #include "third_party/icu/source/common/unicode/uchar.h" | 14 #include "third_party/icu/source/common/unicode/uchar.h" |
15 #include "third_party/icu/source/common/unicode/uscript.h" | 15 #include "third_party/icu/source/common/unicode/uscript.h" |
16 #include "third_party/icu/source/i18n/unicode/coll.h" | 16 #include "third_party/icu/source/i18n/unicode/coll.h" |
17 | 17 |
| 18 #if defined(OS_IOS) |
| 19 #include "base/ios/ios_util.h" |
| 20 #endif |
| 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 // Extract language, country and variant, but ignore keywords. For example, | 24 // Extract language, country and variant, but ignore keywords. For example, |
21 // en-US, ca@valencia, ca-ES@valencia. | 25 // en-US, ca@valencia, ca-ES@valencia. |
22 std::string GetLocaleString(const icu::Locale& locale) { | 26 std::string GetLocaleString(const icu::Locale& locale) { |
23 const char* language = locale.getLanguage(); | 27 const char* language = locale.getLanguage(); |
24 const char* country = locale.getCountry(); | 28 const char* country = locale.getCountry(); |
25 const char* variant = locale.getVariant(); | 29 const char* variant = locale.getVariant(); |
26 | 30 |
27 std::string result = | 31 std::string result = |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 TextDirection GetTextDirectionForLocale(const char* locale_name) { | 138 TextDirection GetTextDirectionForLocale(const char* locale_name) { |
135 const std::string group_name = | 139 const std::string group_name = |
136 FieldTrialList::FindFullName("LightSpeed"); | 140 FieldTrialList::FindFullName("LightSpeed"); |
137 // StartsWith allows flexibility for this experiment to apply to multiple | 141 // StartsWith allows flexibility for this experiment to apply to multiple |
138 // group names. To start, this will apply to AvoidMMapOnStartup. | 142 // group names. To start, this will apply to AvoidMMapOnStartup. |
139 if (StartsWith(group_name, "AvoidMMap", CompareCase::SENSITIVE)) { | 143 if (StartsWith(group_name, "AvoidMMap", CompareCase::SENSITIVE)) { |
140 static const char kEnglishLocale[] = "en_"; | 144 static const char kEnglishLocale[] = "en_"; |
141 if (StartsWith(locale_name, kEnglishLocale, CompareCase::SENSITIVE)) | 145 if (StartsWith(locale_name, kEnglishLocale, CompareCase::SENSITIVE)) |
142 return LEFT_TO_RIGHT; | 146 return LEFT_TO_RIGHT; |
143 } | 147 } |
| 148 |
| 149 // On iOS, check for RTL forcing. |
| 150 #if defined(OS_IOS) |
| 151 if (ios::IsInForcedRTL()) |
| 152 return RIGHT_TO_LEFT; |
| 153 #endif |
| 154 |
144 UErrorCode status = U_ZERO_ERROR; | 155 UErrorCode status = U_ZERO_ERROR; |
145 ULayoutType layout_dir = uloc_getCharacterOrientation(locale_name, &status); | 156 ULayoutType layout_dir = uloc_getCharacterOrientation(locale_name, &status); |
146 DCHECK(U_SUCCESS(status)); | 157 DCHECK(U_SUCCESS(status)); |
147 // Treat anything other than RTL as LTR. | 158 // Treat anything other than RTL as LTR. |
148 return (layout_dir != ULOC_LAYOUT_RTL) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT; | 159 return (layout_dir != ULOC_LAYOUT_RTL) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT; |
149 } | 160 } |
150 | 161 |
151 TextDirection GetFirstStrongCharacterDirection(const string16& text) { | 162 TextDirection GetFirstStrongCharacterDirection(const string16& text) { |
152 const UChar* string = text.c_str(); | 163 const UChar* string = text.c_str(); |
153 size_t length = text.length(); | 164 size_t length = text.length(); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 begin == kRightToLeftOverride) | 406 begin == kRightToLeftOverride) |
396 ++begin_index; | 407 ++begin_index; |
397 size_t end_index = text.length() - 1; | 408 size_t end_index = text.length() - 1; |
398 if (text[end_index] == kPopDirectionalFormatting) | 409 if (text[end_index] == kPopDirectionalFormatting) |
399 --end_index; | 410 --end_index; |
400 return text.substr(begin_index, end_index - begin_index + 1); | 411 return text.substr(begin_index, end_index - begin_index + 1); |
401 } | 412 } |
402 | 413 |
403 } // namespace i18n | 414 } // namespace i18n |
404 } // namespace base | 415 } // namespace base |
OLD | NEW |