Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Bidi stands for Bi-directional text. | 6 * Bidi stands for Bi-directional text. |
| 7 * According to http://en.wikipedia.org/wiki/Bi-directional_text: | 7 * According to http://en.wikipedia.org/wiki/Bi-directional_text: |
| 8 * Bi-directional text is text containing text in both text directionalities, | 8 * Bi-directional text is text containing text in both text directionalities, |
| 9 * both right-to-left (RTL) and left-to-right (LTR). It generally involves text | 9 * both right-to-left (RTL) and left-to-right (LTR). It generally involves text |
| 10 * containing different types of alphabets, but may also refer to boustrophedon, | 10 * containing different types of alphabets, but may also refer to boustrophedon, |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 * general-purpose method (using relative word counts). A | 308 * general-purpose method (using relative word counts). A |
| 309 * TextDirection.UNKNOWN return value indicates completely neutral input. | 309 * TextDirection.UNKNOWN return value indicates completely neutral input. |
| 310 * [isHtml] is true if [text] HTML or HTML-escaped. | 310 * [isHtml] is true if [text] HTML or HTML-escaped. |
| 311 * | 311 * |
| 312 * If the number of RTL words is above a certain percentage of the total | 312 * If the number of RTL words is above a certain percentage of the total |
| 313 * number of strongly directional words, returns RTL. | 313 * number of strongly directional words, returns RTL. |
| 314 * Otherwise, if any words are strongly or weakly LTR, returns LTR. | 314 * Otherwise, if any words are strongly or weakly LTR, returns LTR. |
| 315 * Otherwise, returns UNKNOWN, which is used to mean `neutral`. | 315 * Otherwise, returns UNKNOWN, which is used to mean `neutral`. |
| 316 * Numbers and URLs are counted as weakly LTR. | 316 * Numbers and URLs are counted as weakly LTR. |
| 317 */ | 317 */ |
| 318 static TextDirection estimateDirectionOfText(String text, [bool isHtml=false]) { | 318 static TextDirection estimateDirectionOfText(String text, |
| 319 {bool isHtml: false}) { | |
| 319 text = isHtml? stripHtmlIfNeeded(text) : text; | 320 text = isHtml? stripHtmlIfNeeded(text) : text; |
| 320 var rtlCount = 0; | 321 var rtlCount = 0; |
| 321 var total = 0; | 322 var total = 0; |
| 322 var hasWeaklyLtr = false; | 323 var hasWeaklyLtr = false; |
| 323 // Split a string into 'words' for directionality estimation based on | 324 // Split a string into 'words' for directionality estimation based on |
| 324 // relative word counts. | 325 // relative word counts. |
| 325 for (String token in text.split(const RegExp(r'\s+'))) { | 326 for (String token in text.split(const RegExp(r'\s+'))) { |
| 326 if (startsWithRtl(token)) { | 327 if (startsWithRtl(token)) { |
| 327 rtlCount++; | 328 rtlCount++; |
| 328 total++; | 329 total++; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 } | 387 } |
| 387 } | 388 } |
| 388 return buf.toString(); | 389 return buf.toString(); |
| 389 } | 390 } |
| 390 | 391 |
| 391 /** | 392 /** |
| 392 * Check the estimated directionality of [str], return true if the piece of | 393 * Check the estimated directionality of [str], return true if the piece of |
| 393 * text should be laid out in RTL direction. If [isHtml] is true, the string | 394 * text should be laid out in RTL direction. If [isHtml] is true, the string |
| 394 * is HTML or HTML-escaped. | 395 * is HTML or HTML-escaped. |
| 395 */ | 396 */ |
| 396 static bool detectRtlDirectionality(String str, [bool isHtml]) { | 397 static bool detectRtlDirectionality(String str, {bool isHtml}) { |
|
Lasse Reichstein Nielsen
2012/10/17 14:56:10
Give it a default value of false, instead of relyi
regis
2012/10/17 19:58:16
Done. But I need to postpone these changes in bidi
| |
| 397 return estimateDirectionOfText(str, isHtml) == TextDirection.RTL; | 398 return estimateDirectionOfText(str, isHtml: isHtml) == TextDirection.RTL; |
| 398 } | 399 } |
| 399 } | 400 } |
| OLD | NEW |