Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public abstract Class BreakIterator

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
com.ibm.icu.text.RuleBasedBreakIterator, com.ibm.icu.impl.CaseMapImpl.WholeStringBreakIterator, com.ibm.icu.impl.SimpleFilteredSentenceBreakIterator
Imports
java.text.CharacterIterator, .StringCharacterIterator, java.util.Locale, .MissingResourceException, com.ibm.icu.impl.CSCharacterIterator, .CacheValue, .ICUDebug, com.ibm.icu.util.ICUCloneNotSupportedException, .ULocale

ICU Enhancement

This class is ICU's replacement for java.text.BreakIterator.

ICU

Methods, fields, and other functionality specific to ICU are labeled 'ICU'.

A class that locates boundaries in text. This class defines a protocol for objects that break up a piece of natural-language text according to a set of criteria. Instances or subclasses of BreakIterator can be provided, for example, to break a piece of text into words, sentences, or logical characters according to the conventions of some language or group of languages. We provide five built-in types of BreakIterator:

The text boundary positions are found according to the rules described in Unicode Standard Annex #29, Text Boundaries, and Unicode Standard Annex #14, Line Breaking Properties. These are available at http://www.unicode.org/reports/tr14/ and http://www.unicode.org/reports/tr29/.

BreakIterator's interface follows an "iterator" model (hence the name), meaning it has a concept of a "current position" and methods like first(), last(), next(), and previous() that update the current position. All BreakIterators uphold the following invariants:

BreakIterator accesses the text it analyzes through a CharacterIterator, which makes it possible to use BreakIterator to analyze text in any text-storage vehicle that provides a CharacterIterator interface

Note

Some types of BreakIterator can take a long time to create, and instances of BreakIterator are not currently cached by the system. For optimal performance, keep instances of BreakIterator around as long as makes sense. For example, when word-wrapping a document, don't create and destroy a new BreakIterator for each line. Create one break iterator for the whole document (or whatever stretch of text you're wrapping) and use it to do the whole job of wrapping the text.

Examples:

Creating and using text boundaries

public static void main(String args[]) {
     if (args.length == 1) {
         String stringToExamine = args[0];
         //print each word in order
         BreakIterator boundary = BreakIterator.getWordInstance();
         boundary.setText(stringToExamine);
         printEachForward(boundary, stringToExamine);
         //print each sentence in reverse order
         boundary = BreakIterator.getSentenceInstance(Locale.US);
         boundary.setText(stringToExamine);
         printEachBackward(boundary, stringToExamine);
         printFirst(boundary, stringToExamine);
         printLast(boundary, stringToExamine);
     }
}
Print each element in order
public static void printEachForward(BreakIterator boundary, String source) {
    int start = boundary.first();
    for (int end = boundary.next();
         end != BreakIterator.DONE;
         start = end, end = boundary.next()) {
         System.out.println(source.substring(start,end));
    }
}
Print each element in reverse order
public static void printEachBackward(BreakIterator boundary, String source) {
    int end = boundary.last();
    for (int start = boundary.previous();
         start != BreakIterator.DONE;
         end = start, start = boundary.previous()) {
        System.out.println(source.substring(start,end));
    }
}
Print first element
public static void printFirst(BreakIterator boundary, String source) {
    int start = boundary.first();
    int end = boundary.next();
    System.out.println(source.substring(start,end));
}
Print last element
public static void printLast(BreakIterator boundary, String source) {
    int end = boundary.last();
    int start = boundary.previous();
    System.out.println(source.substring(start,end));
}
Print the element at a specified position
public static void printAt(BreakIterator boundary, int pos, String source) {
    int end = boundary.following(pos);
    int start = boundary.previous();
    System.out.println(source.substring(start,end));
}
Find the next word
public static int nextWordStartAfter(int pos, String text) {
    BreakIterator wb = BreakIterator.getWordInstance();
    wb.setText(text);
    int wordStart = wb.following(pos);
    for (;;) {
        int wordLimit = wb.next();
        if (wordLimit == BreakIterator.DONE) {
            return BreakIterator.DONE;
        }
        int wordStatus = wb.getRuleStatus();
        if (wordStatus != BreakIterator.WORD_NONE) {
            return wordStart;
        }
        wordStart = wordLimit;
     }
}
The iterator returned by getWordInstance is unique in that the break positions it returns don't represent both the start and end of the thing being iterated over. That is, a sentence-break iterator returns breaks that each represent the end of one sentence and the beginning of the next. With the word-break iterator, the characters between two boundaries might be a word, or they might be the punctuation or whitespace between two words. The above code uses getRuleStatus to identify and ignore boundaries associated with punctuation or other non-word characters.
ICU Status
Stable since ICU 2.0.
See Also
CharacterIterator

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv abstract static class

