The Bidi class implements the " Unicode Version 3.0 Bidirectional Algorithm” for working with Arabic and Hebrew text in which letters run right-to-left and numbers run left-to-right. It is named after the first four letters of “bidirectional.” A full description of the bidirectional text handling and the bidirectional algorithim is beyond the scope of this book, but the simplest use case for this class is outlined here. Create a Bidi object by passing an AttributedCharacterIterator or a String and one of the DIRECTION constants (to indicate the base direction of the text) to the Bidi( ) constructor. Or use createLineBidi( ) to return a substring of an existing Bidi object (this is usually done when formatting a paragraph of text to fit on individual lines).

Once you have a Bidi object, use isLeftToRight( ) and isRightToLeft( ) to determine whether all the text has the same direction. If both of these methods return false (which is the same as isMixed( ) returning true) then you cannot treat the text as a single run of uni-directional text. In this case, you must break it into two or more runs of unidirectional text. getRunCount( ) returns the number of distinct runs of text. For each such numbered run, getRunStart( ) returns the index of the first character of the run, and getRunLimit( ) returns the index of the first character past the end of the run. getRunLevel( ) returns the level of the text, which is an integer that represents the direction and nesting level ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.