ICU 72.1 72.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends
icu::BreakIterator Class Referenceabstract

The BreakIterator class implements methods for finding the location of boundaries in text. More...

#include <brkiter.h>

Inheritance diagram for icu::BreakIterator:
icu::UObject icu::UMemory icu::RuleBasedBreakIterator

Public Types

enum  { DONE = (int32_t)-1 }
 

Public Member Functions

virtual ~BreakIterator ()
 destructor More...
 
virtual bool operator== (const BreakIterator &) const =0
 Return true if another object is semantically equal to this one. More...
 
bool operator!= (const BreakIterator &rhs) const
 Returns the complement of the result of operator==. More...
 
virtual BreakIteratorclone () const =0
 Return a polymorphic copy of this object. More...
 
virtual UClassID getDynamicClassID (void) const override=0
 Return a polymorphic class ID for this object. More...
 
virtual CharacterIteratorgetText (void) const =0
 Return a CharacterIterator over the text being analyzed. More...
 
virtual UTextgetUText (UText *fillIn, UErrorCode &status) const =0
 Get a UText for the text being analyzed. More...
 
virtual void setText (const UnicodeString &text)=0
 Change the text over which this operates. More...
 
virtual void setText (UText *text, UErrorCode &status)=0
 Reset the break iterator to operate over the text represented by the UText. More...
 
virtual void adoptText (CharacterIterator *it)=0
 Change the text over which this operates. More...
 
virtual int32_t first (void)=0
 Sets the current iteration position to the beginning of the text, position zero. More...
 
virtual int32_t last (void)=0
 Set the iterator position to the index immediately BEYOND the last character in the text being scanned. More...
 
virtual int32_t previous (void)=0
 Set the iterator position to the boundary preceding the current boundary. More...
 
virtual int32_t next (void)=0
 Advance the iterator to the boundary following the current boundary. More...
 
virtual int32_t current (void) const =0
 Return character index of the current iterator position within the text. More...
 
virtual int32_t following (int32_t offset)=0
 Advance the iterator to the first boundary following the specified offset. More...
 
virtual int32_t preceding (int32_t offset)=0
 Set the iterator position to the first boundary preceding the specified offset. More...
 
virtual UBool isBoundary (int32_t offset)=0
 Return true if the specified position is a boundary position. More...
 
virtual int32_t next (int32_t n)=0
 Set the iterator position to the nth boundary from the current boundary. More...
 
virtual int32_t getRuleStatus () const
 For RuleBasedBreakIterators, return the status tag from the break rule that determined the boundary at the current iteration position. More...
 
virtual int32_t getRuleStatusVec (int32_t *fillInVec, int32_t capacity, UErrorCode &status)
 For RuleBasedBreakIterators, get the status (tag) values from the break rule(s) that determined the boundary at the current iteration position. More...
 
virtual BreakIteratorcreateBufferClone (void *stackBuffer, int32_t &BufferSize, UErrorCode &status)=0
 Deprecated functionality. More...
 
UBool isBufferClone (void)
 Determine whether the BreakIterator was created in user memory by createBufferClone(), and thus should not be deleted. More...
 
Locale getLocale (ULocDataLocaleType type, UErrorCode &status) const
 Returns the locale for this break iterator. More...
 
const char * getLocaleID (ULocDataLocaleType type, UErrorCode &status) const
 Get the locale for this break iterator object. More...
 
virtual BreakIteratorrefreshInputText (UText *input, UErrorCode &status)=0
 Set the subject text string upon which the break iterator is operating without changing any other aspect of the matching state. More...
 
- Public Member Functions inherited from icu::UObject
virtual ~UObject ()
 Destructor. More...
 
virtual UClassID getDynamicClassID () const
 ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. More...
 

Static Public Member Functions

static BreakIteratorcreateWordInstance (const Locale &where, UErrorCode &status)
 Create BreakIterator for word-breaks using the given locale. More...
 
static BreakIteratorcreateLineInstance (const Locale &where, UErrorCode &status)
 Create BreakIterator for line-breaks using specified locale. More...
 
static BreakIteratorcreateCharacterInstance (const Locale &where, UErrorCode &status)
 Create BreakIterator for character-breaks using specified locale Returns an instance of a BreakIterator implementing character breaks. More...
 
