jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************** jpayne@69: * Copyright (C) 1997-2016, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ******************************************************************************** jpayne@69: * jpayne@69: * File brkiter.h jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 02/18/97 aliu Added typedef for TextCount. Made DONE const. jpayne@69: * 05/07/97 aliu Fixed DLL declaration. jpayne@69: * 07/09/97 jfitz Renamed BreakIterator and interface synced with JDK jpayne@69: * 08/11/98 helena Sync-up JDK1.2. jpayne@69: * 01/13/2000 helena Added UErrorCode parameter to createXXXInstance methods. jpayne@69: ******************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef BRKITER_H jpayne@69: #define BRKITER_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Break Iterator. jpayne@69: */ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #if UCONFIG_NO_BREAK_ITERATION jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /* jpayne@69: * Allow the declaration of APIs with pointers to BreakIterator jpayne@69: * even when break iteration is removed from the build. jpayne@69: */ jpayne@69: class BreakIterator; jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #else jpayne@69: jpayne@69: #include "unicode/uobject.h" jpayne@69: #include "unicode/unistr.h" jpayne@69: #include "unicode/chariter.h" jpayne@69: #include "unicode/locid.h" jpayne@69: #include "unicode/ubrk.h" jpayne@69: #include "unicode/strenum.h" jpayne@69: #include "unicode/utext.h" jpayne@69: #include "unicode/umisc.h" jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * The BreakIterator class implements methods for finding the location jpayne@69: * of boundaries in text. BreakIterator is an abstract base class. jpayne@69: * Instances of BreakIterator maintain a current position and scan over jpayne@69: * text returning the index of characters where boundaries occur. jpayne@69: *

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

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

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

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

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

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

jpayne@69: * Code snippets illustrating the use of the Break Iterator APIs jpayne@69: * are available in the ICU User Guide, jpayne@69: * http://icu-project.org/userguide/boundaryAnalysis.html jpayne@69: * and in the sample program icu/source/samples/break/break.cpp jpayne@69: * jpayne@69: */ jpayne@69: class U_COMMON_API BreakIterator : public UObject { jpayne@69: public: jpayne@69: /** jpayne@69: * destructor jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual ~BreakIterator(); jpayne@69: jpayne@69: /** jpayne@69: * Return true if another object is semantically equal to this jpayne@69: * one. The other object should be an instance of the same subclass of jpayne@69: * BreakIterator. Objects of different subclasses are considered jpayne@69: * unequal. jpayne@69: *

