Class RuleBasedBreakIterator
- All Implemented Interfaces:
Cloneable
- Status:
- Stable ICU 2.0.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.This API is ICU internal only.com.ibm.icu.impl.RBBIDataWrapperDeprecated.This API is ICU internal only.Fields inherited from class BreakIterator
DONE, KIND_CHARACTER, KIND_LINE, KIND_SENTENCE, KIND_TITLE, KIND_WORD, WORD_IDEO, WORD_IDEO_LIMIT, WORD_KANA, WORD_KANA_LIMIT, WORD_LETTER, WORD_LETTER_LIMIT, WORD_NONE, WORD_NONE_LIMIT, WORD_NUMBER, WORD_NUMBER_LIMITModifier and TypeFieldDescriptionstatic final intDONE is returned by previous() and next() after all valid boundaries have been returned.static final int[icu]static final int[icu]static final int[icu]static final intDeprecated.ICU 64 UseBreakIterator.getWordInstance()instead.static final int[icu]static final intTag value for words containing ideographic characters, lower limitstatic final intTag value for words containing ideographic characters, upper limitstatic final intTag value for words containing kana characters, lower limitstatic final intTag value for words containing kana characters, upper limitstatic final intTag value for words that contain letters, excluding hiragana, katakana or ideographic characters, lower limit.static final intTag value for words containing letters, upper limitstatic final intTag value for "words" that do not fit into any of other categories.static final intUpper bound for tags for uncategorized words.static final intTag value for words that appear to be numbers, lower limit.static final intTag value for words that appear to be numbers, upper limit. -
Constructor Summary
ConstructorsConstructorDescriptionRuleBasedBreakIterator(String rules) Construct a RuleBasedBreakIterator from a set of rules supplied as a string.RuleBasedBreakIterator(String rules, UnicodeSet.XSymbolTable customProperties) Deprecated.This API is ICU internal only. -
Method Summary
Modifier and TypeMethodDescriptionprotected static final voidcheckOffset(int offset, CharacterIterator text) Throw IndexOutOfBoundsException unless begin <= offset < end.clone()Clones this iterator.static voidcompileRules(String rules, OutputStream ruleBinary) Compile a set of source break rules into the binary state tables used by the break iterator engine.intcurrent()Returns the current iteration position.voiddump(PrintStream out) Deprecated.This API is ICU internal only.booleanReturns true if both BreakIterators are of the same class, have the same rules, and iterate over the same text.intfirst()Sets the current iteration position to the beginning of the text.intfollowing(int startPos) Sets the iterator to refer to the first boundary position following the specified position.static RuleBasedBreakIteratorCreate a break iterator from a precompiled set of break rules.static RuleBasedBreakIteratorDeprecated.This API is ICU internal only.intReturn the status tag from the break rule that determined the boundary at the current iteration position.intgetRuleStatusVec(int[] fillInArray) Get the status (tag) values from the break rule(s) that determined the boundary at the current iteration position.getText()Returns a CharacterIterator over the text being analyzed.inthandleSafePrevious(int fromPosition) Deprecated.This API is ICU internal only.inthashCode()Compute a hashcode for this BreakIteratorbooleanisBoundary(int offset) Returns true if the specified position is a boundary position.intlast()Sets the current iteration position to the end of the text.intnext()Advances the iterator to the next boundary position.intnext(int n) Advances the iterator either forward or backward the specified number of steps.intpreceding(int offset) Sets the iterator to refer to the last boundary position before the specified position.intprevious()Moves the iterator backwards, to the boundary preceding the current one.voidsetText(CharacterIterator newText) Set the iterator to analyze a new piece of text.toString()Returns the description (rules) used to create this iterator.Methods inherited from class BreakIterator
getAvailableLocales, getAvailableULocales, getBreakInstance, getCharacterInstance, getCharacterInstance, getCharacterInstance, getLineInstance, getLineInstance, getLineInstance, getLocale, getSentenceInstance, getSentenceInstance, getSentenceInstance, getTitleInstance, getTitleInstance, getTitleInstance, getWordInstance, getWordInstance, getWordInstance, registerInstance, registerInstance, setText, setText, unregisterModifier and TypeMethodDescriptionstatic Locale[]Returns a list of locales for which BreakIterators can be used.static ULocale[][icu] Returns a list of locales for which BreakIterators can be used.static BreakIteratorgetBreakInstance(ULocale where, int kind) Deprecated.This API is ICU internal only.static BreakIteratorReturns a new instance of BreakIterator that locates logical-character boundaries.static BreakIteratorgetCharacterInstance(ULocale where) [icu] Returns a new instance of BreakIterator that locates logical-character boundaries.static BreakIteratorgetCharacterInstance(Locale where) Returns a new instance of BreakIterator that locates logical-character boundaries.static BreakIteratorReturns a new instance of BreakIterator that locates legal line- wrapping positions.static BreakIteratorgetLineInstance(ULocale where) [icu] Returns a new instance of BreakIterator that locates legal line- wrapping positions.static BreakIteratorgetLineInstance(Locale where) Returns a new instance of BreakIterator that locates legal line- wrapping positions.final ULocalegetLocale(ULocale.Type type) [icu] Returns the locale that was used to create this object, or null.static BreakIteratorReturns a new instance of BreakIterator that locates sentence boundaries.static BreakIteratorgetSentenceInstance(ULocale where) [icu] Returns a new instance of BreakIterator that locates sentence boundaries.static BreakIteratorgetSentenceInstance(Locale where) Returns a new instance of BreakIterator that locates sentence boundaries.static BreakIteratorDeprecated.ICU 64 UseBreakIterator.getWordInstance()instead.static BreakIteratorgetTitleInstance(ULocale where) Deprecated.ICU 64 UseBreakIterator.getWordInstance()instead.static BreakIteratorgetTitleInstance(Locale where) Deprecated.ICU 64 UseBreakIterator.getWordInstance()instead.static BreakIteratorReturns a new instance of BreakIterator that locates word boundaries.static BreakIteratorgetWordInstance(ULocale where) [icu] Returns a new instance of BreakIterator that locates word boundaries.static BreakIteratorgetWordInstance(Locale where) Returns a new instance of BreakIterator that locates word boundaries.static ObjectregisterInstance(BreakIterator iter, ULocale locale, int kind) [icu] Registers a new break iterator of the indicated kind, to use in the given locale.static ObjectregisterInstance(BreakIterator iter, Locale locale, int kind) [icu] Registers a new break iterator of the indicated kind, to use in the given locale.voidsetText(CharSequence newText) Sets the iterator to analyze a new piece of text.voidSets the iterator to analyze a new piece of text.static booleanunregister(Object key) [icu] Unregisters a previously-registered BreakIterator using the key returned from the register call.
-
Field Details
-
fRData
Deprecated.This API is ICU internal only.The rule data for this BreakIterator instance. Not intended for public use. Declared public for testing purposes only.- Status:
- Internal. This API is ICU internal only.
-
fDebugEnv
Deprecated.This API is ICU internal only.Control debug, trace and dump options.- Status:
- Internal. This API is ICU internal only.
-
-
Constructor Details
-
RuleBasedBreakIterator
Construct a RuleBasedBreakIterator from a set of rules supplied as a string.- Parameters:
rules- The break rules to be used.- Status:
- Stable ICU 2.2.
-
RuleBasedBreakIterator
Deprecated.This API is ICU internal only.Construct a RuleBasedBreakIterator from a set of rules supplied as a string, using custom properties.- Parameters:
rules- The break rules to be used.customProperties- An XSymbolTable that supplies the properties to use in the rules, or null to use ICU properties.- Status:
- Internal. This API is ICU internal only.
-
-
Method Details
-
getInstanceFromCompiledRules
public static RuleBasedBreakIterator getInstanceFromCompiledRules(InputStream is) throws IOException Create a break iterator from a precompiled set of break rules.Creating a break iterator from the binary rules is much faster than creating one from source rules.
The binary rules are generated by the RuleBasedBreakIterator.compileRules() function. Binary break iterator rules are not guaranteed to be compatible between different versions of ICU.
- Parameters:
is- an input stream supplying the compiled binary rules.- Throws:
IOException- if there is an error while reading the rules from the InputStream.- See Also:
- Status:
- Stable ICU 4.8.
-
getInstanceFromCompiledRules
@Deprecated public static RuleBasedBreakIterator getInstanceFromCompiledRules(ByteBuffer bytes) throws IOException Deprecated.This API is ICU internal only.Create a break iterator from a precompiled set of break rules.Creating a break iterator from the binary rules is much faster than creating one from source rules.
The binary rules are generated by the RuleBasedBreakIterator.compileRules() function. Binary break iterator rules are not guaranteed to be compatible between different versions of ICU.
- Parameters:
bytes- a buffer supplying the compiled binary rules.- Throws:
IOException- if there is an error while reading the rules from the buffer.- See Also:
- Status:
- Internal. This API is ICU internal only.
-
clone
Clones this iterator.- Overrides:
clonein classBreakIterator- Returns:
- A newly-constructed RuleBasedBreakIterator with the same behavior as this one.
- Status:
- Stable ICU 2.0.
-
equals
-
toString
-
hashCode
-
dump
Deprecated.This API is ICU internal only.Dump the contents of the state table and character classes for this break iterator. For debugging only.- Status:
- Internal. This API is ICU internal only.
-
compileRules
Compile a set of source break rules into the binary state tables used by the break iterator engine. Creating a break iterator from precompiled rules is much faster than creating one from source rules.Binary break rules are not guaranteed to be compatible between different versions of ICU.
- Parameters:
rules- The source form of the break rulesruleBinary- An output stream to receive the compiled rules.- Throws:
IOException- If there is an error writing the output.- See Also:
- Status:
- Stable ICU 4.8.
-
first
public int first()Sets the current iteration position to the beginning of the text. (i.e., the CharacterIterator's starting offset).- Specified by:
firstin classBreakIterator- Returns:
- The offset of the beginning of the text.
- Status:
- Stable ICU 2.0.
-
last
public int last()Sets the current iteration position to the end of the text. (i.e., the CharacterIterator's ending offset).- Specified by:
lastin classBreakIterator- Returns:
- The text's past-the-end offset.
- Status:
- Stable ICU 2.0.
-
next
public int next(int n) Advances the iterator either forward or backward the specified number of steps. Negative values move backward, and positive values move forward. This is equivalent to repeatedly calling next() or previous().- Specified by:
nextin classBreakIterator- Parameters:
n- The number of steps to move. The sign indicates the direction (negative is backwards, and positive is forwards).- Returns:
- The character offset of the boundary position n boundaries away from the current one.
- Status:
- Stable ICU 2.0.
-
next
public int next()Advances the iterator to the next boundary position.- Specified by:
nextin classBreakIterator- Returns:
- The position of the first boundary after this one.
- Status:
- Stable ICU 2.0.
-
previous
public int previous()Moves the iterator backwards, to the boundary preceding the current one.- Specified by:
previousin classBreakIterator- Returns:
- The position of the boundary position immediately preceding the starting position.
- Status:
- Stable ICU 2.0.
-
following
public int following(int startPos) Sets the iterator to refer to the first boundary position following the specified position.- Specified by:
followingin classBreakIterator- Parameters:
startPos- The position from which to begin searching for a break position.- Returns:
- The position of the first break after the current position.
- Status:
- Stable ICU 2.0.
-
preceding
public int preceding(int offset) Sets the iterator to refer to the last boundary position before the specified position.- Overrides:
precedingin classBreakIterator- Parameters:
offset- The position to begin searching for a break from.- Returns:
- The position of the last boundary before the starting position.
- Status:
- Stable ICU 2.0.
-
checkOffset
Throw IndexOutOfBoundsException unless begin <= offset < end.- Status:
- Stable ICU 2.0.
-
isBoundary
public boolean isBoundary(int offset) Returns true if the specified position is a boundary position. As a side effect, leaves the iterator pointing to the first boundary position at or after "offset".- Overrides:
isBoundaryin classBreakIterator- Parameters:
offset- the offset to check.- Returns:
- True if "offset" is a boundary position.
- Status:
- Stable ICU 2.0.
-
current
public int current()Returns the current iteration position. Note that DONE is never returned from this function; if iteration has run to the end of a string, current() will return the length of the string while next() will return BreakIterator.DONE).- Specified by:
currentin classBreakIterator- Returns:
- The current iteration position.
- Status:
- Stable ICU 2.0.
-
getRuleStatus
public int getRuleStatus()Return the status tag from the break rule that determined the boundary at the current iteration position. The values appear in the rule source within brackets, {123}, for example. For rules that do not specify a status, a default value of 0 is returned. If more than one rule applies, the numerically largest of the possible status values is returned.Of the standard types of ICU break iterators, only the word and line break iterator provides status values. The values are defined in class RuleBasedBreakIterator, and allow distinguishing between words that contain alphabetic letters, "words" that appear to be numbers, punctuation and spaces, words containing ideographic characters, and more. Call
getRuleStatusafter obtaining a boundary position fromnext(),previous(), or any other break iterator functions that returns a boundary position.Note that
getRuleStatus()returns the value corresponding tocurrent()index even afternext()has returned DONE.- Overrides:
getRuleStatusin classBreakIterator- Returns:
- the status from the break rule that determined the boundary at the current iteration position.
- Status:
- Stable ICU 60.
-
getRuleStatusVec
public int getRuleStatusVec(int[] fillInArray) Get the status (tag) values from the break rule(s) that determined the boundary at the current iteration position. The values appear in the rule source within brackets, {123}, for example. The default status value for rules that do not explicitly provide one is zero.The status values used by the standard ICU break rules are defined as public constants in class RuleBasedBreakIterator.
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.
- Overrides:
getRuleStatusVecin classBreakIterator- Parameters:
fillInArray- an array to be filled in with the status values.- Returns:
- The number of rule status values from the rules that determined 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.
- Status:
- Stable ICU 60.
-
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.
- Specified by:
getTextin classBreakIterator- Returns:
- An iterator over the text being analyzed.
- Status:
- Stable ICU 2.0.
-
setText
Set 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.
- Specified by:
setTextin classBreakIterator- Parameters:
newText- An iterator over the text to analyze.- Status:
- Stable ICU 2.0.
-
handleSafePrevious
Deprecated.This API is ICU internal only.Iterate backwards from an arbitrary position in the input text using the Safe Reverse rules. This locates a "Safe Position" from which the forward break rules will operate correctly. A Safe Position is not necessarily a boundary itself.The logic of this function is very similar to handleNext(), above, but simpler because the safe table does not require as many options.
- Parameters:
fromPosition- the position in the input text to begin the iteration.- Status:
- Internal. This API is ICU internal only.
-