summaryrefslogtreecommitdiffstats
path: root/base/i18n/rtl.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-23 15:35:25 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-23 15:35:25 +0000
commite5366896e9ccb3dd17c590d115bd999e987a33af (patch)
tree52f4fc2f07b73aaca1199adb1384b123130c22ed /base/i18n/rtl.cc
parentb133cc2db84fc83d5c4aa53020237788fa344c75 (diff)
downloadchromium_src-e5366896e9ccb3dd17c590d115bd999e987a33af.zip
chromium_src-e5366896e9ccb3dd17c590d115bd999e987a33af.tar.gz
chromium_src-e5366896e9ccb3dd17c590d115bd999e987a33af.tar.bz2
Replace wstring with string16 in history. The only time wstring is used now in history is for bookmark-related stuff (the bookmarks system is still wstring-based).
The substantial change here is in RTL to make a string16 variant of the functions and in changing the WordIterator to use string16 (this cleaned up some weird utf-32 code). TEST=none BUG=none Review URL: http://codereview.chromium.org/2808017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50597 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/i18n/rtl.cc')
-rw-r--r--base/i18n/rtl.cc67
1 files changed, 54 insertions, 13 deletions
diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc
index 9fbf35e..65973bd 100644
--- a/base/i18n/rtl.cc
+++ b/base/i18n/rtl.cc
@@ -102,13 +102,8 @@ TextDirection GetTextDirectionForLocale(const char* locale_name) {
return (layout_dir != ULOC_LAYOUT_RTL) ? LEFT_TO_RIGHT : RIGHT_TO_LEFT;
}
-TextDirection GetFirstStrongCharacterDirection(const std::wstring& text) {
-#if defined(WCHAR_T_IS_UTF32)
- string16 text_utf16 = WideToUTF16(text);
- const UChar* string = text_utf16.c_str();
-#else
+TextDirection GetFirstStrongCharacterDirection(const string16& text) {
const UChar* string = text.c_str();
-#endif
size_t length = text.length();
size_t position = 0;
while (position < length) {
@@ -136,8 +131,14 @@ TextDirection GetFirstStrongCharacterDirection(const std::wstring& text) {
return LEFT_TO_RIGHT;
}
-bool AdjustStringForLocaleDirection(const std::wstring& text,
- std::wstring* localized_text) {
+#if defined(WCHAR_T_IS_UTF32)
+TextDirection GetFirstStrongCharacterDirection(const std::wstring& text) {
+ return GetFirstStrongCharacterDirection(WideToUTF16(text));
+}
+#endif
+
+bool AdjustStringForLocaleDirection(const string16& text,
+ string16* localized_text) {
if (!IsRTL() || text.empty())
return false;
@@ -153,13 +154,21 @@ bool AdjustStringForLocaleDirection(const std::wstring& text,
return true;
}
-bool StringContainsStrongRTLChars(const std::wstring& text) {
#if defined(WCHAR_T_IS_UTF32)
- string16 text_utf16 = WideToUTF16(text);
- const UChar* string = text_utf16.c_str();
-#else
- const UChar* string = text.c_str();
+bool AdjustStringForLocaleDirection(const std::wstring& text,
+ std::wstring* localized_text) {
+ string16 out;
+ if (AdjustStringForLocaleDirection(WideToUTF16(text), &out)) {
+ // We should only touch the output on success.
+ *localized_text = UTF16ToWide(out);
+ return true;
+ }
+ return false;
+}
#endif
+
+bool StringContainsStrongRTLChars(const string16& text) {
+ const UChar* string = text.c_str();
size_t length = text.length();
size_t position = 0;
while (position < length) {
@@ -179,6 +188,24 @@ bool StringContainsStrongRTLChars(const std::wstring& text) {
return false;
}
+#if defined(WCHAR_T_IS_UTF32)
+bool StringContainsStrongRTLChars(const std::wstring& text) {
+ return StringContainsStrongRTLChars(WideToUTF16(text));
+}
+#endif
+
+void WrapStringWithLTRFormatting(string16* text) {
+ if (text->empty())
+ return;
+
+ // Inserting an LRE (Left-To-Right Embedding) mark as the first character.
+ text->insert(0, 1, kLeftToRightEmbeddingMark);
+
+ // Inserting a PDF (Pop Directional Formatting) mark as the last character.
+ text->push_back(kPopDirectionalFormatting);
+}
+
+#if defined(WCHAR_T_IS_UTF32)
void WrapStringWithLTRFormatting(std::wstring* text) {
if (text->empty())
return;
@@ -189,7 +216,20 @@ void WrapStringWithLTRFormatting(std::wstring* text) {
// Inserting a PDF (Pop Directional Formatting) mark as the last character.
text->push_back(static_cast<wchar_t>(kPopDirectionalFormatting));
}
+#endif
+
+void WrapStringWithRTLFormatting(string16* text) {
+ if (text->empty())
+ return;
+
+ // Inserting an RLE (Right-To-Left Embedding) mark as the first character.
+ text->insert(0, 1, kRightToLeftEmbeddingMark);
+ // Inserting a PDF (Pop Directional Formatting) mark as the last character.
+ text->push_back(kPopDirectionalFormatting);
+}
+
+#if defined(WCHAR_T_IS_UTF32)
void WrapStringWithRTLFormatting(std::wstring* text) {
if (text->empty())
return;
@@ -200,6 +240,7 @@ void WrapStringWithRTLFormatting(std::wstring* text) {
// Inserting a PDF (Pop Directional Formatting) mark as the last character.
text->push_back(static_cast<wchar_t>(kPopDirectionalFormatting));
}
+#endif
void WrapPathWithLTRFormatting(const FilePath& path,
string16* rtl_safe_path) {