Field Summary

Modifier and TypeField and Description
private ULocale
actualLocale

The locale containing data used to construct this object, or null.

private static final boolean
public static final int
DONE

DONE is returned by previous() and next() after all valid boundaries have been returned.

private static final CacheValue<?>[]
public static final int
private static final int
public static final int
public static final int
public static final int
public static final int
private static BreakIterator.BreakIteratorServiceShim
private ULocale
validLocale

The most specific locale containing any resource data, or null.

public static final int
WORD_IDEO

Tag value for words containing ideographic characters, lower limit

public static final int
WORD_IDEO_LIMIT

Tag value for words containing ideographic characters, upper limit

public static final int
WORD_KANA

Tag value for words containing kana characters, lower limit

public static final int
WORD_KANA_LIMIT

Tag value for words containing kana characters, upper limit

public static final int
WORD_LETTER

Tag value for words that contain letters, excluding hiragana, katakana or ideographic characters, lower limit.

public static final int
WORD_LETTER_LIMIT

Tag value for words containing letters, upper limit

public static final int
WORD_NONE

Tag value for "words" that do not fit into any of other categories.

public static final int
WORD_NONE_LIMIT

Upper bound for tags for uncategorized words.

public static final int
WORD_NUMBER

Tag value for words that appear to be numbers, lower limit.

public static final int
WORD_NUMBER_LIMIT

Tag value for words that appear to be numbers, upper limit.

Constructor Summary

AccessConstructor and Description
protected
BreakIterator()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

The clone.
clone
()

Overrides java.lang.Object.clone.

Clone method.
public abstract int

Returns:

The iterator's current position.
current
()

Return the iterator's current position.

public abstract int

Returns:

The character offset of the beginning of the stretch of text being broken.
first
()

Set the iterator to the first boundary position.

public abstract int

Returns:

The position of the first boundary position following "offset" (whether or not "offset" itself is a boundary position), or DONE if "offset" is the past-the-end offset.
following
(int
The character position to start searching from.
offset
)

Sets the iterator's current iteration position to be the first boundary position following the specified position.

public static synchronized Locale[]

Returns:

An array of Locales. All of the locales in the array can be used when creating a BreakIterator.
getAvailableLocales
()

Returns a list of locales for which BreakIterators can be used.

public static synchronized ULocale[]

Returns:

An array of Locales. All of the locales in the array can be used when creating a BreakIterator.
getAvailableULocales
()

ICU

public static BreakIterator
getBreakInstance(ULocale where, int kind)

Deprecated This API is ICU internal only.
Returns a particular kind of BreakIterator for a locale.
public static BreakIterator

Returns:

A new instance of BreakIterator that locates logical-character boundaries.
getCharacterInstance
()

Returns a new instance of BreakIterator that locates logical-character boundaries.

public static BreakIterator

Returns:

A new instance of BreakIterator that locates logical-character boundaries.
getCharacterInstance
(Locale
A Locale specifying the language of the text being analyzed.
where
)

Returns a new instance of BreakIterator that locates logical-character boundaries.

public static BreakIterator

Returns:

A new instance of BreakIterator that locates logical-character boundaries.
getCharacterInstance
(ULocale
A Locale specifying the language of the text being analyzed.
where
)

ICU

public static BreakIterator

Returns:

A new instance of BreakIterator that locates legal line-wrapping positions.
getLineInstance
()

Returns a new instance of BreakIterator that locates legal line- wrapping positions.

public static BreakIterator

Returns:

A new instance of BreakIterator that locates legal line-wrapping positions.
getLineInstance
(Locale
A Locale specifying the language of the text being broken.
where
)

Returns a new instance of BreakIterator that locates legal line- wrapping positions.

public static BreakIterator

Returns:

A new instance of BreakIterator that locates legal line-wrapping positions.
getLineInstance
(ULocale
A Locale specifying the language of the text being broken.
where
)

ICU

public final ULocale

Returns:

the information specified by type, or null if this object was not constructed from locale data.
getLocale
(ULocale.Type type)

ICU

public int

Returns:

The status from the break rule that determined the boundary at the current iteration position.
getRuleStatus
()

For RuleBasedBreakIterators, return the status tag from the break rule that determined the boundary at the current iteration position.

public int

Returns:

