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

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

Issue 7741032: Upstream android i18n change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 4 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_unittest.cc ('k') | no next file » | 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // box so there is no issue with displaying zero-width bidi control characters 208 // box so there is no issue with displaying zero-width bidi control characters
209 // on any system. Thus no need for the !IsRTL() check here. 209 // on any system. Thus no need for the !IsRTL() check here.
210 if (text->empty()) 210 if (text->empty())
211 return false; 211 return false;
212 212
213 bool ui_direction_is_rtl = IsRTL(); 213 bool ui_direction_is_rtl = IsRTL();
214 214
215 bool has_rtl_chars = StringContainsStrongRTLChars(*text); 215 bool has_rtl_chars = StringContainsStrongRTLChars(*text);
216 if (!ui_direction_is_rtl && has_rtl_chars) { 216 if (!ui_direction_is_rtl && has_rtl_chars) {
217 WrapStringWithRTLFormatting(text); 217 WrapStringWithRTLFormatting(text);
218 text->insert(0, 1, kLeftToRightMark); 218 text->insert(0U, 1U, kLeftToRightMark);
219 text->push_back(kLeftToRightMark); 219 text->push_back(kLeftToRightMark);
220 } else if (ui_direction_is_rtl && has_rtl_chars) { 220 } else if (ui_direction_is_rtl && has_rtl_chars) {
221 WrapStringWithRTLFormatting(text); 221 WrapStringWithRTLFormatting(text);
222 text->insert(0, 1, kRightToLeftMark); 222 text->insert(0U, 1U, kRightToLeftMark);
223 text->push_back(kRightToLeftMark); 223 text->push_back(kRightToLeftMark);
224 } else if (ui_direction_is_rtl) { 224 } else if (ui_direction_is_rtl) {
225 WrapStringWithLTRFormatting(text); 225 WrapStringWithLTRFormatting(text);
226 text->insert(0, 1, kRightToLeftMark); 226 text->insert(0U, 1U, kRightToLeftMark);
227 text->push_back(kRightToLeftMark); 227 text->push_back(kRightToLeftMark);
228 } 228 }
229 229
230 return true; 230 return true;
231 } 231 }
232 232
233 #endif // !OS_WIN 233 #endif // !OS_WIN
234 234
235 bool StringContainsStrongRTLChars(const string16& text) { 235 bool StringContainsStrongRTLChars(const string16& text) {
236 const UChar* string = text.c_str(); 236 const UChar* string = text.c_str();
(...skipping 14 matching lines...) Expand all
251 } 251 }
252 252
253 return false; 253 return false;
254 } 254 }
255 255
256 void WrapStringWithLTRFormatting(string16* text) { 256 void WrapStringWithLTRFormatting(string16* text) {
257 if (text->empty()) 257 if (text->empty())
258 return; 258 return;
259 259
260 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. 260 // Inserting an LRE (Left-To-Right Embedding) mark as the first character.
261 text->insert(0, 1, kLeftToRightEmbeddingMark); 261 text->insert(0U, 1U, kLeftToRightEmbeddingMark);
262 262
263 // Inserting a PDF (Pop Directional Formatting) mark as the last character. 263 // Inserting a PDF (Pop Directional Formatting) mark as the last character.
264 text->push_back(kPopDirectionalFormatting); 264 text->push_back(kPopDirectionalFormatting);
265 } 265 }
266 266
267 void WrapStringWithRTLFormatting(string16* text) { 267 void WrapStringWithRTLFormatting(string16* text) {
268 if (text->empty()) 268 if (text->empty())
269 return; 269 return;
270 270
271 // Inserting an RLE (Right-To-Left Embedding) mark as the first character. 271 // Inserting an RLE (Right-To-Left Embedding) mark as the first character.
272 text->insert(0, 1, kRightToLeftEmbeddingMark); 272 text->insert(0U, 1U, kRightToLeftEmbeddingMark);
273 273
274 // Inserting a PDF (Pop Directional Formatting) mark as the last character. 274 // Inserting a PDF (Pop Directional Formatting) mark as the last character.
275 text->push_back(kPopDirectionalFormatting); 275 text->push_back(kPopDirectionalFormatting);
276 } 276 }
277 277
278 void WrapPathWithLTRFormatting(const FilePath& path, 278 void WrapPathWithLTRFormatting(const FilePath& path,
279 string16* rtl_safe_path) { 279 string16* rtl_safe_path) {
280 // Wrap the overall path with LRE-PDF pair which essentialy marks the 280 // Wrap the overall path with LRE-PDF pair which essentialy marks the
281 // string as a Left-To-Right string. 281 // string as a Left-To-Right string.
282 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. 282 // Inserting an LRE (Left-To-Right Embedding) mark as the first character.
(...skipping 29 matching lines...) Expand all
312 begin == kRightToLeftOverride) 312 begin == kRightToLeftOverride)
313 ++begin_index; 313 ++begin_index;
314 size_t end_index = text.length() - 1; 314 size_t end_index = text.length() - 1;
315 if (text[end_index] == kPopDirectionalFormatting) 315 if (text[end_index] == kPopDirectionalFormatting)
316 --end_index; 316 --end_index;
317 return text.substr(begin_index, end_index - begin_index + 1); 317 return text.substr(begin_index, end_index - begin_index + 1);
318 } 318 }
319 319
320 } // namespace i18n 320 } // namespace i18n
321 } // namespace base 321 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/number_formatting_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698