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
-
Constructor Summary
ConstructorDescriptionBidiAlgorithm
(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.void
dispose()
Releases the native memory of this object.static BidiAlgorithm
finalizable
(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.int
getParagraphBoundary
(int charStart, int charEnd) Returns the boundary of the first paragraph within the given range.static boolean
isFinalizable
(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
- iftext
is 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:
true
if the passed-in bidi algorithm object is finalizable,false
otherwise.
-
getCharBidiClasses
Returns a list containing the bidi classes of all characters in source text. The valid bidi class values are available inBidiClass
as 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
charEnd
if 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
- ifcharStart
is negative, orcharEnd
is greater than the length of source text, orcharStart
is 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
charStart
and ending at eithercharEnd
or 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
- ifcharStart
is negative, orcharEnd
is greater than the length of source text, orcharStart
is greater than or equal tocharEnd
.
-
createParagraph
Creates a paragraph object processed with Unicode Bidirectional Algorithm.This method processes only first paragraph starting at
charStart
and ending at eithercharEnd
or some character before it, in accordance with Rule P1 of Unicode Bidirectional Algorithm.The paragraph level is overridden by
baseLevel
parameter 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:charStart
is negativecharEnd
is greater than the length of source textcharStart
is greater than or equal tocharEnd
baseLevel
is less than zerobaseLevel
is greater thanMAX_LEVEL
-
dispose
public void dispose()Description copied from interface:Disposable
Releases 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:
dispose
in interfaceDisposable
-
toString
-