The number of rule status values from rules that determined the the boundary at the current iteration position. In the event that the array is too small, the return value is the total number of status values that were available, not the reduced number that were actually returned.
getRuleStatusVec
(int[]
an array to be filled in with the status values.
fillInArray
)

For RuleBasedBreakIterators, get the status (tag) values from the break rule(s) that determined the the boundary at the current iteration position.

public static BreakIterator

Returns:

A new instance of BreakIterator that locates sentence boundaries.
getSentenceInstance
()

Returns a new instance of BreakIterator that locates sentence boundaries.

public static BreakIterator

Returns:

A new instance of BreakIterator that locates sentence boundaries.
getSentenceInstance
(Locale
A Locale specifying the language of the text being analyzed.
where
)

Returns a new instance of BreakIterator that locates sentence boundaries.

public static BreakIterator

Returns:

A new instance of BreakIterator that locates sentence boundaries.
getSentenceInstance
(ULocale
A Locale specifying the language of the text being analyzed.
where
)

ICU

private static BreakIterator.BreakIteratorServiceShim
public abstract CharacterIterator

Returns:

A CharacterIterator over the text being analyzed.
getText
()

Returns a CharacterIterator over the text being analyzed.

public static BreakIterator

Returns:

A new instance of BreakIterator that locates title boundaries.
getTitleInstance
()

Deprecated ICU 64 Use getWordInstance instead.

ICU

public static BreakIterator

Returns:

A new instance of BreakIterator that locates title boundaries.
getTitleInstance
(Locale
A Locale specifying the language of the text being analyzed.
where
)

Deprecated ICU 64 Use getWordInstance instead.

ICU

public static BreakIterator

Returns:

A new instance of BreakIterator that locates title boundaries.
getTitleInstance
(ULocale
A Locale specifying the language of the text being analyzed.
where
)

Deprecated ICU 64 Use getWordInstance instead.

ICU

public static BreakIterator

Returns:

An instance of BreakIterator that locates word boundaries.
getWordInstance
()

Returns a new instance of BreakIterator that locates word boundaries.

public static BreakIterator

Returns:

An instance of BreakIterator that locates word boundaries.
getWordInstance
(Locale
A locale specifying the language of the text to be analyzed.
where
)

Returns a new instance of BreakIterator that locates word boundaries.

public static BreakIterator

Returns:

An instance of BreakIterator that locates word boundaries.
getWordInstance
(ULocale
A locale specifying the language of the text to be analyzed.
where
)

ICU

public boolean

Returns:

True if "offset" is a boundary position.
isBoundary
(int
the offset to check.
offset
)

Return true if the specified position is a boundary position.

public abstract int

Returns:

The character offset of the end of the stretch of text being broken.
last
()

Set the iterator to the last boundary position.

public abstract int

Returns:

The position of the boundary n boundaries from the current iteration position, or DONE if moving n boundaries causes the iterator to advance off either end of the text.
next
(int
The number of boundaries to advance over (if positive, moves forward; if negative, moves backwards).
n
)

Move the iterator by the specified number of steps in the text.

public abstract int

Returns:

The position of the first boundary position following the iteration position.
next
()

Advances the iterator forward one boundary.

public int

Returns:

The position of the last boundary position preceding "offset" (whether of not "offset" itself is a boundary position), or DONE if "offset" is the starting offset of the iterator.
preceding
(int
The character position to start searching from.
offset
)

Sets the iterator's current iteration position to be the last boundary position preceding the specified position.

public abstract int

Returns:

The position of the last boundary position preceding the iteration position.
previous
()

Move the iterator backward one boundary.

public static Object

Returns:

a registry key that can be used to unregister this instance
registerInstance
(BreakIterator
the BreakIterator instance to adopt.
iter
,
Locale
the Locale for which this instance is to be registered
locale
,
int
the type of iterator for which this instance is to be registered
kind
)

ICU

public static Object

Returns:

a registry key that can be used to unregister this instance
registerInstance
(BreakIterator
the BreakIterator instance to adopt.
iter
,
ULocale
the Locale for which this instance is to be registered
locale
,
int
the type of iterator for which this instance is to be registered
kind
)

ICU

pack-priv final void
setLocale(ULocale
the most specific locale containing any resource data, or null
valid
,
ULocale
the locale containing data used to construct this object, or null
actual
)

Set information about the locales that were used to create this object.

public void
setText(String
A String containing the text to analyze with this BreakIterator.
newText
)

Sets the iterator to analyze a new piece of text.

public void
setText(CharSequence
A CharSequence containing the text to analyze with this BreakIterator.
newText
)

Sets the iterator to analyze a new piece of text.

