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

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

Issue 10910128: Check string and UI direction in GetDisplayStringInLTRDirectionality, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 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/rtl.h ('k') | base/i18n/rtl_unittest.cc » ('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 #include "base/i18n/rtl.h" 5 #include "base/i18n/rtl.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 rtl_safe_path->append(path.value()); 312 rtl_safe_path->append(path.value());
313 #else // defined(OS_POSIX) && !defined(OS_MACOSX) 313 #else // defined(OS_POSIX) && !defined(OS_MACOSX)
314 std::wstring wide_path = base::SysNativeMBToWide(path.value()); 314 std::wstring wide_path = base::SysNativeMBToWide(path.value());
315 rtl_safe_path->append(WideToUTF16(wide_path)); 315 rtl_safe_path->append(WideToUTF16(wide_path));
316 #endif 316 #endif
317 // Inserting a PDF (Pop Directional Formatting) mark as the last character. 317 // Inserting a PDF (Pop Directional Formatting) mark as the last character.
318 rtl_safe_path->push_back(kPopDirectionalFormatting); 318 rtl_safe_path->push_back(kPopDirectionalFormatting);
319 } 319 }
320 320
321 string16 GetDisplayStringInLTRDirectionality(const string16& text) { 321 string16 GetDisplayStringInLTRDirectionality(const string16& text) {
322 if (!IsRTL()) 322 // Always wrap the string in RTL UI (it may be appended to RTL string).
323 return text; 323 // Also wrap strings with an RTL first strong character direction in LTR UI.
324 string16 text_mutable(text); 324 if (IsRTL() || GetFirstStrongCharacterDirection(text) == RIGHT_TO_LEFT) {
325 WrapStringWithLTRFormatting(&text_mutable); 325 string16 text_mutable(text);
326 return text_mutable; 326 WrapStringWithLTRFormatting(&text_mutable);
327 return text_mutable;
328 }
329 return text;
327 } 330 }
328 331
329 string16 StripWrappingBidiControlCharacters(const string16& text) { 332 string16 StripWrappingBidiControlCharacters(const string16& text) {
330 if (text.empty()) 333 if (text.empty())
331 return text; 334 return text;
332 size_t begin_index = 0; 335 size_t begin_index = 0;
333 char16 begin = text[begin_index]; 336 char16 begin = text[begin_index];
334 if (begin == kLeftToRightEmbeddingMark || 337 if (begin == kLeftToRightEmbeddingMark ||
335 begin == kRightToLeftEmbeddingMark || 338 begin == kRightToLeftEmbeddingMark ||
336 begin == kLeftToRightOverride || 339 begin == kLeftToRightOverride ||
337 begin == kRightToLeftOverride) 340 begin == kRightToLeftOverride)
338 ++begin_index; 341 ++begin_index;
339 size_t end_index = text.length() - 1; 342 size_t end_index = text.length() - 1;
340 if (text[end_index] == kPopDirectionalFormatting) 343 if (text[end_index] == kPopDirectionalFormatting)
341 --end_index; 344 --end_index;
342 return text.substr(begin_index, end_index - begin_index + 1); 345 return text.substr(begin_index, end_index - begin_index + 1);
343 } 346 }
344 347
345 } // namespace i18n 348 } // namespace i18n
346 } // namespace base 349 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/rtl.h ('k') | base/i18n/rtl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698