Package com.google.gwt.i18n.shared
Class BidiUtils
java.lang.Object
com.google.gwt.i18n.shared.BidiUtils
Utility functions for performing common Bidi tests on strings.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
endsWithLtr
(String str) LikeendsWithLtr(String, boolean)
, but assumesstr
is not HTML / HTML-escaped.boolean
endsWithLtr
(String str, boolean isHtml) Check whether the last strongly-directional character in the string is LTR.boolean
endsWithRtl
(String str) LikeendsWithRtl(String, boolean)
, but assumesstr
is not HTML / HTML-escaped.boolean
endsWithRtl
(String str, boolean isHtml) Check whether the last strongly-directional character in the string is RTL.estimateDirection
(String str) LikeestimateDirection(String, boolean)
, but assumesstr
is not HTML / HTML-escaped.estimateDirection
(String str, boolean isHtml) Estimates the directionality of a string based on relative word counts.static BidiUtils
get()
Get an instance of BidiUtils.boolean
LikehasAnyLtr(String, boolean)
, but assumesstr
is not HTML / HTML-escaped.boolean
Checks if the given string has any LTR characters in it.boolean
LikehasAnyRtl(String, boolean)
, but assumesstr
is not HTML / HTML-escaped.boolean
Checks if the given string has any RTL characters in it.boolean
startsWithLtr
(String str) LikestartsWithLtr(String, boolean)
, but assumesstr
is not HTML / HTML-escaped.boolean
startsWithLtr
(String str, boolean isHtml) Check whether the first strongly-directional character in the string is LTR.boolean
startsWithRtl
(String str) LikestartsWithRtl(String, boolean)
, but assumesstr
is not HTML / HTML-escaped.boolean
startsWithRtl
(String str, boolean isHtml) Check whether the first strongly-directional character in the string is RTL.(package private) String
stripHtmlIfNeeded
(String str, boolean isStripNeeded) Returns the input text with spaces instead of HTML tags or HTML escapes, if isStripNeeded is true.
-
Method Details
-
get
Get an instance of BidiUtils.- Returns:
- An instance of BidiUtils
-
endsWithLtr
LikeendsWithLtr(String, boolean)
, but assumesstr
is not HTML / HTML-escaped. -
endsWithLtr
Check whether the last strongly-directional character in the string is LTR.- Parameters:
str
- the string to checkisHtml
- whether str is HTML / HTML-escaped- Returns:
- whether LTR exit directionality was detected
-
endsWithRtl
LikeendsWithRtl(String, boolean)
, but assumesstr
is not HTML / HTML-escaped. -
endsWithRtl
Check whether the last strongly-directional character in the string is RTL.- Parameters:
str
- the string to checkisHtml
- whether str is HTML / HTML-escaped- Returns:
- whether RTL exit directionality was detected
-
estimateDirection
LikeestimateDirection(String, boolean)
, but assumesstr
is not HTML / HTML-escaped. -
estimateDirection
Estimates the directionality of a string based on relative word counts. If the number of RTL words is above a certain percentage of the total number of strongly directional words, returns RTL. Otherwise, if any words are strongly or weakly LTR, returns LTR. Otherwise, returns DEFAULT, which is used to mean "neutral". Numbers are counted as weakly LTR.- Parameters:
str
- the string to checkisHtml
- whetherstr
is HTML / HTML-escaped. Use this to ignore HTML tags and escapes that would otherwise be mistaken for LTR text.- Returns:
- the string's directionality
-
hasAnyLtr
LikehasAnyLtr(String, boolean)
, but assumesstr
is not HTML / HTML-escaped.- Parameters:
str
- the string to be tested- Returns:
- whether the string contains any LTR characters
-
hasAnyLtr
Checks if the given string has any LTR characters in it.- Parameters:
str
- the string to be testedisHtml
- whether str is HTML / HTML-escaped- Returns:
- whether the string contains any LTR characters
-
hasAnyRtl
LikehasAnyRtl(String, boolean)
, but assumesstr
is not HTML / HTML-escaped.- Parameters:
str
- the string to be tested- Returns:
- whether the string contains any RTL characters
-
hasAnyRtl
Checks if the given string has any RTL characters in it.- Parameters:
str
- the string to be testedisHtml
- whether str is HTML / HTML-escaped- Returns:
- whether the string contains any RTL characters
-
startsWithLtr
LikestartsWithLtr(String, boolean)
, but assumesstr
is not HTML / HTML-escaped. -
startsWithLtr
Check whether the first strongly-directional character in the string is LTR.- Parameters:
str
- the string to checkisHtml
- whether str is HTML / HTML-escaped- Returns:
- whether LTR exit directionality was detected
-
startsWithRtl
LikestartsWithRtl(String, boolean)
, but assumesstr
is not HTML / HTML-escaped. -
startsWithRtl
Check whether the first strongly-directional character in the string is RTL.- Parameters:
str
- the string to checkisHtml
- whetherstr
is HTML / HTML-escaped- Returns:
- whether RTL exit directionality was detected
-
stripHtmlIfNeeded
Returns the input text with spaces instead of HTML tags or HTML escapes, if isStripNeeded is true. Else returns the input as is. Useful for text directionality estimation. Note: the function should not be used in other contexts; it is not 100% correct, but rather a good-enough implementation for directionality estimation purposes.
-