Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef BASE_I18N_RTL_H_ | 5 #ifndef BASE_I18N_RTL_H_ |
| 6 #define BASE_I18N_RTL_H_ | 6 #define BASE_I18N_RTL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 // character with strong directionality in the string. If no character in the | 64 // character with strong directionality in the string. If no character in the |
| 65 // text has strong directionality, LEFT_TO_RIGHT is returned. The Bidi | 65 // text has strong directionality, LEFT_TO_RIGHT is returned. The Bidi |
| 66 // character types L, LRE, LRO, R, AL, RLE, and RLO are considered as strong | 66 // character types L, LRE, LRO, R, AL, RLE, and RLO are considered as strong |
| 67 // directionality characters. Please refer to http://unicode.org/reports/tr9/ | 67 // directionality characters. Please refer to http://unicode.org/reports/tr9/ |
| 68 // for more information. | 68 // for more information. |
| 69 TextDirection GetFirstStrongCharacterDirection(const string16& text); | 69 TextDirection GetFirstStrongCharacterDirection(const string16& text); |
| 70 #if defined(WCHAR_T_IS_UTF32) | 70 #if defined(WCHAR_T_IS_UTF32) |
| 71 TextDirection GetFirstStrongCharacterDirection(const std::wstring& text); | 71 TextDirection GetFirstStrongCharacterDirection(const std::wstring& text); |
| 72 #endif | 72 #endif |
| 73 | 73 |
| 74 // Given the string in |text|, this function creates a copy of the string with | 74 // Given the string in |text|, this function modifies the string in place with |
| 75 // the appropriate Unicode formatting marks that mark the string direction | 75 // the appropriate Unicode formatting marks that mark the string direction |
| 76 // (either left-to-right or right-to-left). The new string is returned in | 76 // (either left-to-right or right-to-left).The function checks both the current |
|
Avi (use Gerrit)
2010/11/23 16:07:08
nit: space after period
| |
| 77 // |localized_text|. The function checks both the current locale and the | 77 // locale and the contents of the string in order to determine the direction of |
| 78 // contents of the string in order to determine the direction of the returned | 78 // the returned string. The function returns true if the string in |text| was |
| 79 // string. The function returns true if the string in |text| was properly | 79 // properly adjusted. |
| 80 // adjusted. | |
| 81 // | 80 // |
| 82 // Certain LTR strings are not rendered correctly when the context is RTL. For | 81 // Certain LTR strings are not rendered correctly when the context is RTL. For |
| 83 // example, the string "Foo!" will appear as "!Foo" if it is rendered as is in | 82 // example, the string "Foo!" will appear as "!Foo" if it is rendered as is in |
| 84 // an RTL context. Calling this function will make sure the returned localized | 83 // an RTL context. Calling this function will make sure the returned localized |
| 85 // string is always treated as a right-to-left string. This is done by | 84 // string is always treated as a right-to-left string. This is done by |
| 86 // inserting certain Unicode formatting marks into the returned string. | 85 // inserting certain Unicode formatting marks into the returned string. |
| 87 // | 86 // |
| 88 // TODO(brettw) bug 47194: This funciton is confusing. If it does no adjustment | 87 // TODO(idana) bug 6806: this function adjusts the string in question only |
| 89 // becuase the current locale is not RTL, it will do nothing and return false. | |
| 90 // This means you have to check the return value in many cases which doesn't | |
| 91 // make sense. This should be cleaned up and probably just take a single | |
| 92 // argument that's a pointer to a string that it modifies as necessary. In the | |
| 93 // meantime, the recommended usage is to use the same arg as input & output, | |
| 94 // which will work without extra checks: | |
| 95 // AdjustStringForLocaleDirection(text, &text); | |
| 96 // | |
| 97 // TODO(idana) bug# 1206120: this function adjusts the string in question only | |
| 98 // if the current locale is right-to-left. The function does not take care of | 88 // if the current locale is right-to-left. The function does not take care of |
| 99 // the opposite case (an RTL string displayed in an LTR context) since | 89 // the opposite case (an RTL string displayed in an LTR context) since |
| 100 // adjusting the string involves inserting Unicode formatting characters that | 90 // adjusting the string involves inserting Unicode formatting characters that |
| 101 // Windows does not handle well unless right-to-left language support is | 91 // Windows does not handle well unless right-to-left language support is |
| 102 // installed. Since the English version of Windows doesn't have right-to-left | 92 // installed. Since the English version of Windows doesn't have right-to-left |
| 103 // language support installed by default, inserting the direction Unicode mark | 93 // language support installed by default, inserting the direction Unicode mark |
| 104 // results in Windows displaying squares. | 94 // results in Windows displaying squares. |
| 105 bool AdjustStringForLocaleDirection(const string16& text, | 95 bool AdjustStringForLocaleDirection(string16* text); |
| 106 string16* localized_text); | |
| 107 #if defined(WCHAR_T_IS_UTF32) | 96 #if defined(WCHAR_T_IS_UTF32) |
| 108 bool AdjustStringForLocaleDirection(const std::wstring& text, | 97 bool AdjustStringForLocaleDirection(std::wstring* text); |
| 109 std::wstring* localized_text); | |
| 110 #endif | 98 #endif |
| 111 | 99 |
| 112 // Returns true if the string contains at least one character with strong right | 100 // Returns true if the string contains at least one character with strong right |
| 113 // to left directionality; that is, a character with either R or AL Unicode | 101 // to left directionality; that is, a character with either R or AL Unicode |
| 114 // BiDi character type. | 102 // BiDi character type. |
| 115 bool StringContainsStrongRTLChars(const string16& text); | 103 bool StringContainsStrongRTLChars(const string16& text); |
| 116 #if defined(WCHAR_T_IS_UTF32) | 104 #if defined(WCHAR_T_IS_UTF32) |
| 117 bool StringContainsStrongRTLChars(const std::wstring& text); | 105 bool StringContainsStrongRTLChars(const std::wstring& text); |
| 118 #endif | 106 #endif |
| 119 | 107 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 // return the text itself. Explicit bidi control characters display and have | 139 // return the text itself. Explicit bidi control characters display and have |
| 152 // semantic effect. They can be deleted so they might not always appear in a | 140 // semantic effect. They can be deleted so they might not always appear in a |
| 153 // pair. | 141 // pair. |
| 154 const string16 StripWrappingBidiControlCharacters(const string16& text) | 142 const string16 StripWrappingBidiControlCharacters(const string16& text) |
| 155 WARN_UNUSED_RESULT; | 143 WARN_UNUSED_RESULT; |
| 156 | 144 |
| 157 } // namespace i18n | 145 } // namespace i18n |
| 158 } // namespace base | 146 } // namespace base |
| 159 | 147 |
| 160 #endif // BASE_I18N_RTL_H_ | 148 #endif // BASE_I18N_RTL_H_ |
| OLD | NEW |