diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 00:24:20 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 00:24:20 +0000 |
commit | 883ce72de20ef56c3c332215c12f14886b67bf8e (patch) | |
tree | 01bb9b4b848f52ad91e4b151f935dbf7f2fa00fd /base | |
parent | 4f2fe461d79175b39787686b76d36b7518e132fd (diff) | |
download | chromium_src-883ce72de20ef56c3c332215c12f14886b67bf8e.zip chromium_src-883ce72de20ef56c3c332215c12f14886b67bf8e.tar.gz chromium_src-883ce72de20ef56c3c332215c12f14886b67bf8e.tar.bz2 |
Small cleanups/style fixes. Simplifies RTL functions slightly.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1932006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46419 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/i18n/rtl.cc | 32 | ||||
-rw-r--r-- | base/i18n/rtl.h | 19 |
2 files changed, 23 insertions, 28 deletions
diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc index 52f7de7..4755a94 100644 --- a/base/i18n/rtl.cc +++ b/base/i18n/rtl.cc @@ -77,25 +77,21 @@ void SetICUDefaultLocale(const std::string& locale_string) { g_icu_text_direction = UNKNOWN_DIRECTION; } -TextDirection GetICUTextDirection() { - if (g_icu_text_direction == UNKNOWN_DIRECTION) { - const icu::Locale& locale = icu::Locale::getDefault(); - g_icu_text_direction = GetTextDirectionForLocale(locale.getName()); - } - return g_icu_text_direction; -} - -TextDirection GetTextDirection() { +bool IsRTL() { #if defined(TOOLKIT_GTK) GtkTextDirection gtk_dir = gtk_widget_get_default_direction(); - return (gtk_dir == GTK_TEXT_DIR_LTR) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT; + return (gtk_dir == GTK_TEXT_DIR_RTL); #else - return GetICUTextDirection(); + return ICUIsRTL(); #endif } -bool IsRTL() { - return GetTextDirection() == RIGHT_TO_LEFT; +bool ICUIsRTL() { + if (g_icu_text_direction == UNKNOWN_DIRECTION) { + const icu::Locale& locale = icu::Locale::getDefault(); + g_icu_text_direction = GetTextDirectionForLocale(locale.getName()); + } + return g_icu_text_direction == RIGHT_TO_LEFT; } TextDirection GetTextDirectionForLocale(const char* locale_name) { @@ -142,7 +138,7 @@ TextDirection GetFirstStrongCharacterDirection(const std::wstring& text) { bool AdjustStringForLocaleDirection(const std::wstring& text, std::wstring* localized_text) { - if (GetTextDirection() == LEFT_TO_RIGHT || text.length() == 0) + if (!IsRTL() || text.empty()) return false; // Marking the string as LTR if the locale is RTL and the string does not @@ -184,6 +180,9 @@ bool StringContainsStrongRTLChars(const std::wstring& text) { } void WrapStringWithLTRFormatting(std::wstring* text) { + if (text->empty()) + return; + // Inserting an LRE (Left-To-Right Embedding) mark as the first character. text->insert(0, 1, static_cast<wchar_t>(kLeftToRightEmbeddingMark)); @@ -192,6 +191,9 @@ void WrapStringWithLTRFormatting(std::wstring* text) { } void WrapStringWithRTLFormatting(std::wstring* text) { + if (text->empty()) + return; + // Inserting an RLE (Right-To-Left Embedding) mark as the first character. text->insert(0, 1, static_cast<wchar_t>(kRightToLeftEmbeddingMark)); @@ -218,7 +220,7 @@ void WrapPathWithLTRFormatting(const FilePath& path, } std::wstring GetDisplayStringInLTRDirectionality(std::wstring* text) { - if (GetTextDirection() == RIGHT_TO_LEFT) + if (IsRTL()) WrapStringWithLTRFormatting(text); return *text; } diff --git a/base/i18n/rtl.h b/base/i18n/rtl.h index 05a5ff0..70cd9d3 100644 --- a/base/i18n/rtl.h +++ b/base/i18n/rtl.h @@ -18,7 +18,6 @@ const char16 kLeftToRightEmbeddingMark = 0x202A; const char16 kRightToLeftEmbeddingMark = 0x202B; const char16 kPopDirectionalFormatting = 0x202C; -// Represents the text direction returned by the GetTextDirection() function. enum TextDirection { UNKNOWN_DIRECTION, RIGHT_TO_LEFT, @@ -37,21 +36,15 @@ void GetLanguageAndRegionFromOS(std::string* lang, std::string* region); // that this is called before any locale-dependent API is called. void SetICUDefaultLocale(const std::string& locale_string); -// Returns the text direction for the default ICU locale. It is assumed -// that SetICUDefaultLocale has been called to set the default locale to -// the UI locale of Chrome. Its return is one of the following three: -// * LEFT_TO_RIGHT: Left-To-Right (e.g. English, Chinese, etc.); -// * RIGHT_TO_LEFT: Right-To-Left (e.g. Arabic, Hebrew, etc.), and; -// * UNKNOWN_DIRECTION: unknown (or error). -TextDirection GetICUTextDirection(); - -// Get the application text direction. (This is just the ICU direction, -// except on GTK.) -TextDirection GetTextDirection(); - // Returns true if the application text direction is right-to-left. bool IsRTL(); +// Returns whether the text direction for the default ICU locale is RTL. This +// assumes that SetICUDefaultLocale has been called to set the default locale to +// the UI locale of Chrome. +// NOTE: Generally, you should call IsRTL() instead of this. +bool ICUIsRTL(); + // Returns the text direction for |locale_name|. TextDirection GetTextDirectionForLocale(const char* locale_name); |