jpayne@69: * Return true if this BreakIterator is at the same position in the jpayne@69: * same text, and is the same class and type (word, line, etc.) of jpayne@69: * BreakIterator, as the argument. Text is considered the same if jpayne@69: * it contains the same characters, it need not be the same jpayne@69: * object, and styles are not considered. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UBool operator==(const BreakIterator&) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Returns the complement of the result of operator== jpayne@69: * @param rhs The BreakIterator to be compared for inequality jpayne@69: * @return the complement of the result of operator== jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UBool operator!=(const BreakIterator& rhs) const { return !operator==(rhs); } jpayne@69: jpayne@69: /** jpayne@69: * Return a polymorphic copy of this object. This is an abstract jpayne@69: * method which subclasses implement. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual BreakIterator* clone() const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Return a polymorphic class ID for this object. Different subclasses jpayne@69: * will return distinct unequal values. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID(void) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Return a CharacterIterator over the text being analyzed. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual CharacterIterator& getText(void) const = 0; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Get a UText for the text being analyzed. jpayne@69: * The returned UText is a shallow clone of the UText used internally jpayne@69: * by the break iterator implementation. It can safely be used to jpayne@69: * access the text without impacting any break iterator operations, jpayne@69: * but the underlying text itself must not be altered. jpayne@69: * jpayne@69: * @param fillIn A UText to be filled in. If NULL, a new UText will be jpayne@69: * allocated to hold the result. jpayne@69: * @param status receives any error codes. jpayne@69: * @return The current UText for this break iterator. If an input jpayne@69: * UText was provided, it will always be returned. jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: virtual UText *getUText(UText *fillIn, UErrorCode &status) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Change the text over which this operates. The text boundary is jpayne@69: * reset to the start. jpayne@69: * jpayne@69: * The BreakIterator will retain a reference to the supplied string. jpayne@69: * The caller must not modify or delete the text while the BreakIterator jpayne@69: * retains the reference. jpayne@69: * jpayne@69: * @param text The UnicodeString used to change the text. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setText(const UnicodeString &text) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Reset the break iterator to operate over the text represented by jpayne@69: * the UText. The iterator position is reset to the start. jpayne@69: * jpayne@69: * This function makes a shallow clone of the supplied UText. This means jpayne@69: * that the caller is free to immediately close or otherwise reuse the jpayne@69: * Utext that was passed as a parameter, but that the underlying text itself jpayne@69: * must not be altered while being referenced by the break iterator. jpayne@69: * jpayne@69: * All index positions returned by break iterator functions are jpayne@69: * native indices from the UText. For example, when breaking UTF-8 jpayne@69: * encoded text, the break positions returned by next(), previous(), etc. jpayne@69: * will be UTF-8 string indices, not UTF-16 positions. jpayne@69: * jpayne@69: * @param text The UText used to change the text. jpayne@69: * @param status receives any error codes. jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: virtual void setText(UText *text, UErrorCode &status) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Change the text over which this operates. The text boundary is jpayne@69: * reset to the start. jpayne@69: * Note that setText(UText *) provides similar functionality to this function, jpayne@69: * and is more efficient. jpayne@69: * @param it The CharacterIterator used to change the text. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void adoptText(CharacterIterator* it) = 0; jpayne@69: jpayne@69: enum { jpayne@69: /** jpayne@69: * DONE is returned by previous() and next() after all valid jpayne@69: * boundaries have been returned. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DONE = (int32_t)-1 jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * Sets the current iteration position to the beginning of the text, position zero. jpayne@69: * @return The offset of the beginning of the text, zero. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t first(void) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Set the iterator position to the index immediately BEYOND the last character in the text being scanned. jpayne@69: * @return The index immediately BEYOND the last character in the text being scanned. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t last(void) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Set the iterator position to the boundary preceding the current boundary. jpayne@69: * @return The character index of the previous text boundary or DONE if all jpayne@69: * boundaries have been returned. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t previous(void) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Advance the iterator to the boundary following the current boundary. jpayne@69: * @return The character index of the next text boundary or DONE if all jpayne@69: * boundaries have been returned. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t next(void) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Return character index of the current iterator position within the text. jpayne@69: * @return The boundary most recently returned. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t current(void) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Advance the iterator to the first boundary following the specified offset. jpayne@69: * The value returned is always greater than the offset or jpayne@69: * the value BreakIterator.DONE jpayne@69: * @param offset the offset to begin scanning. jpayne@69: * @return The first boundary after the specified offset. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t following(int32_t offset) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Set the iterator position to the first boundary preceding the specified offset. jpayne@69: * The value returned is always smaller than the offset or jpayne@69: * the value BreakIterator.DONE jpayne@69: * @param offset the offset to begin scanning. jpayne@69: * @return The first boundary before the specified offset. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t preceding(int32_t offset) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Return true if the specified position is a boundary position. jpayne@69: * As a side effect, the current position of the iterator is set jpayne@69: * to the first boundary position at or following the specified offset. jpayne@69: * @param offset the offset to check. jpayne@69: * @return True if "offset" is a boundary position. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UBool isBoundary(int32_t offset) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Set the iterator position to the nth boundary from the current boundary jpayne@69: * @param n the number of boundaries to move by. A value of 0 jpayne@69: * does nothing. Negative values move to previous boundaries jpayne@69: * and positive values move to later boundaries. jpayne@69: * @return The new iterator position, or jpayne@69: * DONE if there are fewer than |n| boundaries in the specified direction. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t next(int32_t n) = 0; jpayne@69: jpayne@69: /** jpayne@69: * For RuleBasedBreakIterators, return the status tag from the break rule jpayne@69: * that determined the boundary at the current iteration position. jpayne@69: *

jpayne@69: * For break iterator types that do not support a rule status, jpayne@69: * a default value of 0 is returned. jpayne@69: *

jpayne@69: * @return the status from the break rule that determined the boundary at jpayne@69: * the current iteration position. jpayne@69: * @see RuleBaseBreakIterator::getRuleStatus() jpayne@69: * @see UWordBreak jpayne@69: * @stable ICU 52 jpayne@69: */ jpayne@69: virtual int32_t getRuleStatus() const; jpayne@69: jpayne@69: /** jpayne@69: * For RuleBasedBreakIterators, get the status (tag) values from the break rule(s) jpayne@69: * that determined the boundary at the current iteration position. jpayne@69: *

jpayne@69: * For break iterator types that do not support rule status, jpayne@69: * no values are returned. jpayne@69: *

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

jpayne@69: * @see RuleBaseBreakIterator::getRuleStatusVec jpayne@69: * jpayne@69: * @param fillInVec an array to be filled in with the status values. jpayne@69: * @param capacity the length of the supplied vector. A length of zero causes jpayne@69: * the function to return the number of status values, in the jpayne@69: * normal way, without attempting to store any values. jpayne@69: * @param status receives error codes. jpayne@69: * @return The number of rule status values from rules that determined jpayne@69: * the boundary at the current iteration position. jpayne@69: * In the event of a U_BUFFER_OVERFLOW_ERROR, the return value jpayne@69: * is the total number of status values that were available, jpayne@69: * not the reduced number that were actually returned. jpayne@69: * @see getRuleStatus jpayne@69: * @stable ICU 52 jpayne@69: */ jpayne@69: virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * Create BreakIterator for word-breaks using the given locale. jpayne@69: * Returns an instance of a BreakIterator implementing word breaks. jpayne@69: * WordBreak is useful for word selection (ex. double click) jpayne@69: * @param where the locale. jpayne@69: * @param status the error code jpayne@69: * @return A BreakIterator for word-breaks. The UErrorCode& status jpayne@69: * parameter is used to return status information to the user. jpayne@69: * To check whether the construction succeeded or not, you should check jpayne@69: * the value of U_SUCCESS(err). If you wish more detailed information, you jpayne@69: * can check for informational error results which still indicate success. jpayne@69: * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For jpayne@69: * example, 'de_CH' was requested, but nothing was found there, so 'de' was jpayne@69: * used. U_USING_DEFAULT_WARNING indicates that the default locale data was jpayne@69: * used; neither the requested locale nor any of its fall back locales jpayne@69: * could be found. jpayne@69: * The caller owns the returned object and is responsible for deleting it. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static BreakIterator* U_EXPORT2 jpayne@69: createWordInstance(const Locale& where, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Create BreakIterator for line-breaks using specified locale. jpayne@69: * Returns an instance of a BreakIterator implementing line breaks. Line jpayne@69: * breaks are logically possible line breaks, actual line breaks are jpayne@69: * usually determined based on display width. jpayne@69: * LineBreak is useful for word wrapping text. jpayne@69: * @param where the locale. jpayne@69: * @param status The error code. jpayne@69: * @return A BreakIterator for line-breaks. The UErrorCode& status jpayne@69: * parameter is used to return status information to the user. jpayne@69: * To check whether the construction succeeded or not, you should check jpayne@69: * the value of U_SUCCESS(err). If you wish more detailed information, you jpayne@69: * can check for informational error results which still indicate success. jpayne@69: * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For jpayne@69: * example, 'de_CH' was requested, but nothing was found there, so 'de' was jpayne@69: * used. U_USING_DEFAULT_WARNING indicates that the default locale data was jpayne@69: * used; neither the requested locale nor any of its fall back locales jpayne@69: * could be found. jpayne@69: * The caller owns the returned object and is responsible for deleting it. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static BreakIterator* U_EXPORT2 jpayne@69: createLineInstance(const Locale& where, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Create BreakIterator for character-breaks using specified locale jpayne@69: * Returns an instance of a BreakIterator implementing character breaks. jpayne@69: * Character breaks are boundaries of combining character sequences. jpayne@69: * @param where the locale. jpayne@69: * @param status The error code. jpayne@69: * @return A BreakIterator for character-breaks. The UErrorCode& status jpayne@69: * parameter is used to return status information to the user. jpayne@69: * To check whether the construction succeeded or not, you should check jpayne@69: * the value of U_SUCCESS(err). If you wish more detailed information, you jpayne@69: * can check for informational error results which still indicate success. jpayne@69: * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For jpayne@69: * example, 'de_CH' was requested, but nothing was found there, so 'de' was jpayne@69: * used. U_USING_DEFAULT_WARNING indicates that the default locale data was jpayne@69: * used; neither the requested locale nor any of its fall back locales jpayne@69: * could be found. jpayne@69: * The caller owns the returned object and is responsible for deleting it. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static BreakIterator* U_EXPORT2 jpayne@69: createCharacterInstance(const Locale& where, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Create BreakIterator for sentence-breaks using specified locale jpayne@69: * Returns an instance of a BreakIterator implementing sentence breaks. jpayne@69: * @param where the locale. jpayne@69: * @param status The error code. jpayne@69: * @return A BreakIterator for sentence-breaks. The UErrorCode& status jpayne@69: * parameter is used to return status information to the user. jpayne@69: * To check whether the construction succeeded or not, you should check jpayne@69: * the value of U_SUCCESS(err). If you wish more detailed information, you jpayne@69: * can check for informational error results which still indicate success. jpayne@69: * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For jpayne@69: * example, 'de_CH' was requested, but nothing was found there, so 'de' was jpayne@69: * used. U_USING_DEFAULT_WARNING indicates that the default locale data was jpayne@69: * used; neither the requested locale nor any of its fall back locales jpayne@69: * could be found. jpayne@69: * The caller owns the returned object and is responsible for deleting it. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static BreakIterator* U_EXPORT2 jpayne@69: createSentenceInstance(const Locale& where, UErrorCode& status); jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Create BreakIterator for title-casing breaks using the specified locale jpayne@69: * Returns an instance of a BreakIterator implementing title breaks. jpayne@69: * The iterator returned locates title boundaries as described for jpayne@69: * Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration, jpayne@69: * please use a word boundary iterator. See {@link #createWordInstance }. jpayne@69: * jpayne@69: * @param where the locale. jpayne@69: * @param status The error code. jpayne@69: * @return A BreakIterator for title-breaks. The UErrorCode& status jpayne@69: * parameter is used to return status information to the user. jpayne@69: * To check whether the construction succeeded or not, you should check jpayne@69: * the value of U_SUCCESS(err). If you wish more detailed information, you jpayne@69: * can check for informational error results which still indicate success. jpayne@69: * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For jpayne@69: * example, 'de_CH' was requested, but nothing was found there, so 'de' was jpayne@69: * used. U_USING_DEFAULT_WARNING indicates that the default locale data was jpayne@69: * used; neither the requested locale nor any of its fall back locales jpayne@69: * could be found. jpayne@69: * The caller owns the returned object and is responsible for deleting it. jpayne@69: * @deprecated ICU 64 Use createWordInstance instead. jpayne@69: */ jpayne@69: static BreakIterator* U_EXPORT2 jpayne@69: createTitleInstance(const Locale& where, UErrorCode& status); jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: /** jpayne@69: * Get the set of Locales for which TextBoundaries are installed. jpayne@69: *

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

jpayne@69: * @param count the output parameter of number of elements in the locale list jpayne@69: * @return available locales jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); jpayne@69: jpayne@69: /** jpayne@69: * Get name of the object for the desired Locale, in the desired language. jpayne@69: * @param objectLocale must be from getAvailableLocales. jpayne@69: * @param displayLocale specifies the desired locale for output. jpayne@69: * @param name the fill-in parameter of the return value jpayne@69: * Uses best match. jpayne@69: * @return user-displayable name jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale, jpayne@69: const Locale& displayLocale, jpayne@69: UnicodeString& name); jpayne@69: jpayne@69: /** jpayne@69: * Get name of the object for the desired Locale, in the language of the jpayne@69: * default locale. jpayne@69: * @param objectLocale must be from getMatchingLocales jpayne@69: * @param name the fill-in parameter of the return value jpayne@69: * @return user-displayable name jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale, jpayne@69: UnicodeString& name); jpayne@69: jpayne@69: #ifndef U_FORCE_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Deprecated functionality. Use clone() instead. jpayne@69: * jpayne@69: * Thread safe client-buffer-based cloning operation jpayne@69: * Do NOT call delete on a safeclone, since 'new' is not used to create it. jpayne@69: * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated. jpayne@69: * If buffer is not large enough, new memory will be allocated. jpayne@69: * @param BufferSize reference to size of allocated space. jpayne@69: * If BufferSize == 0, a sufficient size for use in cloning will jpayne@69: * be returned ('pre-flighting') jpayne@69: * If BufferSize is not enough for a stack-based safe clone, jpayne@69: * new memory will be allocated. jpayne@69: * @param status to indicate whether the operation went on smoothly or there were errors jpayne@69: * An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any allocations were jpayne@69: * necessary. jpayne@69: * @return pointer to the new clone jpayne@69: * jpayne@69: * @deprecated ICU 52. Use clone() instead. jpayne@69: */ jpayne@69: virtual BreakIterator * createBufferClone(void *stackBuffer, jpayne@69: int32_t &BufferSize, jpayne@69: UErrorCode &status) = 0; jpayne@69: #endif // U_FORCE_HIDE_DEPRECATED_API jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: jpayne@69: /** jpayne@69: * Determine whether the BreakIterator was created in user memory by jpayne@69: * createBufferClone(), and thus should not be deleted. Such objects jpayne@69: * must be closed by an explicit call to the destructor (not delete). jpayne@69: * @deprecated ICU 52. Always delete the BreakIterator. jpayne@69: */ jpayne@69: inline UBool isBufferClone(void); jpayne@69: jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: #if !UCONFIG_NO_SERVICE jpayne@69: /** jpayne@69: * Register a new break iterator of the indicated kind, to use in the given locale. jpayne@69: * The break iterator will be adopted. Clones of the iterator will be returned jpayne@69: * if a request for a break iterator of the given kind matches or falls back to jpayne@69: * this locale. jpayne@69: * Because ICU may choose to cache BreakIterators internally, this must jpayne@69: * be called at application startup, prior to any calls to jpayne@69: * BreakIterator::createXXXInstance to avoid undefined behavior. jpayne@69: * @param toAdopt the BreakIterator instance to be adopted jpayne@69: * @param locale the Locale for which this instance is to be registered jpayne@69: * @param kind the type of iterator for which this instance is to be registered jpayne@69: * @param status the in/out status code, no special meanings are assigned jpayne@69: * @return a registry key that can be used to unregister this instance jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: static URegistryKey U_EXPORT2 registerInstance(BreakIterator* toAdopt, jpayne@69: const Locale& locale, jpayne@69: UBreakIteratorType kind, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Unregister a previously-registered BreakIterator using the key returned from the jpayne@69: * register call. Key becomes invalid after a successful call and should not be used again. jpayne@69: * The BreakIterator corresponding to the key will be deleted. jpayne@69: * Because ICU may choose to cache BreakIterators internally, this should jpayne@69: * be called during application shutdown, after all calls to jpayne@69: * BreakIterator::createXXXInstance to avoid undefined behavior. jpayne@69: * @param key the registry key returned by a previous call to registerInstance jpayne@69: * @param status the in/out status code, no special meanings are assigned jpayne@69: * @return TRUE if the iterator for the key was successfully unregistered jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Return a StringEnumeration over the locales available at the time of the call, jpayne@69: * including registered locales. jpayne@69: * @return a StringEnumeration over the locales available at the time of the call jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: static StringEnumeration* U_EXPORT2 getAvailableLocales(void); jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Returns the locale for this break iterator. Two flavors are available: valid and jpayne@69: * actual locale. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** Get the locale for this break iterator object. You can choose between valid and actual locale. jpayne@69: * @param type type of the locale we're looking for (valid or actual) jpayne@69: * @param status error code for the operation jpayne@69: * @return the locale jpayne@69: * @internal jpayne@69: */ jpayne@69: const char *getLocaleID(ULocDataLocaleType type, UErrorCode& status) const; jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Set the subject text string upon which the break iterator is operating jpayne@69: * without changing any other aspect of the matching state. jpayne@69: * The new and previous text strings must have the same content. jpayne@69: * jpayne@69: * This function is intended for use in environments where ICU is operating on jpayne@69: * strings that may move around in memory. It provides a mechanism for notifying jpayne@69: * ICU that the string has been relocated, and providing a new UText to access the jpayne@69: * string in its new position. jpayne@69: * jpayne@69: * Note that the break iterator implementation never copies the underlying text jpayne@69: * of a string being processed, but always operates directly on the original text jpayne@69: * provided by the user. Refreshing simply drops the references to the old text jpayne@69: * and replaces them with references to the new. jpayne@69: * jpayne@69: * Caution: this function is normally used only by very specialized, jpayne@69: * system-level code. One example use case is with garbage collection that moves jpayne@69: * the text in memory. jpayne@69: * jpayne@69: * @param input The new (moved) text string. jpayne@69: * @param status Receives errors detected by this function. jpayne@69: * @return *this jpayne@69: * jpayne@69: * @stable ICU 49 jpayne@69: */ jpayne@69: virtual BreakIterator &refreshInputText(UText *input, UErrorCode &status) = 0; jpayne@69: jpayne@69: private: jpayne@69: static BreakIterator* buildInstance(const Locale& loc, const char *type, UErrorCode& status); jpayne@69: static BreakIterator* createInstance(const Locale& loc, int32_t kind, UErrorCode& status); jpayne@69: static BreakIterator* makeInstance(const Locale& loc, int32_t kind, UErrorCode& status); jpayne@69: jpayne@69: friend class ICUBreakIteratorFactory; jpayne@69: friend class ICUBreakIteratorService; jpayne@69: jpayne@69: protected: jpayne@69: // Do not enclose protected default/copy constructors with #ifndef U_HIDE_INTERNAL_API jpayne@69: // or else the compiler will create a public ones. jpayne@69: /** @internal */ jpayne@69: BreakIterator(); jpayne@69: /** @internal */ jpayne@69: BreakIterator (const BreakIterator &other); jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** @internal */ jpayne@69: BreakIterator (const Locale& valid, const Locale &actual); jpayne@69: /** @internal. Assignment Operator, used by RuleBasedBreakIterator. */ jpayne@69: BreakIterator &operator = (const BreakIterator &other); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: private: jpayne@69: jpayne@69: /** @internal (private) */ jpayne@69: char actualLocale[ULOC_FULLNAME_CAPACITY]; jpayne@69: char validLocale[ULOC_FULLNAME_CAPACITY]; jpayne@69: }; jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: jpayne@69: inline UBool BreakIterator::isBufferClone() jpayne@69: { jpayne@69: return FALSE; jpayne@69: } jpayne@69: jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_BREAK_ITERATION */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // BRKITER_H jpayne@69: //eof