static BreakIteratorcreateSentenceInstance (const Locale &where, UErrorCode &status)
 Create BreakIterator for sentence-breaks using specified locale Returns an instance of a BreakIterator implementing sentence breaks. More...
 
static BreakIteratorcreateTitleInstance (const Locale &where, UErrorCode &status)
 Create BreakIterator for title-casing breaks using the specified locale Returns an instance of a BreakIterator implementing title breaks. More...
 
static const LocalegetAvailableLocales (int32_t &count)
 Get the set of Locales for which TextBoundaries are installed. More...
 
static UnicodeStringgetDisplayName (const Locale &objectLocale, const Locale &displayLocale, UnicodeString &name)
 Get name of the object for the desired Locale, in the desired language. More...
 
static UnicodeStringgetDisplayName (const Locale &objectLocale, UnicodeString &name)
 Get name of the object for the desired Locale, in the language of the default locale. More...
 
static URegistryKey registerInstance (BreakIterator *toAdopt, const Locale &locale, UBreakIteratorType kind, UErrorCode &status)
 Register a new break iterator of the indicated kind, to use in the given locale. More...
 
static UBool unregister (URegistryKey key, UErrorCode &status)
 Unregister a previously-registered BreakIterator using the key returned from the register call. More...
 
static StringEnumerationgetAvailableLocales (void)
 Return a StringEnumeration over the locales available at the time of the call, including registered locales. More...
 

Protected Member Functions

 BreakIterator ()
 
 BreakIterator (const BreakIterator &other)
 
 BreakIterator (const Locale &valid, const Locale &actual)
 
BreakIteratoroperator= (const BreakIterator &other)
 

Friends

class ICUBreakIteratorFactory
 
class ICUBreakIteratorService
 

Detailed Description

The BreakIterator class implements methods for finding the location of boundaries in text.

BreakIterator is an abstract base class. Instances of BreakIterator maintain a current position and scan over text returning the index of characters where boundaries occur.

Line boundary analysis determines where a text string can be broken when line-wrapping. The mechanism correctly handles punctuation and hyphenated words.

Sentence boundary analysis allows selection with correct interpretation of periods within numbers and abbreviations, and trailing punctuation marks such as quotation marks and parentheses.

Word boundary analysis is used by search and replace functions, as well as within text editing applications that allow the user to select words with a double click. Word selection provides correct interpretation of punctuation marks within and following words. Characters that are not part of a word, such as symbols or punctuation marks, have word-breaks on both sides.

Character boundary analysis allows users to interact with characters as they expect to, for example, when moving the cursor through a text string. Character boundary analysis provides correct navigation of through character strings, regardless of how the character is stored. For example, an accented character might be stored as a base character and a diacritical mark. What users consider to be a character can differ between languages.

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/.

In addition to the C++ API defined in this header file, a plain C API with equivalent functionality is defined in the file ubrk.h

Code snippets illustrating the use of the Break Iterator APIs are available in the ICU User Guide, https://unicode-org.github.io/icu/userguide/boundaryanalysis/ and in the sample program icu/source/samples/break/break.cpp

Definition at line 106 of file brkiter.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
DONE 

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

Stable:
ICU 2.0

Definition at line 217 of file brkiter.h.

Constructor & Destructor Documentation

◆ ~BreakIterator()

virtual icu::BreakIterator::~BreakIterator ( )
virtual

destructor

Stable:
ICU 2.0

◆ BreakIterator() [1/3]

icu::BreakIterator::BreakIterator ( )
protected
Internal:
Do not use. This API is for internal use only.

◆ BreakIterator() [2/3]

icu::BreakIterator::BreakIterator ( const BreakIterator other)
protected
Internal:
Do not use. This API is for internal use only.

◆ BreakIterator() [3/3]

icu::BreakIterator::BreakIterator ( const Locale valid,
const Locale actual 
)
protected
Internal:
Do not use. This API is for internal use only.

Member Function Documentation

◆ adoptText()

virtual void icu::BreakIterator::adoptText ( CharacterIterator it)
pure virtual

Change the text over which this operates.

The text boundary is reset to the start. Note that setText(UText *) provides similar functionality to this function, and is more efficient.

Parameters
itThe CharacterIterator used to change the text.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ clone()

virtual BreakIterator * icu::BreakIterator::clone ( ) const
pure virtual

Return a polymorphic copy of this object.

This is an abstract method which subclasses implement.

Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ createBufferClone()

