#include <brkiter.h>
Public Types | |
enum | { DONE = (int32_t)-1 } |
Public Member Functions | |
virtual | ~BreakIterator () |
destructor | |
virtual UBool | operator== (const BreakIterator &) const =0 |
Return true if another object is semantically equal to this one. | |
UBool | operator!= (const BreakIterator &rhs) const |
Returns the complement of the result of operator==. | |
virtual BreakIterator * | clone (void) const =0 |
Return a polymorphic copy of this object. | |
virtual UClassID | getDynamicClassID (void) const =0 |
Return a polymorphic class ID for this object. | |
virtual CharacterIterator & | getText (void) const =0 |
Return a CharacterIterator over the text being analyzed. | |
virtual UText * | getUText (UText *fillIn, UErrorCode &status) const =0 |
Get a UText for the text being analyzed. | |
virtual void | setText (const UnicodeString &text)=0 |
Change the text over which this operates. | |
virtual void | setText (UText *text, UErrorCode &status)=0 |
Reset the break iterator to operate over the text represented by the UText. | |
virtual void | adoptText (CharacterIterator *it)=0 |
Change the text over which this operates. | |
virtual int32_t | first (void)=0 |
Return the index of the first character in the text being scanned. | |
virtual int32_t | last (void)=0 |
Return the index immediately BEYOND the last character in the text being scanned. | |
virtual int32_t | previous (void)=0 |
Return the boundary preceding the current boundary. | |
virtual int32_t | next (void)=0 |
Return the boundary following the current boundary. | |
virtual int32_t | current (void) const =0 |
Return character index of the current interator position within the text. | |
virtual int32_t | following (int32_t offset)=0 |
Return the first boundary following the specified offset. | |
virtual int32_t | preceding (int32_t offset)=0 |
Return the first boundary preceding the specified offset. | |
virtual UBool | isBoundary (int32_t offset)=0 |
Return true if the specfied position is a boundary position. | |
virtual int32_t | next (int32_t n)=0 |
Return the nth boundary from the current boundary. | |
virtual BreakIterator * | createBufferClone (void *stackBuffer, int32_t &BufferSize, UErrorCode &status)=0 |
Thread safe client-buffer-based cloning operation Do NOT call delete on a safeclone, since 'new' is not used to create it. | |
UBool | isBufferClone (void) |
Determine whether the BreakIterator was created in user memory by createBufferClone(), and thus should not be deleted. | |
Locale | getLocale (ULocDataLocaleType type, UErrorCode &status) const |
Returns the locale for this break iterator. | |
const char * | getLocaleID (ULocDataLocaleType type, UErrorCode &status) const |
Get the locale for this break iterator object. | |
Static Public Member Functions | |
static BreakIterator * | createWordInstance (const Locale &where, UErrorCode &status) |
Create BreakIterator for word-breaks using the given locale. | |
static BreakIterator * | createLineInstance (const Locale &where, UErrorCode &status) |
Create BreakIterator for line-breaks using specified locale. | |
static BreakIterator * | createCharacterInstance (const Locale &where, UErrorCode &status) |
Create BreakIterator for character-breaks using specified locale Returns an instance of a BreakIterator implementing character breaks. | |
static BreakIterator * | createSentenceInstance (const Locale &where, UErrorCode &status) |
Create BreakIterator for sentence-breaks using specified locale Returns an instance of a BreakIterator implementing sentence breaks. | |
static BreakIterator * | createTitleInstance (const Locale &where, UErrorCode &status) |
Create BreakIterator for title-casing breaks using the specified locale Returns an instance of a BreakIterator implementing title breaks. | |
static const Locale * | getAvailableLocales (int32_t &count) |
Get the set of Locales for which TextBoundaries are installed. | |
static UnicodeString & | getDisplayName (const Locale &objectLocale, const Locale &displayLocale, UnicodeString &name) |
Get name of the object for the desired Locale, in the desired langauge. | |
static UnicodeString & | getDisplayName (const Locale &objectLocale, UnicodeString &name) |
Get name of the object for the desired Locale, in the langauge of the default locale. | |
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. | |
static UBool | unregister (URegistryKey key, UErrorCode &status) |
Unregister a previously-registered BreakIterator using the key returned from the register call. | |
static StringEnumeration * | getAvailableLocales (void) |
Return a StringEnumeration over the locales available at the time of the call, including registered locales. | |
Protected Member Functions | |
BreakIterator () | |
BreakIterator (const BreakIterator &other) | |
Protected Attributes | |
UBool | fBufferClone |
Friends | |
class | ICUBreakIteratorFactory |
class | ICUBreakIteratorService |
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 snippits illustrating the use of the Break Iterator APIs are available in the ICU User Guide, http://icu-project.org/userguide/boundaryAnalysis.html and in the sample program icu/source/samples/break/break.cpp"
Definition at line 100 of file brkiter.h.
anonymous enum |
DONE |
DONE is returned by previous() and next() after all valid boundaries have been returned.
|
virtual BreakIterator::~BreakIterator | ( | ) | [virtual] |
BreakIterator::BreakIterator | ( | ) | [protected] |
BreakIterator::BreakIterator | ( | const BreakIterator & | other | ) | [inline, protected] |
virtual void 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.
it | The CharacterIterator used to change the text. |
Implemented in RuleBasedBreakIterator.
virtual BreakIterator* BreakIterator::clone | ( | void | ) | const [pure virtual] |
Return a polymorphic copy of this object.
This is an abstract method which subclasses implement.
Implemented in RuleBasedBreakIterator.
virtual BreakIterator* BreakIterator::createBufferClone | ( | void * | stackBuffer, | |
int32_t & | BufferSize, | |||
UErrorCode & | status | |||
) | [pure virtual] |
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 NULL 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 in RuleBasedBreakIterator.
static BreakIterator* 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.
where | the locale. | |
status | The error code. |
static BreakIterator* 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.
where | the locale. | |
status | The error code. |
static BreakIterator* 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.
where | the locale. | |
status | The error code. |
static BreakIterator* 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 Word Boundary iterator.createWordInstance
where | the locale. | |
status | The error code. |
static BreakIterator* 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)
where | the locale. | |
status | the error code |
virtual int32_t BreakIterator::current | ( | void | ) | const [pure virtual] |
Return character index of the current interator position within the text.
Implemented in RuleBasedBreakIterator.
virtual int32_t BreakIterator::first | ( | void | ) | [pure virtual] |
Return the index of the first character in the text being scanned.
Implemented in RuleBasedBreakIterator.
virtual int32_t BreakIterator::following | ( | int32_t | offset | ) | [pure virtual] |
Return the first boundary following the specified offset.
The value returned is always greater than the offset or the value BreakIterator.DONE
offset | the offset to begin scanning. |
Implemented in RuleBasedBreakIterator.
static StringEnumeration* BreakIterator::getAvailableLocales | ( | void | ) | [static] |
Return a StringEnumeration over the locales available at the time of the call, including registered locales.
static const Locale* 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
count | the output parameter of number of elements in the locale list |
static UnicodeString& BreakIterator::getDisplayName | ( | const Locale & | objectLocale, | |
UnicodeString & | name | |||
) | [static] |
static UnicodeString& BreakIterator::getDisplayName | ( | const Locale & | objectLocale, | |
const Locale & | displayLocale, | |||
UnicodeString & | name | |||
) | [static] |
virtual UClassID BreakIterator::getDynamicClassID | ( | void | ) | const [pure virtual] |
Return a polymorphic class ID for this object.
Different subclasses will return distinct unequal values.
Implements UObject.
Implemented in RuleBasedBreakIterator.
Locale BreakIterator::getLocale | ( | ULocDataLocaleType | type, | |
UErrorCode & | status | |||
) | const |
Returns the locale for this break iterator.
Two flavors are available: valid and actual locale.
const char* 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 CharacterIterator& BreakIterator::getText | ( | void | ) | const [pure virtual] |
Return a CharacterIterator over the text being analyzed.
Implemented in RuleBasedBreakIterator.
virtual UText* 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.
fillIn | A UText to be filled in. If NULL, a new UText will be allocated to hold the result. | |
status | receives any error codes. |
Implemented in RuleBasedBreakIterator.
virtual UBool BreakIterator::isBoundary | ( | int32_t | offset | ) | [pure virtual] |
Return true if the specfied 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 in RuleBasedBreakIterator.
UBool 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).
Definition at line 546 of file brkiter.h.
References fBufferClone.
virtual int32_t BreakIterator::last | ( | void | ) | [pure virtual] |
Return the index immediately BEYOND the last character in the text being scanned.
Implemented in RuleBasedBreakIterator.
virtual int32_t BreakIterator::next | ( | int32_t | n | ) | [pure virtual] |
Return the nth boundary from the current boundary.
n | which boundary to return. A value of 0 does nothing. Negative values move to previous boundaries and positive values move to later boundaries. |
Implemented in RuleBasedBreakIterator.
virtual int32_t BreakIterator::next | ( | void | ) | [pure virtual] |
Return the boundary following the current boundary.
Implemented in RuleBasedBreakIterator.
UBool BreakIterator::operator!= | ( | const BreakIterator & | rhs | ) | const [inline] |
Returns the complement of the result of operator==.
rhs | The BreakIterator to be compared for inequality |
Reimplemented in RuleBasedBreakIterator.
virtual UBool 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.
Implemented in RuleBasedBreakIterator.
virtual int32_t BreakIterator::preceding | ( | int32_t | offset | ) | [pure virtual] |
Return the first boundary preceding the specified offset.
The value returned is always smaller than the offset or the value BreakIterator.DONE
offset | the offset to begin scanning. |
Implemented in RuleBasedBreakIterator.
virtual int32_t BreakIterator::previous | ( | void | ) | [pure virtual] |
Return the boundary preceding the current boundary.
Implemented in RuleBasedBreakIterator.
static URegistryKey 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.
toAdopt | the BreakIterator instance to be adopted | |
locale | the Locale 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 |
virtual void 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.
text | The UText used to change the text. | |
status | receives any error codes. |
Implemented in RuleBasedBreakIterator.
virtual void BreakIterator::setText | ( | const UnicodeString & | text | ) | [pure virtual] |
Change the text over which this operates.
The text boundary is reset to the start.
text | The UnicodeString used to change the text. |
Implemented in RuleBasedBreakIterator.
static UBool 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.
key | the registry key returned by a previous call to registerInstance | |
status | the in/out status code, no special meanings are assigned |
UBool BreakIterator::fBufferClone [protected] |
Definition at line 529 of file brkiter.h.
Referenced by isBufferClone().