public abstract void
setText(CharacterIterator
A CharacterIterator referring to the text to analyze with this BreakIterator (the iterator's current position is ignored, but its other state is significant).
newText
)

Sets the iterator to analyze a new piece of text.

public static boolean

Returns:

true if the iterator for the key was successfully unregistered
unregister
(Object
the registry key returned by a previous call to registerInstance
key
)

ICU

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actualLocaleback to summary
private ULocale actualLocale

The locale containing data used to construct this object, or null.

See Also
com.ibm.icu.util.ULocale
DEBUGback to summary
private static final boolean DEBUG
DONEback to summary
public static final int DONE

DONE is returned by previous() and next() after all valid boundaries have been returned.

ICU Status
Stable since ICU 2.0.
iterCacheback to summary
private static final CacheValue<?>[] iterCache
KIND_CHARACTERback to summary
public static final int KIND_CHARACTER

ICU

ICU Status
Stable since ICU 2.4.
KIND_COUNTback to summary
private static final int KIND_COUNT
Since
ICU 2.8
KIND_LINEback to summary
public static final int KIND_LINE

ICU

ICU Status
Stable since ICU 2.4.
KIND_SENTENCEback to summary
public static final int KIND_SENTENCE

ICU

ICU Status
Stable since ICU 2.4.
KIND_TITLEback to summary
public static final int KIND_TITLE

Deprecated

ICU 64 Use getWordInstance instead.

ICU

Annotations
@Deprecated
See Also
getTitleInstance, getWordInstance
KIND_WORDback to summary
public static final int KIND_WORD

ICU

ICU Status
Stable since ICU 2.4.
shimback to summary
private static BreakIterator.BreakIteratorServiceShim shim
validLocaleback to summary
private ULocale validLocale

The most specific locale containing any resource data, or null.

See Also
com.ibm.icu.util.ULocale
WORD_IDEOback to summary
public static final int WORD_IDEO

Tag value for words containing ideographic characters, lower limit

ICU Status
Stable since ICU 53.
WORD_IDEO_LIMITback to summary
public static final int WORD_IDEO_LIMIT

Tag value for words containing ideographic characters, upper limit

ICU Status
Stable since ICU 53.
WORD_KANAback to summary
public static final int WORD_KANA

Tag value for words containing kana characters, lower limit

ICU Status
Stable since ICU 53.
WORD_KANA_LIMITback to summary
public static final int WORD_KANA_LIMIT

Tag value for words containing kana characters, upper limit

ICU Status
Stable since ICU 53.
WORD_LETTERback to summary
public static final int WORD_LETTER

Tag value for words that contain letters, excluding hiragana, katakana or ideographic characters, lower limit.

ICU Status
Stable since ICU 53.
WORD_LETTER_LIMITback to summary
public static final int WORD_LETTER_LIMIT

Tag value for words containing letters, upper limit

ICU Status
Stable since ICU 53.
WORD_NONEback to summary
public static final int WORD_NONE

Tag value for "words" that do not fit into any of other categories. Includes spaces and most punctuation.

ICU Status
Stable since ICU 53.
WORD_NONE_LIMITback to summary
public static final int WORD_NONE_LIMIT

Upper bound for tags for uncategorized words.

ICU Status
Stable since ICU 53.
WORD_NUMBERback to summary
public static final int WORD_NUMBER

Tag value for words that appear to be numbers, lower limit.

ICU Status
Stable since ICU 53.
WORD_NUMBER_LIMITback to summary
public static final int WORD_NUMBER_LIMIT

Tag value for words that appear to be numbers, upper limit.

ICU Status
Stable since ICU 53.

Constructor Detail

BreakIteratorback to summary
protected BreakIterator()

Default constructor. There is no state that is carried by this abstract base class.

ICU Status
Stable since ICU 2.0.

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Clone method. Creates another BreakIterator with the same behavior and current state as this one.

Returns:Object

The clone.

Annotations
@Override
ICU Status
Stable since ICU 2.0.
currentback to summary
public abstract int current()

Return the iterator's current position.

Returns:int

The iterator's current position.

ICU Status
Stable since ICU 2.0.
firstback to summary
public abstract int first()

Set the iterator to the first boundary position. This is always the beginning index of the text this iterator iterates over. For example, if the iterator iterates over a whole string, this function will always return 0.

Returns:int

The character offset of the beginning of the stretch of text being broken.

ICU Status
Stable since ICU 2.0.
followingback to summary
public abstract int following(int offset)

Sets the iterator's current iteration position to be the first boundary position following the specified position. (Whether the specified position is itself a boundary position or not doesn't matter-- this function always moves the iteration position to the first boundary after the specified position.) If the specified position is the past-the-end position, returns DONE.