virtual BreakIterator * icu::BreakIterator::createBufferClone ( void *  stackBuffer,
int32_t &  BufferSize,
UErrorCode status 
)
pure virtual

Deprecated functionality.

Use clone() instead.

Thread safe client-buffer-based cloning operation Do NOT call delete on a safeclone, since 'new' is not used to create it.

Parameters
stackBufferuser allocated space for the new clone. If NULL new memory will be allocated. If buffer is not large enough, new memory will be allocated.
BufferSizereference to size of allocated space. If BufferSize == 0, a sufficient size for use in cloning will be returned ('pre-flighting') If BufferSize is not enough for a stack-based safe clone, new memory will be allocated.
statusto indicate whether the operation went on smoothly or there were errors An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any allocations were necessary.
Returns
pointer to the new clone
Deprecated:
ICU 52. Use clone() instead.

Implemented in icu::RuleBasedBreakIterator.

◆ createCharacterInstance()

static BreakIterator * icu::BreakIterator::createCharacterInstance ( const Locale where,
UErrorCode status 
)
static

Create BreakIterator for character-breaks using specified locale Returns an instance of a BreakIterator implementing character breaks.

Character breaks are boundaries of combining character sequences.

Parameters
wherethe locale.
statusThe error code.
Returns
A BreakIterator for character-breaks. The UErrorCode& status parameter is used to return status information to the user. To check whether the construction succeeded or not, you should check the value of U_SUCCESS(err). If you wish more detailed information, you can check for informational error results which still indicate success. U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For example, 'de_CH' was requested, but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the default locale data was used; neither the requested locale nor any of its fall back locales could be found. The caller owns the returned object and is responsible for deleting it.
Stable:
ICU 2.0

◆ createLineInstance()

static BreakIterator * icu::BreakIterator::createLineInstance ( const Locale where,
UErrorCode status 
)
static

Create BreakIterator for line-breaks using specified locale.

Returns an instance of a BreakIterator implementing line breaks. Line breaks are logically possible line breaks, actual line breaks are usually determined based on display width. LineBreak is useful for word wrapping text.

Parameters
wherethe locale.
statusThe error code.
Returns
A BreakIterator for line-breaks. The UErrorCode& status parameter is used to return status information to the user. To check whether the construction succeeded or not, you should check the value of U_SUCCESS(err). If you wish more detailed information, you can check for informational error results which still indicate success. U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For example, 'de_CH' was requested, but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the default locale data was used; neither the requested locale nor any of its fall back locales could be found. The caller owns the returned object and is responsible for deleting it.
Stable:
ICU 2.0

◆ createSentenceInstance()

static BreakIterator * icu::BreakIterator::createSentenceInstance ( const Locale where,
UErrorCode status 
)
static

Create BreakIterator for sentence-breaks using specified locale Returns an instance of a BreakIterator implementing sentence breaks.

Parameters
wherethe locale.
statusThe error code.
Returns
A BreakIterator for sentence-breaks. The UErrorCode& status parameter is used to return status information to the user. To check whether the construction succeeded or not, you should check the value of U_SUCCESS(err). If you wish more detailed information, you can check for informational error results which still indicate success. U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For example, 'de_CH' was requested, but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the default locale data was used; neither the requested locale nor any of its fall back locales could be found. The caller owns the returned object and is responsible for deleting it.
Stable:
ICU 2.0

◆ createTitleInstance()

static BreakIterator * icu::BreakIterator::createTitleInstance ( const Locale where,
UErrorCode status 
)
static

Create BreakIterator for title-casing breaks using the specified locale Returns an instance of a BreakIterator implementing title breaks.

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. See createWordInstance.

Parameters
wherethe locale.
statusThe error code.
Returns
A BreakIterator for title-breaks. The UErrorCode& status parameter is used to return status information to the user. To check whether the construction succeeded or not, you should check the value of U_SUCCESS(err). If you wish more detailed information, you can check for informational error results which still indicate success. U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For example, 'de_CH' was requested, but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the default locale data was used; neither the requested locale nor any of its fall back locales could be found. The caller owns the returned object and is responsible for deleting it.
Deprecated:
ICU 64 Use createWordInstance instead.

◆ createWordInstance()

static BreakIterator * icu::BreakIterator::createWordInstance ( const Locale where,
UErrorCode status 
)
static

