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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 size_t next_position = position; | 156 size_t next_position = position; |
157 U16_NEXT(string, next_position, length, character); | 157 U16_NEXT(string, next_position, length, character); |
158 TextDirection direction = GetCharacterDirection(character); | 158 TextDirection direction = GetCharacterDirection(character); |
159 if (direction != UNKNOWN_DIRECTION) | 159 if (direction != UNKNOWN_DIRECTION) |
160 return direction; | 160 return direction; |
161 position = next_position; | 161 position = next_position; |
162 } | 162 } |
163 return LEFT_TO_RIGHT; | 163 return LEFT_TO_RIGHT; |
164 } | 164 } |
165 | 165 |
| 166 TextDirection GetLastStrongCharacterDirection(const string16& text) { |
| 167 const UChar* string = text.c_str(); |
| 168 size_t position = text.length(); |
| 169 while (position > 0) { |
| 170 UChar32 character; |
| 171 size_t prev_position = position; |
| 172 U16_PREV(string, 0, prev_position, character); |
| 173 TextDirection direction = GetCharacterDirection(character); |
| 174 if (direction != UNKNOWN_DIRECTION) |
| 175 return direction; |
| 176 position = prev_position; |
| 177 } |
| 178 return LEFT_TO_RIGHT; |
| 179 } |
| 180 |
166 TextDirection GetStringDirection(const string16& text) { | 181 TextDirection GetStringDirection(const string16& text) { |
167 const UChar* string = text.c_str(); | 182 const UChar* string = text.c_str(); |
168 size_t length = text.length(); | 183 size_t length = text.length(); |
169 size_t position = 0; | 184 size_t position = 0; |
170 | 185 |
171 TextDirection result(UNKNOWN_DIRECTION); | 186 TextDirection result(UNKNOWN_DIRECTION); |
172 while (position < length) { | 187 while (position < length) { |
173 UChar32 character; | 188 UChar32 character; |
174 size_t next_position = position; | 189 size_t next_position = position; |
175 U16_NEXT(string, next_position, length, character); | 190 U16_NEXT(string, next_position, length, character); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 begin == kRightToLeftOverride) | 389 begin == kRightToLeftOverride) |
375 ++begin_index; | 390 ++begin_index; |
376 size_t end_index = text.length() - 1; | 391 size_t end_index = text.length() - 1; |
377 if (text[end_index] == kPopDirectionalFormatting) | 392 if (text[end_index] == kPopDirectionalFormatting) |
378 --end_index; | 393 --end_index; |
379 return text.substr(begin_index, end_index - begin_index + 1); | 394 return text.substr(begin_index, end_index - begin_index + 1); |
380 } | 395 } |
381 | 396 |
382 } // namespace i18n | 397 } // namespace i18n |
383 } // namespace base | 398 } // namespace base |
OLD | NEW |