Chromium Code Reviews| 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 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
|
msw
2017/04/28 22:04:03
This function is called heavily, cache the value (
Kevin Bailey
2017/04/29 04:24:03
Done.
| |
| 59 if (command_line->HasSwitch(switches::kForceTextDirection)) { | |
| 60 std::string force_flag = | |
| 61 command_line->GetSwitchValueASCII(switches::kForceTextDirection); | |
| 62 | |
| 63 if (force_flag == switches::kForceUIDirectionRTL) | |
| 64 return base::i18n::RIGHT_TO_LEFT; | |
| 65 if (force_flag == switches::kForceUIDirectionLTR) | |
| 66 return base::i18n::LEFT_TO_RIGHT; | |
| 67 } | |
| 58 // Now that we have the character, we use ICU in order to query for the | 68 // Now that we have the character, we use ICU in order to query for the |
| 59 // appropriate Unicode BiDi character type. | 69 // appropriate Unicode BiDi character type. |
| 60 int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); | 70 int32_t property = u_getIntPropertyValue(character, UCHAR_BIDI_CLASS); |
| 61 if ((property == U_RIGHT_TO_LEFT) || | 71 if ((property == U_RIGHT_TO_LEFT) || |
| 62 (property == U_RIGHT_TO_LEFT_ARABIC) || | 72 (property == U_RIGHT_TO_LEFT_ARABIC) || |
| 63 (property == U_RIGHT_TO_LEFT_EMBEDDING) || | 73 (property == U_RIGHT_TO_LEFT_EMBEDDING) || |
| 64 (property == U_RIGHT_TO_LEFT_OVERRIDE)) { | 74 (property == U_RIGHT_TO_LEFT_OVERRIDE)) { |
| 65 return base::i18n::RIGHT_TO_LEFT; | 75 return base::i18n::RIGHT_TO_LEFT; |
| 66 } else if ((property == U_LEFT_TO_RIGHT) || | 76 } else if ((property == U_LEFT_TO_RIGHT) || |
| 67 (property == U_LEFT_TO_RIGHT_EMBEDDING) || | 77 (property == U_LEFT_TO_RIGHT_EMBEDDING) || |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 begin == kRightToLeftOverride) | 454 begin == kRightToLeftOverride) |
| 445 ++begin_index; | 455 ++begin_index; |
| 446 size_t end_index = text.length() - 1; | 456 size_t end_index = text.length() - 1; |
| 447 if (text[end_index] == kPopDirectionalFormatting) | 457 if (text[end_index] == kPopDirectionalFormatting) |
| 448 --end_index; | 458 --end_index; |
| 449 return text.substr(begin_index, end_index - begin_index + 1); | 459 return text.substr(begin_index, end_index - begin_index + 1); |
| 450 } | 460 } |
| 451 | 461 |
| 452 } // namespace i18n | 462 } // namespace i18n |
| 453 } // namespace base | 463 } // namespace base |
| OLD | NEW |