Parameters
offset:int

The character position to start searching from.

Returns:int

The position of the first boundary position following "offset" (whether or not "offset" itself is a boundary position), or DONE if "offset" is the past-the-end offset.

ICU Status
Stable since ICU 2.0.
getAvailableLocalesback to summary
public static synchronized Locale[] getAvailableLocales()

Returns a list of locales for which BreakIterators can be used.

Returns:Locale[]

An array of Locales. All of the locales in the array can be used when creating a BreakIterator.

ICU Status
Stable since ICU 2.6.
getAvailableULocalesback to summary
public static synchronized ULocale[] getAvailableULocales()

ICU

Returns a list of locales for which BreakIterators can be used.
Returns:ULocale[]

An array of Locales. All of the locales in the array can be used when creating a BreakIterator.

ICU Status
Draft since ICU 3.2 (retain).
getBreakInstanceback to summary
public static BreakIterator getBreakInstance(ULocale where, int kind)

Deprecated

This API is ICU internal only.

Returns a particular kind of BreakIterator for a locale. Avoids writing a switch statement with getXYZInstance(where) calls.

Annotations
@Deprecated
ICU Status
Internal ICU component.
getCharacterInstanceback to summary
public static BreakIterator getCharacterInstance()

Returns a new instance of BreakIterator that locates logical-character boundaries. This function assumes that the text being analyzed is in the default locale's language.

Returns:BreakIterator

A new instance of BreakIterator that locates logical-character boundaries.

ICU Status
Stable since ICU 2.0.
getCharacterInstanceback to summary
public static BreakIterator getCharacterInstance(Locale where)

Returns a new instance of BreakIterator that locates logical-character boundaries.

Parameters
where:Locale

A Locale specifying the language of the text being analyzed.

Returns:BreakIterator

A new instance of BreakIterator that locates logical-character boundaries.

Exceptions
NullPointerException:
if where is null.
ICU Status
Stable since ICU 2.0.
getCharacterInstanceback to summary
public static BreakIterator getCharacterInstance(ULocale where)

ICU

Returns a new instance of BreakIterator that locates logical-character boundaries.
Parameters
where:ULocale

A Locale specifying the language of the text being analyzed.

Returns:BreakIterator

A new instance of BreakIterator that locates logical-character boundaries.

Exceptions
NullPointerException:
if where is null.
ICU Status
Stable since ICU 3.2.
getLineInstanceback to summary
public static BreakIterator getLineInstance()

Returns a new instance of BreakIterator that locates legal line- wrapping positions. This function assumes the text being broken is in the default locale's language.

Returns:BreakIterator

A new instance of BreakIterator that locates legal line-wrapping positions.

ICU Status
Stable since ICU 2.0.
getLineInstanceback to summary
public static BreakIterator getLineInstance(Locale where)

Returns a new instance of BreakIterator that locates legal line- wrapping positions.

Parameters
where:Locale

A Locale specifying the language of the text being broken.

Returns:BreakIterator

A new instance of BreakIterator that locates legal line-wrapping positions.

Exceptions
NullPointerException:
if where is null.
ICU Status
Stable since ICU 2.0.
getLineInstanceback to summary
public static BreakIterator getLineInstance(ULocale where)

ICU

Returns a new instance of BreakIterator that locates legal line- wrapping positions.
Parameters
where:ULocale

A Locale specifying the language of the text being broken.

Returns:BreakIterator

A new instance of BreakIterator that locates legal line-wrapping positions.

Exceptions
NullPointerException:
if where is null.
ICU Status
Stable since ICU 3.2.
getLocaleback to summary
public final ULocale getLocale(ULocale.Type type)

ICU

Returns the locale that was used to create this object, or null. This may may differ from the locale requested at the time of this object's creation. For example, if an object is created for locale en_US_CALIFORNIA, the actual data may be drawn from en (the actual locale), and en_US may be the most specific locale that exists (the valid locale).

Note

The actual locale is returned correctly, but the valid locale is not, in most cases.

Parameters
type:ULocale.Type

type of information requested, either com.ibm.icu.util.ULocale#VALID_LOCALE or com.ibm.icu.util.ULocale#ACTUAL_LOCALE.

Returns:ULocale

the information specified by type, or null if this object was not constructed from locale data.

