OLD | NEW |
---|---|
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/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 | 254 |
255 // Unlike Windows, Linux and OS X can correctly display RTL glyphs out of the | 255 // Unlike Windows, Linux and OS X can correctly display RTL glyphs out of the |
256 // box so there is no issue with displaying zero-width bidi control characters | 256 // box so there is no issue with displaying zero-width bidi control characters |
257 // on any system. Thus no need for the !IsRTL() check here. | 257 // on any system. Thus no need for the !IsRTL() check here. |
258 if (text->empty()) | 258 if (text->empty()) |
259 return false; | 259 return false; |
260 | 260 |
261 bool ui_direction_is_rtl = IsRTL(); | 261 bool ui_direction_is_rtl = IsRTL(); |
262 | 262 |
263 bool has_rtl_chars = StringContainsStrongRTLChars(*text); | 263 bool has_rtl_chars = StringContainsStrongRTLChars(*text); |
264 const size_t pos = 0; | |
265 const size_t num = 1; | |
264 if (!ui_direction_is_rtl && has_rtl_chars) { | 266 if (!ui_direction_is_rtl && has_rtl_chars) { |
265 WrapStringWithRTLFormatting(text); | 267 WrapStringWithRTLFormatting(text); |
266 text->insert(0U, 1U, kLeftToRightMark); | 268 text->insert(pos, num, kLeftToRightMark); |
rmcilroy
2014/02/25 11:01:37
Is this change really necessary? This file is alr
rmcilroy
2014/02/26 15:14:31
Please just do a static_cast<size_t>(0) here (and
| |
267 text->push_back(kLeftToRightMark); | 269 text->push_back(kLeftToRightMark); |
268 } else if (ui_direction_is_rtl && has_rtl_chars) { | 270 } else if (ui_direction_is_rtl && has_rtl_chars) { |
269 WrapStringWithRTLFormatting(text); | 271 WrapStringWithRTLFormatting(text); |
270 text->insert(0U, 1U, kRightToLeftMark); | 272 text->insert(pos, num, kRightToLeftMark); |
271 text->push_back(kRightToLeftMark); | 273 text->push_back(kRightToLeftMark); |
272 } else if (ui_direction_is_rtl) { | 274 } else if (ui_direction_is_rtl) { |
273 WrapStringWithLTRFormatting(text); | 275 WrapStringWithLTRFormatting(text); |
274 text->insert(0U, 1U, kRightToLeftMark); | 276 text->insert(pos, num, kRightToLeftMark); |
275 text->push_back(kRightToLeftMark); | 277 text->push_back(kRightToLeftMark); |
276 } else { | 278 } else { |
277 return false; | 279 return false; |
278 } | 280 } |
279 | 281 |
280 return true; | 282 return true; |
281 } | 283 } |
282 | 284 |
283 bool UnadjustStringForLocaleDirection(string16* text) { | 285 bool UnadjustStringForLocaleDirection(string16* text) { |
284 if (text->empty()) | 286 if (text->empty()) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 } | 327 } |
326 | 328 |
327 return false; | 329 return false; |
328 } | 330 } |
329 | 331 |
330 void WrapStringWithLTRFormatting(string16* text) { | 332 void WrapStringWithLTRFormatting(string16* text) { |
331 if (text->empty()) | 333 if (text->empty()) |
332 return; | 334 return; |
333 | 335 |
334 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. | 336 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. |
335 text->insert(0U, 1U, kLeftToRightEmbeddingMark); | 337 text->insert(static_cast<size_t>(0), static_cast<size_t>(1), |
338 kLeftToRightEmbeddingMark); | |
336 | 339 |
337 // Inserting a PDF (Pop Directional Formatting) mark as the last character. | 340 // Inserting a PDF (Pop Directional Formatting) mark as the last character. |
338 text->push_back(kPopDirectionalFormatting); | 341 text->push_back(kPopDirectionalFormatting); |
339 } | 342 } |
340 | 343 |
341 void WrapStringWithRTLFormatting(string16* text) { | 344 void WrapStringWithRTLFormatting(string16* text) { |
342 if (text->empty()) | 345 if (text->empty()) |
343 return; | 346 return; |
344 | 347 |
345 // Inserting an RLE (Right-To-Left Embedding) mark as the first character. | 348 // Inserting an RLE (Right-To-Left Embedding) mark as the first character. |
346 text->insert(0U, 1U, kRightToLeftEmbeddingMark); | 349 text->insert(static_cast<size_t>(0), static_cast<size_t>(1), |
350 kRightToLeftEmbeddingMark); | |
347 | 351 |
348 // Inserting a PDF (Pop Directional Formatting) mark as the last character. | 352 // Inserting a PDF (Pop Directional Formatting) mark as the last character. |
349 text->push_back(kPopDirectionalFormatting); | 353 text->push_back(kPopDirectionalFormatting); |
350 } | 354 } |
351 | 355 |
352 void WrapPathWithLTRFormatting(const FilePath& path, | 356 void WrapPathWithLTRFormatting(const FilePath& path, |
353 string16* rtl_safe_path) { | 357 string16* rtl_safe_path) { |
354 // Wrap the overall path with LRE-PDF pair which essentialy marks the | 358 // Wrap the overall path with LRE-PDF pair which essentialy marks the |
355 // string as a Left-To-Right string. | 359 // string as a Left-To-Right string. |
356 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. | 360 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 begin == kRightToLeftOverride) | 393 begin == kRightToLeftOverride) |
390 ++begin_index; | 394 ++begin_index; |
391 size_t end_index = text.length() - 1; | 395 size_t end_index = text.length() - 1; |
392 if (text[end_index] == kPopDirectionalFormatting) | 396 if (text[end_index] == kPopDirectionalFormatting) |
393 --end_index; | 397 --end_index; |
394 return text.substr(begin_index, end_index - begin_index + 1); | 398 return text.substr(begin_index, end_index - begin_index + 1); |
395 } | 399 } |
396 | 400 |
397 } // namespace i18n | 401 } // namespace i18n |
398 } // namespace base | 402 } // namespace base |
OLD | NEW |