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 part of intl; | 5 part of intl; |
6 | 6 |
7 /** | 7 /** |
8 * Bidi stands for Bi-directional text. | 8 * Bidi stands for Bi-directional text. |
9 * According to http://en.wikipedia.org/wiki/Bi-directional_text: | 9 * According to http://en.wikipedia.org/wiki/Bi-directional_text: |
10 * Bi-directional text is text containing text in both text directionalities, | 10 * Bi-directional text is text containing text in both text directionalities, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 * The languages usually written in a right-to-left script are taken as those | 179 * The languages usually written in a right-to-left script are taken as those |
180 * with Suppress-Script: Hebr|Arab|Thaa|Nkoo|Tfng in | 180 * with Suppress-Script: Hebr|Arab|Thaa|Nkoo|Tfng in |
181 * http://www.iana.org/assignments/language-subtag-registry, | 181 * http://www.iana.org/assignments/language-subtag-registry, |
182 * as well as Sindhi (sd) and Uyghur (ug). | 182 * as well as Sindhi (sd) and Uyghur (ug). |
183 * The presence of other subtags of the language code, e.g. regions like EG | 183 * The presence of other subtags of the language code, e.g. regions like EG |
184 * (Egypt), is ignored. | 184 * (Egypt), is ignored. |
185 */ | 185 */ |
186 static bool isRtlLanguage(String languageString) { | 186 static bool isRtlLanguage(String languageString) { |
187 return new RegExp(r'^(ar|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_]' | 187 return new RegExp(r'^(ar|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_]' |
188 r'(Arab|Hebr|Thaa|Nkoo|Tfng))(?!.*[-_](Latn|Cyrl)($|-|_))' | 188 r'(Arab|Hebr|Thaa|Nkoo|Tfng))(?!.*[-_](Latn|Cyrl)($|-|_))' |
189 r'($|-|_)', ignoreCase : true).hasMatch(languageString); | 189 r'($|-|_)', caseSensitive: false).hasMatch(languageString); |
190 } | 190 } |
191 | 191 |
192 /** | 192 /** |
193 * Enforce the [html] snippet in RTL directionality regardless of overall | 193 * Enforce the [html] snippet in RTL directionality regardless of overall |
194 * context. If the html piece was enclosed by a tag, the direction will be | 194 * context. If the html piece was enclosed by a tag, the direction will be |
195 * applied to existing tag, otherwise a span tag will be added as wrapper. | 195 * applied to existing tag, otherwise a span tag will be added as wrapper. |
196 * For this reason, if html snippet start with with tag, this tag must enclose | 196 * For this reason, if html snippet start with with tag, this tag must enclose |
197 * the whole piece. If the tag already has a direction specified, this new one | 197 * the whole piece. If the tag already has a direction specified, this new one |
198 * will override existing one in behavior (should work on Chrome, FF, and IE | 198 * will override existing one in behavior (should work on Chrome, FF, and IE |
199 * since this was ported directly from the Closure version). | 199 * since this was ported directly from the Closure version). |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } | 394 } |
395 | 395 |
396 /** | 396 /** |
397 * Check the estimated directionality of [str], return true if the piece of | 397 * Check the estimated directionality of [str], return true if the piece of |
398 * text should be laid out in RTL direction. If [isHtml] is true, the string | 398 * text should be laid out in RTL direction. If [isHtml] is true, the string |
399 * is HTML or HTML-escaped. | 399 * is HTML or HTML-escaped. |
400 */ | 400 */ |
401 static bool detectRtlDirectionality(String str, {bool isHtml: false}) { | 401 static bool detectRtlDirectionality(String str, {bool isHtml: false}) { |
402 return estimateDirectionOfText(str, isHtml: isHtml) == TextDirection.RTL; | 402 return estimateDirectionOfText(str, isHtml: isHtml) == TextDirection.RTL; |
403 } | 403 } |
404 } | 404 } |
OLD | NEW |