| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Returns LEFT_TO_RIGHT or RIGHT_TO_LEFT if |character| has strong | 54 // Returns LEFT_TO_RIGHT or RIGHT_TO_LEFT if |character| has strong |
| 55 // directionality, returns UNKNOWN_DIRECTION if it doesn't. Please refer to | 55 // directionality, returns UNKNOWN_DIRECTION if it doesn't. Please refer to |
| 56 // http://unicode.org/reports/tr9/ for more information. | 56 // http://unicode.org/reports/tr9/ for more information. |
| 57 base::i18n::TextDirection GetCharacterDirection(UChar32 character) { | 57 base::i18n::TextDirection GetCharacterDirection(UChar32 character) { |
| 58 static bool has_switch = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 59 switches::kForceTextDirection); |
| 60 if (has_switch) { |
| 61 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 62 std::string force_flag = |
| 63 command_line->GetSwitchValueASCII(switches::kForceTextDirection); |
| 64 |
| 65 if (force_flag == switches::kForceDirectionRTL) |
| 66 return base::i18n::RIGHT_TO_LEFT; |
| 67 if (force_flag == switches::kForceDirectionLTR) |
| 68 return base::i18n::LEFT_TO_RIGHT; |
| 69 } |
| 58 // Now that we have the character, we use ICU in order to query for the | 70 // Now that we have the character, we use ICU in order to query for the |
| 59 // appropriate Unicode BiDi character type. | 71 // appropriate Unicode BiDi character type. |
| 60 int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); | 72 int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); |
| 61 if ((property == U_RIGHT_TO_LEFT) || | 73 if ((property == U_RIGHT_TO_LEFT) || |
| 62 (property == U_RIGHT_TO_LEFT_ARABIC) || | 74 (property == U_RIGHT_TO_LEFT_ARABIC) || |
| 63 (property == U_RIGHT_TO_LEFT_EMBEDDING) || | 75 (property == U_RIGHT_TO_LEFT_EMBEDDING) || |
| 64 (property == U_RIGHT_TO_LEFT_OVERRIDE)) { | 76 (property == U_RIGHT_TO_LEFT_OVERRIDE)) { |
| 65 return base::i18n::RIGHT_TO_LEFT; | 77 return base::i18n::RIGHT_TO_LEFT; |
| 66 } else if ((property == U_LEFT_TO_RIGHT) || | 78 } else if ((property == U_LEFT_TO_RIGHT) || |
| 67 (property == U_LEFT_TO_RIGHT_EMBEDDING) || | 79 (property == U_LEFT_TO_RIGHT_EMBEDDING) || |
| (...skipping 10 matching lines...) Expand all Loading... |
| 78 #if defined(OS_IOS) | 90 #if defined(OS_IOS) |
| 79 if (base::ios::IsInForcedRTL()) | 91 if (base::ios::IsInForcedRTL()) |
| 80 return base::i18n::RIGHT_TO_LEFT; | 92 return base::i18n::RIGHT_TO_LEFT; |
| 81 #endif | 93 #endif |
| 82 | 94 |
| 83 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 95 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 84 if (command_line->HasSwitch(switches::kForceUIDirection)) { | 96 if (command_line->HasSwitch(switches::kForceUIDirection)) { |
| 85 std::string force_flag = | 97 std::string force_flag = |
| 86 command_line->GetSwitchValueASCII(switches::kForceUIDirection); | 98 command_line->GetSwitchValueASCII(switches::kForceUIDirection); |
| 87 | 99 |
| 88 if (force_flag == switches::kForceUIDirectionLTR) | 100 if (force_flag == switches::kForceDirectionLTR) |
| 89 return base::i18n::LEFT_TO_RIGHT; | 101 return base::i18n::LEFT_TO_RIGHT; |
| 90 | 102 |
| 91 if (force_flag == switches::kForceUIDirectionRTL) | 103 if (force_flag == switches::kForceDirectionRTL) |
| 92 return base::i18n::RIGHT_TO_LEFT; | 104 return base::i18n::RIGHT_TO_LEFT; |
| 93 } | 105 } |
| 94 | 106 |
| 95 return base::i18n::UNKNOWN_DIRECTION; | 107 return base::i18n::UNKNOWN_DIRECTION; |
| 96 } | 108 } |
| 97 | 109 |
| 98 } // namespace | 110 } // namespace |
| 99 | 111 |
| 100 namespace base { | 112 namespace base { |
| 101 namespace i18n { | 113 namespace i18n { |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 begin == kRightToLeftOverride) | 456 begin == kRightToLeftOverride) |
| 445 ++begin_index; | 457 ++begin_index; |
| 446 size_t end_index = text.length() - 1; | 458 size_t end_index = text.length() - 1; |
| 447 if (text[end_index] == kPopDirectionalFormatting) | 459 if (text[end_index] == kPopDirectionalFormatting) |
| 448 --end_index; | 460 --end_index; |
| 449 return text.substr(begin_index, end_index - begin_index + 1); | 461 return text.substr(begin_index, end_index - begin_index + 1); |
| 450 } | 462 } |
| 451 | 463 |
| 452 } // namespace i18n | 464 } // namespace i18n |
| 453 } // namespace base | 465 } // namespace base |
| OLD | NEW |