ICU Status
Draft since ICU 2.8 (retain).
See Also
com.ibm.icu.util.ULocale, com.ibm.icu.util.ULocale#VALID_LOCALE, com.ibm.icu.util.ULocale#ACTUAL_LOCALE
getRuleStatusback to summary
public int getRuleStatus()

For RuleBasedBreakIterators, return the status tag from the break rule that determined the boundary at the current iteration position.

For break iterator types that do not support a rule status, a default value of 0 is returned.

Returns:int

The status from the break rule that determined the boundary at the current iteration position.

ICU Status
Stable since ICU 52.
getRuleStatusVecback to summary
public int getRuleStatusVec(int[] fillInArray)

For RuleBasedBreakIterators, get the status (tag) values from the break rule(s) that determined the the boundary at the current iteration position.

For break iterator types that do not support rule status, no values are returned.

If the size of the output array is insufficient to hold the data, the output will be truncated to the available length. No exception will be thrown.

Parameters
fillInArray:int[]

an array to be filled in with the status values.

Returns:int

The number of rule status values from rules that determined the the boundary at the current iteration position. In the event that the array is too small, the return value is the total number of status values that were available, not the reduced number that were actually returned.

ICU Status
Stable since ICU 52.
getSentenceInstanceback to summary
public static BreakIterator getSentenceInstance()

Returns a new instance of BreakIterator that locates sentence boundaries. This function assumes the text being analyzed is in the default locale's language.

Returns:BreakIterator

A new instance of BreakIterator that locates sentence boundaries.

ICU Status
Stable since ICU 2.0.
getSentenceInstanceback to summary
public static BreakIterator getSentenceInstance(Locale where)

Returns a new instance of BreakIterator that locates sentence boundaries.

Parameters
where:Locale

A Locale specifying the language of the text being analyzed.

Returns:BreakIterator

A new instance of BreakIterator that locates sentence boundaries.

Exceptions
NullPointerException:
if where is null.
ICU Status
Stable since ICU 2.0.
getSentenceInstanceback to summary
public static BreakIterator getSentenceInstance(ULocale where)

ICU

Returns a new instance of BreakIterator that locates sentence boundaries.
Parameters
where:ULocale

A Locale specifying the language of the text being analyzed.

Returns:BreakIterator

A new instance of BreakIterator that locates sentence boundaries.

Exceptions
NullPointerException:
if where is null.
ICU Status
Stable since ICU 3.2.
getShimback to summary
private static BreakIterator.BreakIteratorServiceShim getShim()
getTextback to summary
public abstract CharacterIterator getText()

Returns a CharacterIterator over the text being analyzed.

Caution

The state of the returned CharacterIterator must not be modified in any way while the BreakIterator is still in use. Doing so will lead to undefined behavior of the BreakIterator. Clone the returned CharacterIterator first and work with that.

The returned CharacterIterator is a reference to the actual iterator being used by the BreakIterator. No guarantees are made about the current position of this iterator when it is returned; it may differ from the BreakIterators current position. If you need to move that position to examine the text, clone this function's return value first.

Returns:CharacterIterator

A CharacterIterator over the text being analyzed.

ICU Status
Stable since ICU 2.0.
getTitleInstanceback to summary
public static BreakIterator getTitleInstance()

Deprecated

ICU 64 Use getWordInstance instead.

ICU

Returns a new instance of BreakIterator that locates title boundaries. This function assumes the text being analyzed is in the default locale's language. The iterator returned locates title boundaries as described for Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration, please use a word boundary iterator. getWordInstance
Returns:BreakIterator

A new instance of BreakIterator that locates title boundaries.

Annotations
@Deprecated
getTitleInstanceback to summary
public static BreakIterator getTitleInstance(Locale where)

Deprecated

ICU 64 Use getWordInstance instead.

ICU

Returns a new instance of BreakIterator that locates title boundaries. The iterator returned locates title boundaries as described for Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration, please use Word Boundary iterator.getWordInstance
Parameters
where:Locale

A Locale specifying the language of the text being analyzed.

Returns:BreakIterator

A new instance of BreakIterator that locates title boundaries.

Annotations
@Deprecated
Exceptions
NullPointerException:
if where is null.
getTitleInstanceback to summary
public static BreakIterator getTitleInstance(ULocale where)

Deprecated

ICU 64 Use getWordInstance instead.

ICU

Returns a new instance of BreakIterator that locates title boundaries. The iterator returned locates title boundaries as described for Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration, please use Word Boundary iterator.getWordInstance
Parameters
where:ULocale

A Locale specifying the language of the text being analyzed.

Returns:BreakIterator

A new instance of BreakIterator that locates title boundaries.