Create BreakIterator for word-breaks using the given locale.

Returns an instance of a BreakIterator implementing word breaks. WordBreak is useful for word selection (ex. double click)

Parameters
wherethe locale.
statusthe error code
Returns
A BreakIterator for word-breaks. The UErrorCode& status parameter is used to return status information to the user. To check whether the construction succeeded or not, you should check the value of U_SUCCESS(err). If you wish more detailed information, you can check for informational error results which still indicate success. U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For example, 'de_CH' was requested, but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that the default locale data was used; neither the requested locale nor any of its fall back locales could be found. The caller owns the returned object and is responsible for deleting it.
Stable:
ICU 2.0

◆ current()

virtual int32_t icu::BreakIterator::current ( void  ) const
pure virtual

Return character index of the current iterator position within the text.

Returns
The boundary most recently returned.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ first()

virtual int32_t icu::BreakIterator::first ( void  )
pure virtual

Sets the current iteration position to the beginning of the text, position zero.

Returns
The offset of the beginning of the text, zero.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ following()

virtual int32_t icu::BreakIterator::following ( int32_t  offset)
pure virtual

Advance the iterator to the first boundary following the specified offset.

The value returned is always greater than the offset or the value BreakIterator.DONE

Parameters
offsetthe offset to begin scanning.
Returns
The first boundary after the specified offset.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ getAvailableLocales() [1/2]

static const Locale * icu::BreakIterator::getAvailableLocales ( int32_t &  count)
static

Get the set of Locales for which TextBoundaries are installed.

Note: this will not return locales added through the register call. To see the registered locales too, use the getAvailableLocales function that returns a StringEnumeration object

Parameters
countthe output parameter of number of elements in the locale list
Returns
available locales
Stable:
ICU 2.0

◆ getAvailableLocales() [2/2]

static StringEnumeration * icu::BreakIterator::getAvailableLocales ( void  )
static

Return a StringEnumeration over the locales available at the time of the call, including registered locales.

Returns
a StringEnumeration over the locales available at the time of the call
Stable:
ICU 2.4

◆ getDisplayName() [1/2]

static UnicodeString & icu::BreakIterator::getDisplayName ( const Locale objectLocale,
const Locale displayLocale,
UnicodeString name 
)
static

Get name of the object for the desired Locale, in the desired language.

Parameters
objectLocalemust be from getAvailableLocales.
displayLocalespecifies the desired locale for output.
namethe fill-in parameter of the return value Uses best match.
Returns
user-displayable name
Stable:
ICU 2.0

◆ getDisplayName() [2/2]

static UnicodeString & icu::BreakIterator::getDisplayName ( const Locale objectLocale,
UnicodeString name 
)
static

Get name of the object for the desired Locale, in the language of the default locale.

Parameters
objectLocalemust be from getMatchingLocales
namethe fill-in parameter of the return value
Returns
user-displayable name
Stable:
ICU 2.0

◆ getDynamicClassID()

virtual UClassID icu::BreakIterator::getDynamicClassID ( void  ) const
overridepure virtual

Return a polymorphic class ID for this object.

Different subclasses will return distinct unequal values.

Stable:
ICU 2.0

Reimplemented from icu::UObject.

Implemented in icu::RuleBasedBreakIterator.

◆ getLocale()

Locale icu::BreakIterator::getLocale ( ULocDataLocaleType  type,
UErrorCode status 
) const

Returns the locale for this break iterator.

Two flavors are available: valid and actual locale.

Stable:
ICU 2.8

◆ getLocaleID()

const char * icu::BreakIterator::getLocaleID ( ULocDataLocaleType  type,
UErrorCode status 
) const

Get the locale for this break iterator object.

You can choose between valid and actual locale.

Parameters
typetype of the locale we're looking for (valid or actual)
statuserror code for the operation
Returns
the locale
Internal:
Do not use. This API is for internal use only.

◆ getRuleStatus()

virtual int32_t icu::BreakIterator::getRuleStatus ( ) const
virtual

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
the status from the break rule that determined the boundary at the current iteration position.
See also
RuleBaseBreakIterator::getRuleStatus()
UWordBreak
Stable:
ICU 52

Reimplemented in icu::RuleBasedBreakIterator.

◆ getRuleStatusVec()

