Class BidiAlgorithm
- All Implemented Interfaces:
Disposable
A BidiAlgorithm object provides information related to individual paragraphs in
source text by applying rule P1. It can be used to create paragraph objects by explicitly
specifying the paragraph level or deriving it from rules P2 and P3. Once a paragraph object is
created, embedding levels of characters can be queried from it.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBidiAlgorithm(String text) Constructs a bidi algorithm object for the given text. -
Method Summary
Modifier and TypeMethodDescriptioncreateParagraph(int charStart, int charEnd, byte baseLevel) Creates a paragraph object processed with Unicode Bidirectional Algorithm.createParagraph(int charStart, int charEnd, BaseDirection baseDirection) Creates a paragraph object processed with Unicode Bidirectional Algorithm.voiddispose()Releases the native memory of this object.static BidiAlgorithmfinalizable(BidiAlgorithm bidiAlgorithm) Wraps a bidi algorithm object into a finalizable instance which is guaranteed to be disposed automatically by the GC when no longer in use.Returns a list containing the bidi classes of all characters in source text.intgetParagraphBoundary(int charStart, int charEnd) Returns the boundary of the first paragraph within the given range.static booleanisFinalizable(BidiAlgorithm bidiAlgorithm) Checks whether a bidi algorithm object is finalizable or not.toString()
-
Field Details
-
MAX_LEVEL
public static final byte MAX_LEVELMaximum explicit embedding level.- See Also:
-
-
Constructor Details
-
BidiAlgorithm
Constructs a bidi algorithm object for the given text.- Parameters:
text- The text to apply unicode bidirectional algorithm on.- Throws:
IllegalArgumentException- iftextis empty.
-
-
Method Details
-
finalizable
Wraps a bidi algorithm object into a finalizable instance which is guaranteed to be disposed automatically by the GC when no longer in use. After calling this method,dispose()should not be called on either original object or returned object. Callingdispose()on returned object will throw anUnsupportedOperationException.Note: The behavior is undefined if the passed-in object is already disposed or wrapped into another finalizable instance.
- Parameters:
bidiAlgorithm- The bidi algorithm object to wrap into a finalizable instance.- Returns:
- The finalizable instance of the passed-in bidi algorithm object.
-
isFinalizable
Checks whether a bidi algorithm object is finalizable or not.- Parameters:
bidiAlgorithm- The bidi algorithm object to check.- Returns:
trueif the passed-in bidi algorithm object is finalizable,falseotherwise.
-
getCharBidiClasses
Returns a list containing the bidi classes of all characters in source text. The valid bidi class values are available inBidiClassas static constants.- Returns:
- A list containing the bidi classes of all characters in source text.
-
getParagraphBoundary
public int getParagraphBoundary(int charStart, int charEnd) Returns the boundary of the first paragraph within the given range.The boundary of the paragraph occurs after a character whose bidirectional type is Paragraph Separator (B), or the
charEndif no such character exists before it. The exception to this rule is when a Carriage Return (CR) is followed by a Line Feed (LF). Both CR and LF are paragraph separators, but in that case, the boundary of the paragraph is considered after LF character.- Parameters:
charStart- The index to the first character of the paragraph in source text.charEnd- The suggested index after the last character of the paragraph in source text.- Returns:
- The boundary of the first paragraph within the given range.
- Throws:
IllegalArgumentException- ifcharStartis negative, orcharEndis greater than the length of source text, orcharStartis greater than or equal tocharEnd.
-
createParagraph
@NonNull public BidiParagraph createParagraph(int charStart, int charEnd, @NonNull BaseDirection baseDirection) Creates a paragraph object processed with Unicode Bidirectional Algorithm.This method processes only first paragraph starting at
charStartand ending at eithercharEndor some character before it, in accordance with Rule P1 of Unicode Bidirectional Algorithm.The paragraph level is determined by applying Rules P2-P3 and embedding levels are resolved by applying Rules X1-I2.
- Parameters:
charStart- The index to the first character of the paragraph in source text.charEnd- The suggested index after the last character of the paragraph in source text.baseDirection- The base direction of the paragraph.- Returns:
- A paragraph object processed with Unicode Bidirectional Algorithm.
- Throws:
IllegalArgumentException- ifcharStartis negative, orcharEndis greater than the length of source text, orcharStartis greater than or equal tocharEnd.
-
createParagraph
Creates a paragraph object processed with Unicode Bidirectional Algorithm.This method processes only first paragraph starting at
charStartand ending at eithercharEndor some character before it, in accordance with Rule P1 of Unicode Bidirectional Algorithm.The paragraph level is overridden by
baseLevelparameter and embedding levels are resolved by applying Rules X1-I2.- Parameters:
charStart- The index to the first character of the paragraph in source text.charEnd- The suggested index after the last character of the paragraph in source text.baseLevel- Base level to override.- Returns:
- A paragraph object processed with Unicode Bidirectional Algorithm.
- Throws:
IllegalArgumentException- if any of the following is true:charStartis negativecharEndis greater than the length of source textcharStartis greater than or equal tocharEndbaseLevelis less than zerobaseLevelis greater thanMAX_LEVEL
-
dispose
public void dispose()Description copied from interface:DisposableReleases the native memory of this object. Failing to call this method will cause memory leaks.Note: The behavior is undefined if this method is called more than once on the same object.
- Specified by:
disposein interfaceDisposable
-
toString
-