Annotations
@Deprecated
Exceptions
NullPointerException:
if where is null.
getWordInstanceback to summary
public static BreakIterator getWordInstance()

Returns a new instance of BreakIterator that locates word boundaries. This function assumes that the text being analyzed is in the default locale's language.

Returns:BreakIterator

An instance of BreakIterator that locates word boundaries.

ICU Status
Stable since ICU 2.0.
getWordInstanceback to summary
public static BreakIterator getWordInstance(Locale where)

Returns a new instance of BreakIterator that locates word boundaries.

Parameters
where:Locale

A locale specifying the language of the text to be analyzed.

Returns:BreakIterator

An instance of BreakIterator that locates word boundaries.

Exceptions
NullPointerException:
if where is null.
ICU Status
Stable since ICU 2.0.
getWordInstanceback to summary
public static BreakIterator getWordInstance(ULocale where)

ICU

Returns a new instance of BreakIterator that locates word boundaries.
Parameters
where:ULocale

A locale specifying the language of the text to be analyzed.

Returns:BreakIterator

An instance of BreakIterator that locates word boundaries.

Exceptions
NullPointerException:
if where is null.
ICU Status
Stable since ICU 3.2.
isBoundaryback to summary
public boolean isBoundary(int offset)

Return true if the specified position is a boundary position. If the function returns true, the current iteration position is set to the specified position; if the function returns false, the current iteration position is set as though following() had been called.

Parameters
offset:int

the offset to check.

Returns:boolean

True if "offset" is a boundary position.

ICU Status
Stable since ICU 2.0.
lastback to summary
public abstract int last()

Set the iterator to the last boundary position. This is always the "past-the-end" index of the text this iterator iterates over. For example, if the iterator iterates over a whole string (call it "text"), this function will always return text.length().

Returns:int

The character offset of the end of the stretch of text being broken.

ICU Status
Stable since ICU 2.0.
nextback to summary
public abstract int next(int n)

Move the iterator by the specified number of steps in the text. A positive number moves the iterator forward; a negative number moves the iterator backwards. If this causes the iterator to move off either end of the text, this function returns DONE; otherwise, this function returns the position of the appropriate boundary. Calling this function is equivalent to calling next() or previous() n times.

Parameters
n:int

The number of boundaries to advance over (if positive, moves forward; if negative, moves backwards).

Returns:int

The position of the boundary n boundaries from the current iteration position, or DONE if moving n boundaries causes the iterator to advance off either end of the text.

ICU Status
Stable since ICU 2.0.
nextback to summary
public abstract int next()

Advances the iterator forward one boundary. The current iteration position is updated to point to the next boundary position after the current position, and this is also the value that is returned. If the current position is equal to the value returned by last(), or to DONE, this function returns DONE and sets the current position to DONE.

Returns:int

The position of the first boundary position following the iteration position.

ICU Status
Stable since ICU 2.0.
precedingback to summary
public int preceding(int offset)

Sets the iterator's current iteration position to be the last boundary position preceding the specified position. (Whether the specified position is itself a boundary position or not doesn't matter-- this function always moves the iteration position to the last boundary before the specified position.) If the specified position is the starting position, returns DONE.

Parameters
offset:int

The character position to start searching from.

Returns:int

The position of the last boundary position preceding "offset" (whether of not "offset" itself is a boundary position), or DONE if "offset" is the starting offset of the iterator.

ICU Status
Stable since ICU 2.0.
previousback to summary
public abstract int previous()

Move the iterator backward one boundary. The current iteration position is updated to point to the last boundary position before the current position, and this is also the value that is returned. If the current position is equal to the value returned by first(), or to DONE, this function returns DONE and sets the current position to DONE.

Returns:int

The position of the last boundary position preceding the iteration position.

ICU Status
Stable since ICU 2.0.
registerInstanceback to summary
public static Object registerInstance(BreakIterator iter, Locale locale, int kind)

ICU

Registers a new break iterator of the indicated kind, to use in the given locale. Clones of the iterator will be returned if a request for a break iterator of the given kind matches or falls back to this locale.

Because ICU may choose to cache BreakIterator objects internally, this must be called at application startup, prior to any calls to BreakIterator.getInstance to avoid undefined behavior.

Parameters
iter:BreakIterator

the BreakIterator instance to adopt.

locale:Locale

the Locale for which this instance is to be registered

kind:int

the type of iterator for which this instance is to be registered

Returns:Object

a registry key that can be used to unregister this instance

ICU Status
Stable since ICU 2.4.
registerInstanceback to summary
public static Object registerInstance(BreakIterator iter, ULocale locale, int kind)