virtual int32_t icu::BreakIterator::getRuleStatusVec ( int32_t *  fillInVec,
int32_t  capacity,
UErrorCode status 
)
virtual

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

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

The returned status value(s) are stored into an array provided by the caller. The values are stored in sorted (ascending) order. If the capacity of the output array is insufficient to hold the data, the output will be truncated to the available length, and a U_BUFFER_OVERFLOW_ERROR will be signaled.

See also
RuleBaseBreakIterator::getRuleStatusVec
Parameters
fillInVecan array to be filled in with the status values.
capacitythe length of the supplied vector. A length of zero causes the function to return the number of status values, in the normal way, without attempting to store any values.
statusreceives error codes.
Returns
The number of rule status values from rules that determined the boundary at the current iteration position. In the event of a U_BUFFER_OVERFLOW_ERROR, the return value is the total number of status values that were available, not the reduced number that were actually returned.
See also
getRuleStatus
Stable:
ICU 52

Reimplemented in icu::RuleBasedBreakIterator.

◆ getText()

virtual CharacterIterator & icu::BreakIterator::getText ( void  ) const
pure virtual

Return a CharacterIterator over the text being analyzed.

Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ getUText()

virtual UText * icu::BreakIterator::getUText ( UText fillIn,
UErrorCode status 
) const
pure virtual

Get a UText for the text being analyzed.

The returned UText is a shallow clone of the UText used internally by the break iterator implementation. It can safely be used to access the text without impacting any break iterator operations, but the underlying text itself must not be altered.

Parameters
fillInA UText to be filled in. If NULL, a new UText will be allocated to hold the result.
statusreceives any error codes.
Returns
The current UText for this break iterator. If an input UText was provided, it will always be returned.
Stable:
ICU 3.4

Implemented in icu::RuleBasedBreakIterator.

◆ isBoundary()

virtual UBool icu::BreakIterator::isBoundary ( int32_t  offset)
pure virtual

Return true if the specified position is a boundary position.

As a side effect, the current position of the iterator is set to the first boundary position at or following the specified offset.

Parameters
offsetthe offset to check.
Returns
True if "offset" is a boundary position.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ isBufferClone()

UBool icu::BreakIterator::isBufferClone ( void  )
inline

Determine whether the BreakIterator was created in user memory by createBufferClone(), and thus should not be deleted.

Such objects must be closed by an explicit call to the destructor (not delete).

Deprecated:
ICU 52. Always delete the BreakIterator.

Definition at line 656 of file brkiter.h.

◆ last()

virtual int32_t icu::BreakIterator::last ( void  )
pure virtual

Set the iterator position to the index immediately BEYOND the last character in the text being scanned.

Returns
The index immediately BEYOND the last character in the text being scanned.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ next() [1/2]

virtual int32_t icu::BreakIterator::next ( int32_t  n)
pure virtual

Set the iterator position to the nth boundary from the current boundary.

Parameters
nthe number of boundaries to move by. A value of 0 does nothing. Negative values move to previous boundaries and positive values move to later boundaries.
Returns
The new iterator position, or DONE if there are fewer than |n| boundaries in the specified direction.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ next() [2/2]

virtual int32_t icu::BreakIterator::next ( void  )
pure virtual

Advance the iterator to the boundary following the current boundary.

Returns
The character index of the next text boundary or DONE if all boundaries have been returned.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ operator!=()

bool icu::BreakIterator::operator!= ( const BreakIterator rhs) const
inline

Returns the complement of the result of operator==.

Parameters
rhsThe BreakIterator to be compared for inequality
Returns
the complement of the result of operator==
Stable:
ICU 2.0

Definition at line 135 of file brkiter.h.

References icu::operator==().

◆ operator=()

BreakIterator & icu::BreakIterator::operator= ( const BreakIterator other)
protected
Internal:
Do not use. This API is for internal use only.. Assignment Operator, used by RuleBasedBreakIterator.

◆ operator==()

virtual bool icu::BreakIterator::operator== ( const BreakIterator ) const
pure virtual

Return true if another object is semantically equal to this one.

The other object should be an instance of the same subclass of BreakIterator. Objects of different subclasses are considered unequal.

Return true if this BreakIterator is at the same position in the same text, and is the same class and type (word, line, etc.) of BreakIterator, as the argument. Text is considered the same if it contains the same characters, it need not be the same object, and styles are not considered.

Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ preceding()

