| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 if (!ui_direction_is_rtl && has_rtl_chars) { | 264 if (!ui_direction_is_rtl && has_rtl_chars) { |
| 265 WrapStringWithRTLFormatting(text); | 265 WrapStringWithRTLFormatting(text); |
| 266 text->insert(0U, 1U, kLeftToRightMark); | 266 text->insert(static_cast<size_t>(0), static_cast<size_t>(1), |
| 267 kLeftToRightMark); |
| 267 text->push_back(kLeftToRightMark); | 268 text->push_back(kLeftToRightMark); |
| 268 } else if (ui_direction_is_rtl && has_rtl_chars) { | 269 } else if (ui_direction_is_rtl && has_rtl_chars) { |
| 269 WrapStringWithRTLFormatting(text); | 270 WrapStringWithRTLFormatting(text); |
| 270 text->insert(0U, 1U, kRightToLeftMark); | 271 text->insert(static_cast<size_t>(0), static_cast<size_t>(1), |
| 272 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(static_cast<size_t>(0), static_cast<size_t>(1), |
| 277 kRightToLeftMark); |
| 275 text->push_back(kRightToLeftMark); | 278 text->push_back(kRightToLeftMark); |
| 276 } else { | 279 } else { |
| 277 return false; | 280 return false; |
| 278 } | 281 } |
| 279 | 282 |
| 280 return true; | 283 return true; |
| 281 } | 284 } |
| 282 | 285 |
| 283 bool UnadjustStringForLocaleDirection(string16* text) { | 286 bool UnadjustStringForLocaleDirection(string16* text) { |
| 284 if (text->empty()) | 287 if (text->empty()) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 328 } |
| 326 | 329 |
| 327 return false; | 330 return false; |
| 328 } | 331 } |
| 329 | 332 |
| 330 void WrapStringWithLTRFormatting(string16* text) { | 333 void WrapStringWithLTRFormatting(string16* text) { |
| 331 if (text->empty()) | 334 if (text->empty()) |
| 332 return; | 335 return; |
| 333 | 336 |
| 334 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. | 337 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. |
| 335 text->insert(0U, 1U, kLeftToRightEmbeddingMark); | 338 text->insert(static_cast<size_t>(0), static_cast<size_t>(1), |
| 339 kLeftToRightEmbeddingMark); |
| 336 | 340 |
| 337 // Inserting a PDF (Pop Directional Formatting) mark as the last character. | 341 // Inserting a PDF (Pop Directional Formatting) mark as the last character. |
| 338 text->push_back(kPopDirectionalFormatting); | 342 text->push_back(kPopDirectionalFormatting); |
| 339 } | 343 } |
| 340 | 344 |
| 341 void WrapStringWithRTLFormatting(string16* text) { | 345 void WrapStringWithRTLFormatting(string16* text) { |
| 342 if (text->empty()) | 346 if (text->empty()) |
| 343 return; | 347 return; |
| 344 | 348 |
| 345 // Inserting an RLE (Right-To-Left Embedding) mark as the first character. | 349 // Inserting an RLE (Right-To-Left Embedding) mark as the first character. |
| 346 text->insert(0U, 1U, kRightToLeftEmbeddingMark); | 350 text->insert(static_cast<size_t>(0), static_cast<size_t>(1), |
| 351 kRightToLeftEmbeddingMark); |
| 347 | 352 |
| 348 // Inserting a PDF (Pop Directional Formatting) mark as the last character. | 353 // Inserting a PDF (Pop Directional Formatting) mark as the last character. |
| 349 text->push_back(kPopDirectionalFormatting); | 354 text->push_back(kPopDirectionalFormatting); |
| 350 } | 355 } |
| 351 | 356 |
| 352 void WrapPathWithLTRFormatting(const FilePath& path, | 357 void WrapPathWithLTRFormatting(const FilePath& path, |
| 353 string16* rtl_safe_path) { | 358 string16* rtl_safe_path) { |
| 354 // Wrap the overall path with LRE-PDF pair which essentialy marks the | 359 // Wrap the overall path with LRE-PDF pair which essentialy marks the |
| 355 // string as a Left-To-Right string. | 360 // string as a Left-To-Right string. |
| 356 // Inserting an LRE (Left-To-Right Embedding) mark as the first character. | 361 // 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) | 394 begin == kRightToLeftOverride) |
| 390 ++begin_index; | 395 ++begin_index; |
| 391 size_t end_index = text.length() - 1; | 396 size_t end_index = text.length() - 1; |
| 392 if (text[end_index] == kPopDirectionalFormatting) | 397 if (text[end_index] == kPopDirectionalFormatting) |
| 393 --end_index; | 398 --end_index; |
| 394 return text.substr(begin_index, end_index - begin_index + 1); | 399 return text.substr(begin_index, end_index - begin_index + 1); |
| 395 } | 400 } |
| 396 | 401 |
| 397 } // namespace i18n | 402 } // namespace i18n |
| 398 } // namespace base | 403 } // namespace base |
| OLD | NEW |