ICU

Registers a new break iterator of the indicated kind, to use in the given locale. Clones of the iterator will be returned if a request for a break iterator of the given kind matches or falls back to this locale.

Because ICU may choose to cache BreakIterator objects internally, this must be called at application startup, prior to any calls to BreakIterator.getInstance to avoid undefined behavior.

Parameters
iter:BreakIterator

the BreakIterator instance to adopt.

locale:ULocale

the Locale for which this instance is to be registered

kind:int

the type of iterator for which this instance is to be registered

Returns:Object

a registry key that can be used to unregister this instance

ICU Status
Stable since ICU 3.2.
setLocaleback to summary
pack-priv final void setLocale(ULocale valid, ULocale actual)

Set information about the locales that were used to create this object. If the object was not constructed from locale data, both arguments should be set to null. Otherwise, neither should be null. The actual locale must be at the same level or less specific than the valid locale. This method is intended for use by factories or other entities that create objects of this class.

Parameters
valid:ULocale

the most specific locale containing any resource data, or null

actual:ULocale

the locale containing data used to construct this object, or null

See Also
com.ibm.icu.util.ULocale, com.ibm.icu.util.ULocale#VALID_LOCALE, com.ibm.icu.util.ULocale#ACTUAL_LOCALE
setTextback to summary
public void setText(String newText)

Sets the iterator to analyze a new piece of text. The new piece of text is passed in as a String, and the current iteration position is reset to the beginning of the string. (The old text is dropped.)

Parameters
newText:String

A String containing the text to analyze with this BreakIterator.

ICU Status
Stable since ICU 2.0.
setTextback to summary
public void setText(CharSequence newText)

Sets the iterator to analyze a new piece of text. The new piece of text is passed in as a CharSequence, and the current iteration position is reset to the beginning of the text. (The old text is dropped.)

The text underlying the CharSequence must not be be modified while the BreakIterator holds a references to it. (As could possibly occur with a StringBuilder, for example).

Parameters
newText:CharSequence

A CharSequence containing the text to analyze with this BreakIterator.

ICU Status
Stable since ICU 60.
setTextback to summary
public abstract void setText(CharacterIterator newText)

Sets the iterator to analyze a new piece of text. This function resets the current iteration position to the beginning of the text. (The old iterator is dropped.)

Caution

The supplied CharacterIterator is used directly by the BreakIterator, and must not be altered in any way by code outside of the BreakIterator. Doing so will lead to undefined behavior of the BreakIterator.

Parameters
newText:CharacterIterator

A CharacterIterator referring to the text to analyze with this BreakIterator (the iterator's current position is ignored, but its other state is significant).

ICU Status
Stable since ICU 2.0.
unregisterback to summary
public static boolean unregister(Object key)

ICU

Unregisters a previously-registered BreakIterator using the key returned from the register call. Key becomes invalid after this call and should not be used again.
Parameters
key:Object

the registry key returned by a previous call to registerInstance

Returns:boolean

true if the iterator for the key was successfully unregistered

ICU Status
Stable since ICU 2.4.
com.ibm.icu.text back to summary

private final Class BreakIterator.BreakIteratorCache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private BreakIterator
private ULocale

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv BreakIterator
pack-priv ULocale
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iterback to summary
private BreakIterator iter
whereback to summary
private ULocale where

Constructor Detail

BreakIteratorCacheback to summary
pack-priv BreakIteratorCache(ULocale where, BreakIterator iter)

Method Detail

createBreakInstanceback to summary
pack-priv BreakIterator createBreakInstance()
getLocaleback to summary
pack-priv ULocale getLocale()
com.ibm.icu.text back to summary

pack-priv abstract Class BreakIterator.BreakIteratorServiceShim

extends Object
Class Inheritance
Known Direct Subclasses
com.ibm.icu.text.BreakIteratorFactory

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public abstract BreakIterator
public abstract Locale[]
public abstract ULocale[]
public abstract Object
public abstract boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BreakIteratorServiceShimback to summary
pack-priv BreakIteratorServiceShim()

Method Detail

createBreakIteratorback to summary
public abstract BreakIterator createBreakIterator(ULocale l, int k)
getAvailableLocalesback to summary
public abstract Locale[] getAvailableLocales()
getAvailableULocalesback to summary
public abstract ULocale[] getAvailableULocales()
registerInstanceback to summary
public abstract Object registerInstance(BreakIterator iter, ULocale l, int k)
unregisterback to summary
public abstract boolean unregister(Object key)