virtual int32_t icu::BreakIterator::preceding ( int32_t  offset)
pure virtual

Set the iterator position to the first boundary preceding the specified offset.

The value returned is always smaller than the offset or the value BreakIterator.DONE

Parameters
offsetthe offset to begin scanning.
Returns
The first boundary before the specified offset.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ previous()

virtual int32_t icu::BreakIterator::previous ( void  )
pure virtual

Set the iterator position to the boundary preceding the current boundary.

Returns
The character index of the previous text boundary or DONE if all boundaries have been returned.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ refreshInputText()

virtual BreakIterator & icu::BreakIterator::refreshInputText ( UText input,
UErrorCode status 
)
pure virtual

Set the subject text string upon which the break iterator is operating without changing any other aspect of the matching state.

The new and previous text strings must have the same content.

This function is intended for use in environments where ICU is operating on strings that may move around in memory. It provides a mechanism for notifying ICU that the string has been relocated, and providing a new UText to access the string in its new position.

Note that the break iterator implementation never copies the underlying text of a string being processed, but always operates directly on the original text provided by the user. Refreshing simply drops the references to the old text and replaces them with references to the new.

Caution: this function is normally used only by very specialized, system-level code. One example use case is with garbage collection that moves the text in memory.

Parameters
inputThe new (moved) text string.
statusReceives errors detected by this function.
Returns
*this
Stable:
ICU 49

Implemented in icu::RuleBasedBreakIterator.

◆ registerInstance()

static URegistryKey icu::BreakIterator::registerInstance ( BreakIterator toAdopt,
const Locale locale,
UBreakIteratorType  kind,
UErrorCode status 
)
static

Register a new break iterator of the indicated kind, to use in the given locale.

The break iterator will be adopted. 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 BreakIterators internally, this must be called at application startup, prior to any calls to BreakIterator::createXXXInstance to avoid undefined behavior.

Parameters
toAdoptthe BreakIterator instance to be adopted
localethe Locale for which this instance is to be registered
kindthe type of iterator for which this instance is to be registered
statusthe in/out status code, no special meanings are assigned
Returns
a registry key that can be used to unregister this instance
Stable:
ICU 2.4

◆ setText() [1/2]

virtual void icu::BreakIterator::setText ( const UnicodeString text)
pure virtual

Change the text over which this operates.

The text boundary is reset to the start.

The BreakIterator will retain a reference to the supplied string. The caller must not modify or delete the text while the BreakIterator retains the reference.

Parameters
textThe UnicodeString used to change the text.
Stable:
ICU 2.0

Implemented in icu::RuleBasedBreakIterator.

◆ setText() [2/2]

virtual void icu::BreakIterator::setText ( UText text,
UErrorCode status 
)
pure virtual

Reset the break iterator to operate over the text represented by the UText.

The iterator position is reset to the start.

This function makes a shallow clone of the supplied UText. This means that the caller is free to immediately close or otherwise reuse the Utext that was passed as a parameter, but that the underlying text itself must not be altered while being referenced by the break iterator.

All index positions returned by break iterator functions are native indices from the UText. For example, when breaking UTF-8 encoded text, the break positions returned by next(), previous(), etc. will be UTF-8 string indices, not UTF-16 positions.

Parameters
textThe UText used to change the text.
statusreceives any error codes.
Stable:
ICU 3.4

Implemented in icu::RuleBasedBreakIterator.

◆ unregister()

static UBool icu::BreakIterator::unregister ( URegistryKey  key,
UErrorCode status 
)
static

Unregister a previously-registered BreakIterator using the key returned from the register call.

Key becomes invalid after a successful call and should not be used again. The BreakIterator corresponding to the key will be deleted. Because ICU may choose to cache BreakIterators internally, this should be called during application shutdown, after all calls to BreakIterator::createXXXInstance to avoid undefined behavior.

Parameters
keythe registry key returned by a previous call to registerInstance
statusthe in/out status code, no special meanings are assigned
Returns
true if the iterator for the key was successfully unregistered
Stable:
ICU 2.4

Friends And Related Function Documentation

◆ ICUBreakIteratorFactory

friend class ICUBreakIteratorFactory
friend

Definition at line 630 of file brkiter.h.

◆ ICUBreakIteratorService

friend class ICUBreakIteratorService
friend

Definition at line 631 of file brkiter.h.


The documentation for this class was generated from the following file: