ICU 78.1 78.1 |
TheBreakIterator class implements methods for finding the location of boundaries in text.More...
#include <brkiter.h>

Public Types | |
| enum | {DONE = static_cast<int32_t>(-1) } |
Public Member Functions | |
| virtualU_COMMON_API | ~BreakIterator () |
| destructorMore... | |
| virtualU_COMMON_API bool | operator== (constBreakIterator &) const =0 |
| Return true if another object is semantically equal to this one.More... | |
| U_COMMON_API bool | operator!= (constBreakIterator &rhs) const |
| Returns the complement of the result of operator==.More... | |
| virtualU_COMMON_APIBreakIterator * | clone () const =0 |
| Return a polymorphic copy of this object.More... | |
| virtualU_COMMON_APIUClassID | getDynamicClassID () const override=0 |
| Return a polymorphic class ID for this object.More... | |
| virtualU_COMMON_APICharacterIterator & | getText () const =0 |
| Return aCharacterIterator over the text being analyzed.More... | |
| virtualU_COMMON_APIUText * | getUText (UText *fillIn,UErrorCode &status) const =0 |
| Get aUText for the text being analyzed.More... | |
| virtualU_COMMON_API void | setText (constUnicodeString &text)=0 |
| Change the text over which this operates.More... | |
| virtualU_COMMON_API void | setText (UText *text,UErrorCode &status)=0 |
| Reset the break iterator to operate over the text represented by theUText.More... | |
| virtualU_COMMON_API void | adoptText (CharacterIterator *it)=0 |
| Change the text over which this operates.More... | |
| virtualU_COMMON_API int32_t | first ()=0 |
| Sets the current iteration position to the beginning of the text, position zero.More... | |
| virtualU_COMMON_API int32_t | last ()=0 |
| Set the iterator position to the index immediately BEYOND the last character in the text being scanned.More... | |
| virtualU_COMMON_API int32_t | previous ()=0 |
| Set the iterator position to the boundary preceding the current boundary.More... | |
| virtualU_COMMON_API int32_t | next ()=0 |
| Advance the iterator to the boundary following the current boundary.More... | |
| virtualU_COMMON_API int32_t | current () const =0 |
| Return character index of the current iterator position within the text.More... | |
| virtualU_COMMON_API int32_t | following (int32_t offset)=0 |
| Advance the iterator to the first boundary following the specified offset.More... | |
| virtualU_COMMON_API int32_t | preceding (int32_t offset)=0 |
| Set the iterator position to the first boundary preceding the specified offset.More... | |
| virtualU_COMMON_APIUBool | isBoundary (int32_t offset)=0 |
| Return true if the specified position is a boundary position.More... | |
| virtualU_COMMON_API int32_t | next (int32_t n)=0 |
| Set the iterator position to the nth boundary from the current boundary.More... | |
| virtualU_COMMON_API int32_t | getRuleStatus () const |
| For RuleBasedBreakIterators, return the status tag from the break rule that determined the boundary at the current iteration position.More... | |
| virtualU_COMMON_API 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... | |
| virtualU_COMMON_APIBreakIterator * | createBufferClone (void *stackBuffer, int32_t &BufferSize,UErrorCode &status)=0 |
| Deprecated functionality.More... | |
| U_COMMON_APIUBool | isBufferClone () |
| Determine whether theBreakIterator was created in user memory bycreateBufferClone(), and thus should not be deleted.More... | |
| U_COMMON_APILocale | getLocale (ULocDataLocaleType type,UErrorCode &status) const |
| Returns the locale for this break iterator.More... | |
| U_COMMON_API const char * | getLocaleID (ULocDataLocaleType type,UErrorCode &status) const |
| Get the locale for this break iterator object.More... | |
| virtualU_COMMON_APIBreakIterator & | refreshInputText (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 fromicu::UObject | |
| virtual | ~UObject () |
| Destructor.More... | |
Static Public Member Functions | |
| staticU_COMMON_APIBreakIterator * | createWordInstance (constLocale &where,UErrorCode &status) |
| CreateBreakIterator for word-breaks using the given locale.More... | |
| staticU_COMMON_APIBreakIterator * | createLineInstance (constLocale &where,UErrorCode &status) |
| CreateBreakIterator for line-breaks using specified locale.More... | |
| staticU_COMMON_APIBreakIterator * | createCharacterInstance (constLocale &where,UErrorCode &status) |
| CreateBreakIterator for character-breaks using specified locale Returns an instance of aBreakIterator implementing character breaks.More... | |
| staticU_COMMON_APIBreakIterator * | createSentenceInstance (constLocale &where,UErrorCode &status) |
| CreateBreakIterator for sentence-breaks using specified locale Returns an instance of aBreakIterator implementing sentence breaks.More... | |
| staticU_COMMON_APIBreakIterator * | createTitleInstance (constLocale &where,UErrorCode &status) |
| CreateBreakIterator for title-casing breaks using the specified locale Returns an instance of aBreakIterator implementing title breaks.More... | |
| staticU_COMMON_API constLocale * | getAvailableLocales (int32_t &count) |
| Get the set of Locales for which TextBoundaries are installed.More... | |
| staticU_COMMON_APIUnicodeString & | getDisplayName (constLocale &objectLocale, constLocale &displayLocale,UnicodeString &name) |
| Get name of the object for the desiredLocale, in the desired language.More... | |
| staticU_COMMON_APIUnicodeString & | getDisplayName (constLocale &objectLocale,UnicodeString &name) |
| Get name of the object for the desiredLocale, in the language of the default locale.More... | |
| staticU_COMMON_APIURegistryKey | registerInstance (BreakIterator *toAdopt, constLocale &locale,UBreakIteratorType kind,UErrorCode &status) |
| Register a new break iterator of the indicated kind, to use in the given locale.More... | |
| staticU_COMMON_APIUBool | unregister (URegistryKey key,UErrorCode &status) |
| Unregister a previously-registeredBreakIterator using the key returned from the register call.More... | |
| staticU_COMMON_APIStringEnumeration * | getAvailableLocales () |
| Return aStringEnumeration over the locales available at the time of the call, including registered locales.More... | |
Protected Member Functions | |
| U_COMMON_API | BreakIterator () |
| U_COMMON_API | BreakIterator (constBreakIterator &other) |
| U_COMMON_API | BreakIterator (constLocale &valid, constLocale &actual) |
| U_COMMON_APIBreakIterator & | operator= (constBreakIterator &other) |
Friends | |
| class | ICUBreakIteratorFactory |
| class | ICUBreakIteratorService |
TheBreakIterator class implements methods for finding the location of boundaries in text.
BreakIterator is an abstract base class. Instances ofBreakIterator 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 athttp://www.unicode.org/reports/tr14/ andhttp://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 fileubrk.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
| anonymous enum |
| Enumerator | |
|---|---|
| DONE | DONE is returned byprevious() andnext() after all valid boundaries have been returned.
|
| virtual |
destructor
| protected |
This API is for internal use only.
| protected |
This API is for internal use only.
| protected |
This API is for internal use only.
| 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.
| it | TheCharacterIterator used to change the text. |
Implemented inicu::RuleBasedBreakIterator.
| pure virtual |
Return a polymorphic copy of this object.
This is an abstract method which subclasses implement.
Implemented inicu::RuleBasedBreakIterator.
| pure virtual |
Deprecated functionality.
Useclone() instead.
Thread safe client-buffer-based cloning operation Do NOT call delete on a safeclone, since 'new' is not used to create it.
| stackBuffer | user allocated space for the new clone. If nullptr new memory will be allocated. If buffer is not large enough, new memory will be allocated. |
| BufferSize | reference 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. |
| status | to 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. |
Implemented inicu::RuleBasedBreakIterator.
| static |
CreateBreakIterator for character-breaks using specified locale Returns an instance of aBreakIterator implementing character breaks.
Character breaks are boundaries of combining character sequences.
| where | the locale. |
| status | The error code. |
| static |
CreateBreakIterator for line-breaks using specified locale.
Returns an instance of aBreakIterator 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.
| where | the locale. |
| status | The error code. |
| static |
CreateBreakIterator for sentence-breaks using specified locale Returns an instance of aBreakIterator implementing sentence breaks.
| where | the locale. |
| status | The error code. |
| static |
CreateBreakIterator for title-casing breaks using the specified locale Returns an instance of aBreakIterator 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. SeecreateWordInstance.
| where | the locale. |
| status | The error code. |
| static |
CreateBreakIterator for word-breaks using the given locale.
Returns an instance of aBreakIterator implementing word breaks. WordBreak is useful for word selection (ex. double click)
| where | the locale. |
| status | the error code |
| pure virtual |
Return character index of the current iterator position within the text.
Implemented inicu::RuleBasedBreakIterator.
| pure virtual |
Sets the current iteration position to the beginning of the text, position zero.
Implemented inicu::RuleBasedBreakIterator.
| pure virtual |
Advance the iterator to the first boundary following the specified offset.
The value returned is always greater than the offset or the valueBreakIterator.DONE
| offset | the offset to begin scanning. |
Implemented inicu::RuleBasedBreakIterator.
| static |
Return aStringEnumeration over the locales available at the time of the call, including registered locales.
| 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 aStringEnumeration object
| count | the output parameter of number of elements in the locale list |
| static |
| static |
| overridepure virtual |
Return a polymorphic class ID for this object.
Different subclasses will return distinct unequal values.
Reimplemented fromicu::UObject.
Implemented inicu::RuleBasedBreakIterator.
| U_COMMON_APILocale icu::BreakIterator::getLocale | ( | ULocDataLocaleType | type, |
| UErrorCode & | status | ||
| ) | const |
Returns the locale for this break iterator.
Two flavors are available: valid and actual locale.
| U_COMMON_API 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.
| type | type of the locale we're looking for (valid or actual) |
| status | error code for the operation |
| 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.
Reimplemented inicu::RuleBasedBreakIterator.
| 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.
| fillInVec | an array to be filled in with the status values. |
| capacity | the 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. |
| status | receives error codes. |
Reimplemented inicu::RuleBasedBreakIterator.
| pure virtual |
Return aCharacterIterator over the text being analyzed.
Implemented inicu::RuleBasedBreakIterator.
| pure virtual |
Get aUText for the text being analyzed.
The returnedUText is a shallow clone of theUText 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.
| fillIn | AUText to be filled in. If nullptr, a newUText will be allocated to hold the result. |
| status | receives any error codes. |
Implemented inicu::RuleBasedBreakIterator.
| 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.
| offset | the offset to check. |
Implemented inicu::RuleBasedBreakIterator.
| inline |
Determine whether theBreakIterator was created in user memory bycreateBufferClone(), and thus should not be deleted.
Such objects must be closed by an explicit call to the destructor (not delete).
| pure virtual |
Set the iterator position to the index immediately BEYOND the last character in the text being scanned.
Implemented inicu::RuleBasedBreakIterator.
| pure virtual |
Advance the iterator to the boundary following the current boundary.
Implemented inicu::RuleBasedBreakIterator.
| pure virtual |
Set the iterator position to the nth boundary from the current boundary.
| n | the 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. |
Implemented inicu::RuleBasedBreakIterator.
| inline |
Returns the complement of the result of operator==.
| rhs | TheBreakIterator to be compared for inequality |
Definition at line135 of filebrkiter.h.
Referencesicu::operator==().
| protected |
This API is for internal use only.. Assignment Operator, used byRuleBasedBreakIterator.
| pure virtual |
Return true if another object is semantically equal to this one.
The other object should be an instance of the same subclass ofBreakIterator. Objects of different subclasses are considered unequal.
Return true if thisBreakIterator is at the same position in the same text, and is the same class and type (word, line, etc.) ofBreakIterator, 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.
Implemented inicu::RuleBasedBreakIterator.
Referenced byicu::RuleBasedBreakIterator::operator!=().
| 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 valueBreakIterator.DONE
| offset | the offset to begin scanning. |
Implemented inicu::RuleBasedBreakIterator.
| pure virtual |
Set the iterator position to the boundary preceding the current boundary.
Implemented inicu::RuleBasedBreakIterator.
| 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 newUText 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.
| input | The new (moved) text string. |
| status | Receives errors detected by this function. |
Implemented inicu::RuleBasedBreakIterator.
| 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.
| toAdopt | theBreakIterator instance to be adopted |
| locale | theLocale for which this instance is to be registered |
| kind | the type of iterator for which this instance is to be registered |
| status | the in/out status code, no special meanings are assigned |
| pure virtual |
Change the text over which this operates.
The text boundary is reset to the start.
TheBreakIterator will retain a reference to the supplied string. The caller must not modify or delete the text while theBreakIterator retains the reference.
| text | TheUnicodeString used to change the text. |
Implemented inicu::RuleBasedBreakIterator.
| pure virtual |
Reset the break iterator to operate over the text represented by theUText.
The iterator position is reset to the start.
This function makes a shallow clone of the suppliedUText. 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 theUText. For example, when breaking UTF-8 encoded text, the break positions returned bynext(),previous(), etc. will be UTF-8 string indices, not UTF-16 positions.
| text | TheUText used to change the text. |
| status | receives any error codes. |
Implemented inicu::RuleBasedBreakIterator.
| static |
Unregister a previously-registeredBreakIterator using the key returned from the register call.
Key becomes invalid after a successful call and should not be used again. TheBreakIterator 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.
| key | the registry key returned by a previous call to registerInstance |
| status | the in/out status code, no special meanings are assigned |