Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 656
نمايش فراداده

This class determines character, word, sentence, and line breaks in a block of text in a way that is independent of locale and text encoding. As an abstract class, BreakIterator cannot be instantiated directly. Instead, you must use one of the class methods getCharacterInstance( ), getWordInstance( ), getSentenceInstance( ), or getLineInstance( ) to return an instance of a nonabstract subclass of BreakIterator. These various factory methods return a BreakIterator object that is configured to locate the requested boundary types and is localized to work for the optionally specified locale.

Once you have obtained an appropriate BreakIterator object, use setText( ) to specify the text in which to locate boundaries. To locate boundaries in a Java String object, simply specify the string. To locate boundaries in text that uses some other encoding, you must specify a CharacterIterator object for that text so that the BreakIterator object can locate the individual characters of the text. Having set the text to be searched, you can determine the character positions of characters, words, sentences, or line breaks with the first( ), last( ), next( ), previous( ), current( ), and following( ) methods, which perform the obvious functions. Note that these methods do not return text itself, but merely the position of the appropriate word, sentence, or line break.

Figure 15-2. java.text.BreakIterator

public abstract class 

BreakIterator implements Cloneable { // Protected Constructors protected

BreakIterator ( ); // Public Constants public static final int

DONE ; =-1 // Public Class Methods public static java.util.Locale[ ]

getAvailableLocales ( ); synchronized public static BreakIterator

getCharacterInstance ( ); public static BreakIterator

getCharacterInstance (java.util.Locale

where ); public static BreakIterator

getLineInstance ( ); public static BreakIterator

getLineInstance (java.util.Locale

where ); public static BreakIterator

getSentenceInstance ( ); public static BreakIterator

getSentenceInstance (java.util.Locale

where ); public static BreakIterator

getWordInstance ( ); public static BreakIterator

getWordInstance (java.util.Locale

where ); // Protected Class Methods

5.0 protected static int

getInt (byte[ ]

buf , int

offset );

5.0 protected static long

getLong (byte[ ]

buf , int

offset );

5.0 protected static short

getShort (byte[ ]

buf , int

offset ); // Public Instance Methods public abstract int

current ( ); public abstract int

first ( ); public abstract int

following (int

offset ); public abstract CharacterIterator

getText ( );

1.2 public boolean

isBoundary (int

offset ); public abstract int

last ( ); public abstract int

next ( ); public abstract int

next (int

n );

1.2 public int

preceding (int

offset ); public abstract int

previous ( ); public void

setText (String

newText ); public abstract void

setText (CharacterIterator

newText ); // Public Methods Overriding Object public Object

clone ( ); }