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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 result += '-'; | 44 result += '-'; |
45 result += country; | 45 result += country; |
46 } | 46 } |
47 | 47 |
48 if (variant != NULL && *variant != '\0') | 48 if (variant != NULL && *variant != '\0') |
49 result += '@' + base::ToLowerASCII(variant); | 49 result += '@' + base::ToLowerASCII(variant); |
50 | 50 |
51 return result; | 51 return result; |
52 } | 52 } |
53 | 53 |
54 bool HasForcedTextDirectionSwitch() { | |
msw
2017/05/01 20:56:18
nit: "// Get the cached switch presence; avoids re
Kevin Bailey
2017/05/01 21:21:42
Done. Seemed like a bit much overhead for a whole
| |
55 static bool value = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
56 switches::kForceTextDirection); | |
57 return value; | |
58 } | |
59 | |
54 // Returns LEFT_TO_RIGHT or RIGHT_TO_LEFT if |character| has strong | 60 // Returns LEFT_TO_RIGHT or RIGHT_TO_LEFT if |character| has strong |
55 // directionality, returns UNKNOWN_DIRECTION if it doesn't. Please refer to | 61 // directionality, returns UNKNOWN_DIRECTION if it doesn't. Please refer to |
56 // http://unicode.org/reports/tr9/ for more information. | 62 // http://unicode.org/reports/tr9/ for more information. |
57 base::i18n::TextDirection GetCharacterDirection(UChar32 character) { | 63 base::i18n::TextDirection GetCharacterDirection(UChar32 character) { |
64 if (HasForcedTextDirectionSwitch()) { | |
65 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
66 std::string force_flag = | |
67 command_line->GetSwitchValueASCII(switches::kForceTextDirection); | |
68 | |
69 if (force_flag == switches::kForceDirectionRTL) | |
70 return base::i18n::RIGHT_TO_LEFT; | |
71 if (force_flag == switches::kForceDirectionLTR) | |
72 return base::i18n::LEFT_TO_RIGHT; | |
73 } | |
58 // Now that we have the character, we use ICU in order to query for the | 74 // Now that we have the character, we use ICU in order to query for the |
59 // appropriate Unicode BiDi character type. | 75 // appropriate Unicode BiDi character type. |
60 int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); | 76 int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); |
61 if ((property == U_RIGHT_TO_LEFT) || | 77 if ((property == U_RIGHT_TO_LEFT) || |
62 (property == U_RIGHT_TO_LEFT_ARABIC) || | 78 (property == U_RIGHT_TO_LEFT_ARABIC) || |
63 (property == U_RIGHT_TO_LEFT_EMBEDDING) || | 79 (property == U_RIGHT_TO_LEFT_EMBEDDING) || |
64 (property == U_RIGHT_TO_LEFT_OVERRIDE)) { | 80 (property == U_RIGHT_TO_LEFT_OVERRIDE)) { |
65 return base::i18n::RIGHT_TO_LEFT; | 81 return base::i18n::RIGHT_TO_LEFT; |
66 } else if ((property == U_LEFT_TO_RIGHT) || | 82 } else if ((property == U_LEFT_TO_RIGHT) || |
67 (property == U_LEFT_TO_RIGHT_EMBEDDING) || | 83 (property == U_LEFT_TO_RIGHT_EMBEDDING) || |
(...skipping 10 matching lines...) Expand all Loading... | |
78 #if defined(OS_IOS) | 94 #if defined(OS_IOS) |
79 if (base::ios::IsInForcedRTL()) | 95 if (base::ios::IsInForcedRTL()) |
80 return base::i18n::RIGHT_TO_LEFT; | 96 return base::i18n::RIGHT_TO_LEFT; |
81 #endif | 97 #endif |
82 | 98 |
83 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 99 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
84 if (command_line->HasSwitch(switches::kForceUIDirection)) { | 100 if (command_line->HasSwitch(switches::kForceUIDirection)) { |
85 std::string force_flag = | 101 std::string force_flag = |
86 command_line->GetSwitchValueASCII(switches::kForceUIDirection); | 102 command_line->GetSwitchValueASCII(switches::kForceUIDirection); |
87 | 103 |
88 if (force_flag == switches::kForceUIDirectionLTR) | 104 if (force_flag == switches::kForceDirectionLTR) |
89 return base::i18n::LEFT_TO_RIGHT; | 105 return base::i18n::LEFT_TO_RIGHT; |
90 | 106 |
91 if (force_flag == switches::kForceUIDirectionRTL) | 107 if (force_flag == switches::kForceDirectionRTL) |
92 return base::i18n::RIGHT_TO_LEFT; | 108 return base::i18n::RIGHT_TO_LEFT; |
93 } | 109 } |
94 | 110 |
95 return base::i18n::UNKNOWN_DIRECTION; | 111 return base::i18n::UNKNOWN_DIRECTION; |
96 } | 112 } |
97 | 113 |
98 } // namespace | 114 } // namespace |
99 | 115 |
100 namespace base { | 116 namespace base { |
101 namespace i18n { | 117 namespace i18n { |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 begin == kRightToLeftOverride) | 460 begin == kRightToLeftOverride) |
445 ++begin_index; | 461 ++begin_index; |
446 size_t end_index = text.length() - 1; | 462 size_t end_index = text.length() - 1; |
447 if (text[end_index] == kPopDirectionalFormatting) | 463 if (text[end_index] == kPopDirectionalFormatting) |
448 --end_index; | 464 --end_index; |
449 return text.substr(begin_index, end_index - begin_index + 1); | 465 return text.substr(begin_index, end_index - begin_index + 1); |
450 } | 466 } |
451 | 467 |
452 } // namespace i18n | 468 } // namespace i18n |
453 } // namespace base | 469 } // namespace base |
OLD | NEW |