Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: base/i18n/rtl.h

Issue 7812009: Base: Switch base_i18n to be a separate dll (component build) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/i18n/number_formatting.h ('k') | base/i18n/time_formatting.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #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
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/i18n/base_i18n_export.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 15
15 class FilePath; 16 class FilePath;
16 17
17 namespace base { 18 namespace base {
18 namespace i18n { 19 namespace i18n {
19 20
20 const char16 kRightToLeftMark = 0x200F; 21 const char16 kRightToLeftMark = 0x200F;
21 const char16 kLeftToRightMark = 0x200E; 22 const char16 kLeftToRightMark = 0x200E;
22 const char16 kLeftToRightEmbeddingMark = 0x202A; 23 const char16 kLeftToRightEmbeddingMark = 0x202A;
23 const char16 kRightToLeftEmbeddingMark = 0x202B; 24 const char16 kRightToLeftEmbeddingMark = 0x202B;
24 const char16 kPopDirectionalFormatting = 0x202C; 25 const char16 kPopDirectionalFormatting = 0x202C;
25 const char16 kLeftToRightOverride = 0x202D; 26 const char16 kLeftToRightOverride = 0x202D;
26 const char16 kRightToLeftOverride = 0x202E; 27 const char16 kRightToLeftOverride = 0x202E;
27 28
28 enum TextDirection { 29 enum TextDirection {
29 UNKNOWN_DIRECTION, 30 UNKNOWN_DIRECTION,
30 RIGHT_TO_LEFT, 31 RIGHT_TO_LEFT,
31 LEFT_TO_RIGHT, 32 LEFT_TO_RIGHT,
32 }; 33 };
33 34
34 // Get the locale that the currently running process has been configured to use. 35 // Get the locale that the currently running process has been configured to use.
35 // The return value is of the form language[-country] (e.g., en-US) where the 36 // The return value is of the form language[-country] (e.g., en-US) where the
36 // language is the 2 or 3 letter code from ISO-639. 37 // language is the 2 or 3 letter code from ISO-639.
37 std::string GetConfiguredLocale(); 38 BASE_I18N_EXPORT std::string GetConfiguredLocale();
38 39
39 // Canonicalize a string (eg. a POSIX locale string) to a Chrome locale name. 40 // Canonicalize a string (eg. a POSIX locale string) to a Chrome locale name.
40 std::string GetCanonicalLocale(const char* locale); 41 BASE_I18N_EXPORT std::string GetCanonicalLocale(const char* locale);
41 42
42 // Sets the default locale of ICU. 43 // Sets the default locale of ICU.
43 // Once the application locale of Chrome in GetApplicationLocale is determined, 44 // Once the application locale of Chrome in GetApplicationLocale is determined,
44 // the default locale of ICU need to be changed to match the application locale 45 // the default locale of ICU need to be changed to match the application locale
45 // so that ICU functions work correctly in a locale-dependent manner. 46 // so that ICU functions work correctly in a locale-dependent manner.
46 // This is handy in that we don't have to call GetApplicationLocale() 47 // This is handy in that we don't have to call GetApplicationLocale()
47 // everytime we call locale-dependent ICU APIs as long as we make sure 48 // everytime we call locale-dependent ICU APIs as long as we make sure
48 // that this is called before any locale-dependent API is called. 49 // that this is called before any locale-dependent API is called.
49 void SetICUDefaultLocale(const std::string& locale_string); 50 BASE_I18N_EXPORT void SetICUDefaultLocale(const std::string& locale_string);
50 51
51 // Returns true if the application text direction is right-to-left. 52 // Returns true if the application text direction is right-to-left.
52 bool IsRTL(); 53 BASE_I18N_EXPORT bool IsRTL();
53 54
54 // Returns whether the text direction for the default ICU locale is RTL. This 55 // Returns whether the text direction for the default ICU locale is RTL. This
55 // assumes that SetICUDefaultLocale has been called to set the default locale to 56 // assumes that SetICUDefaultLocale has been called to set the default locale to
56 // the UI locale of Chrome. 57 // the UI locale of Chrome.
57 // NOTE: Generally, you should call IsRTL() instead of this. 58 // NOTE: Generally, you should call IsRTL() instead of this.
58 bool ICUIsRTL(); 59 BASE_I18N_EXPORT bool ICUIsRTL();
59 60
60 // Returns the text direction for |locale_name|. 61 // Returns the text direction for |locale_name|.
61 TextDirection GetTextDirectionForLocale(const char* locale_name); 62 BASE_I18N_EXPORT TextDirection GetTextDirectionForLocale(
63 const char* locale_name);
62 64
63 // Given the string in |text|, returns the directionality of the first 65 // Given the string in |text|, returns the directionality of the first
64 // character with strong directionality in the string. If no character in the 66 // character with strong directionality in the string. If no character in the
65 // text has strong directionality, LEFT_TO_RIGHT is returned. The Bidi 67 // 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 68 // 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/ 69 // directionality characters. Please refer to http://unicode.org/reports/tr9/
68 // for more information. 70 // for more information.
69 TextDirection GetFirstStrongCharacterDirection(const string16& text); 71 BASE_I18N_EXPORT TextDirection GetFirstStrongCharacterDirection(
72 const string16& text);
70 73
71 // Given the string in |text|, this function modifies the string in place with 74 // Given the string in |text|, this function modifies the string in place with
72 // the appropriate Unicode formatting marks that mark the string direction 75 // the appropriate Unicode formatting marks that mark the string direction
73 // (either left-to-right or right-to-left). The function checks both the current 76 // (either left-to-right or right-to-left). The function checks both the current
74 // locale and the contents of the string in order to determine the direction of 77 // locale and the contents of the string in order to determine the direction of
75 // the returned string. The function returns true if the string in |text| was 78 // the returned string. The function returns true if the string in |text| was
76 // properly adjusted. 79 // properly adjusted.
77 // 80 //
78 // 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
79 // 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
80 // 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
81 // 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
82 // inserting certain Unicode formatting marks into the returned string. 85 // inserting certain Unicode formatting marks into the returned string.
83 // 86 //
84 // ** Notes about the Windows version of this function: 87 // ** Notes about the Windows version of this function:
85 // TODO(idana) bug 6806: this function adjusts the string in question only 88 // TODO(idana) bug 6806: this function adjusts the string in question only
86 // if the current locale is right-to-left. The function does not take care of 89 // if the current locale is right-to-left. The function does not take care of
87 // the opposite case (an RTL string displayed in an LTR context) since 90 // the opposite case (an RTL string displayed in an LTR context) since
88 // adjusting the string involves inserting Unicode formatting characters that 91 // adjusting the string involves inserting Unicode formatting characters that
89 // Windows does not handle well unless right-to-left language support is 92 // Windows does not handle well unless right-to-left language support is
90 // installed. Since the English version of Windows doesn't have right-to-left 93 // installed. Since the English version of Windows doesn't have right-to-left
91 // language support installed by default, inserting the direction Unicode mark 94 // language support installed by default, inserting the direction Unicode mark
92 // results in Windows displaying squares. 95 // results in Windows displaying squares.
93 bool AdjustStringForLocaleDirection(string16* text); 96 BASE_I18N_EXPORT bool AdjustStringForLocaleDirection(string16* text);
94 97
95 // Returns true if the string contains at least one character with strong right 98 // Returns true if the string contains at least one character with strong right
96 // to left directionality; that is, a character with either R or AL Unicode 99 // to left directionality; that is, a character with either R or AL Unicode
97 // BiDi character type. 100 // BiDi character type.
98 bool StringContainsStrongRTLChars(const string16& text); 101 BASE_I18N_EXPORT bool StringContainsStrongRTLChars(const string16& text);
99 102
100 // Wraps a string with an LRE-PDF pair which essentialy marks the string as a 103 // Wraps a string with an LRE-PDF pair which essentialy marks the string as a
101 // Left-To-Right string. Doing this is useful in order to make sure LTR 104 // Left-To-Right string. Doing this is useful in order to make sure LTR
102 // strings are rendered properly in an RTL context. 105 // strings are rendered properly in an RTL context.
103 void WrapStringWithLTRFormatting(string16* text); 106 BASE_I18N_EXPORT void WrapStringWithLTRFormatting(string16* text);
104 107
105 // Wraps a string with an RLE-PDF pair which essentialy marks the string as a 108 // Wraps a string with an RLE-PDF pair which essentialy marks the string as a
106 // Right-To-Left string. Doing this is useful in order to make sure RTL 109 // Right-To-Left string. Doing this is useful in order to make sure RTL
107 // strings are rendered properly in an LTR context. 110 // strings are rendered properly in an LTR context.
108 void WrapStringWithRTLFormatting(string16* text); 111 BASE_I18N_EXPORT void WrapStringWithRTLFormatting(string16* text);
109 112
110 // Wraps file path to get it to display correctly in RTL UI. All filepaths 113 // Wraps file path to get it to display correctly in RTL UI. All filepaths
111 // should be passed through this function before display in UI for RTL locales. 114 // should be passed through this function before display in UI for RTL locales.
112 void WrapPathWithLTRFormatting(const FilePath& path, 115 BASE_I18N_EXPORT void WrapPathWithLTRFormatting(const FilePath& path,
113 string16* rtl_safe_path); 116 string16* rtl_safe_path);
114 117
115 // Given the string in |text|, this function returns the adjusted string having 118 // Given the string in |text|, this function returns the adjusted string having
116 // LTR directionality for display purpose. Which means that in RTL locale the 119 // LTR directionality for display purpose. Which means that in RTL locale the
117 // string is wrapped with LRE (Left-To-Right Embedding) and PDF (Pop 120 // string is wrapped with LRE (Left-To-Right Embedding) and PDF (Pop
118 // Directional Formatting) marks and returned. In LTR locale, the string itself 121 // Directional Formatting) marks and returned. In LTR locale, the string itself
119 // is returned. 122 // is returned.
120 string16 GetDisplayStringInLTRDirectionality(const string16& text) 123 BASE_I18N_EXPORT string16 GetDisplayStringInLTRDirectionality(
121 WARN_UNUSED_RESULT; 124 const string16& text) WARN_UNUSED_RESULT;
122 125
123 // Strip the beginning (U+202A..U+202B, U+202D..U+202E) and/or ending (U+202C) 126 // Strip the beginning (U+202A..U+202B, U+202D..U+202E) and/or ending (U+202C)
124 // explicit bidi control characters from |text|, if there are any. Otherwise, 127 // explicit bidi control characters from |text|, if there are any. Otherwise,
125 // return the text itself. Explicit bidi control characters display and have 128 // return the text itself. Explicit bidi control characters display and have
126 // semantic effect. They can be deleted so they might not always appear in a 129 // semantic effect. They can be deleted so they might not always appear in a
127 // pair. 130 // pair.
128 const string16 StripWrappingBidiControlCharacters(const string16& text) 131 BASE_I18N_EXPORT const string16 StripWrappingBidiControlCharacters(
129 WARN_UNUSED_RESULT; 132 const string16& text) WARN_UNUSED_RESULT;
130 133
131 } // namespace i18n 134 } // namespace i18n
132 } // namespace base 135 } // namespace base
133 136
134 #endif // BASE_I18N_RTL_H_ 137 #endif // BASE_I18N_RTL_H_
OLDNEW
« no previous file with comments | « base/i18n/number_formatting.h ('k') | base/i18n/time_formatting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698