Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/unicode/brkiter.h
38827 views
/*1********************************************************************************2* Copyright (C) 1997-2016, International Business Machines3* Corporation and others. All Rights Reserved.4********************************************************************************5*6* File brkiter.h7*8* Modification History:9*10* Date Name Description11* 02/18/97 aliu Added typedef for TextCount. Made DONE const.12* 05/07/97 aliu Fixed DLL declaration.13* 07/09/97 jfitz Renamed BreakIterator and interface synced with JDK14* 08/11/98 helena Sync-up JDK1.2.15* 01/13/2000 helena Added UErrorCode parameter to createXXXInstance methods.16********************************************************************************17*/1819#ifndef BRKITER_H20#define BRKITER_H2122#include "unicode/utypes.h"2324/**25* \file26* \brief C++ API: Break Iterator.27*/2829#if UCONFIG_NO_BREAK_ITERATION3031U_NAMESPACE_BEGIN3233/*34* Allow the declaration of APIs with pointers to BreakIterator35* even when break iteration is removed from the build.36*/37class BreakIterator;3839U_NAMESPACE_END4041#else4243#include "unicode/uobject.h"44#include "unicode/unistr.h"45#include "unicode/chariter.h"46#include "unicode/locid.h"47#include "unicode/ubrk.h"48#include "unicode/strenum.h"49#include "unicode/utext.h"50#include "unicode/umisc.h"5152U_NAMESPACE_BEGIN5354/**55* The BreakIterator class implements methods for finding the location56* of boundaries in text. BreakIterator is an abstract base class.57* Instances of BreakIterator maintain a current position and scan over58* text returning the index of characters where boundaries occur.59* <p>60* Line boundary analysis determines where a text string can be broken61* when line-wrapping. The mechanism correctly handles punctuation and62* hyphenated words.63* <p>64* Sentence boundary analysis allows selection with correct65* interpretation of periods within numbers and abbreviations, and66* trailing punctuation marks such as quotation marks and parentheses.67* <p>68* Word boundary analysis is used by search and replace functions, as69* well as within text editing applications that allow the user to70* select words with a double click. Word selection provides correct71* interpretation of punctuation marks within and following72* words. Characters that are not part of a word, such as symbols or73* punctuation marks, have word-breaks on both sides.74* <p>75* Character boundary analysis allows users to interact with76* characters as they expect to, for example, when moving the cursor77* through a text string. Character boundary analysis provides correct78* navigation of through character strings, regardless of how the79* character is stored. For example, an accented character might be80* stored as a base character and a diacritical mark. What users81* consider to be a character can differ between languages.82* <p>83* The text boundary positions are found according to the rules84* described in Unicode Standard Annex #29, Text Boundaries, and85* Unicode Standard Annex #14, Line Breaking Properties. These86* are available at http://www.unicode.org/reports/tr14/ and87* http://www.unicode.org/reports/tr29/.88* <p>89* In addition to the C++ API defined in this header file, a90* plain C API with equivalent functionality is defined in the91* file ubrk.h92* <p>93* Code snippets illustrating the use of the Break Iterator APIs94* are available in the ICU User Guide,95* http://icu-project.org/userguide/boundaryAnalysis.html96* and in the sample program icu/source/samples/break/break.cpp97*98*/99class U_COMMON_API BreakIterator : public UObject {100public:101/**102* destructor103* @stable ICU 2.0104*/105virtual ~BreakIterator();106107/**108* Return true if another object is semantically equal to this109* one. The other object should be an instance of the same subclass of110* BreakIterator. Objects of different subclasses are considered111* unequal.112* <P>113* Return true if this BreakIterator is at the same position in the114* same text, and is the same class and type (word, line, etc.) of115* BreakIterator, as the argument. Text is considered the same if116* it contains the same characters, it need not be the same117* object, and styles are not considered.118* @stable ICU 2.0119*/120virtual UBool operator==(const BreakIterator&) const = 0;121122/**123* Returns the complement of the result of operator==124* @param rhs The BreakIterator to be compared for inequality125* @return the complement of the result of operator==126* @stable ICU 2.0127*/128UBool operator!=(const BreakIterator& rhs) const { return !operator==(rhs); }129130/**131* Return a polymorphic copy of this object. This is an abstract132* method which subclasses implement.133* @stable ICU 2.0134*/135virtual BreakIterator* clone(void) const = 0;136137/**138* Return a polymorphic class ID for this object. Different subclasses139* will return distinct unequal values.140* @stable ICU 2.0141*/142virtual UClassID getDynamicClassID(void) const = 0;143144/**145* Return a CharacterIterator over the text being analyzed.146* @stable ICU 2.0147*/148virtual CharacterIterator& getText(void) const = 0;149150151/**152* Get a UText for the text being analyzed.153* The returned UText is a shallow clone of the UText used internally154* by the break iterator implementation. It can safely be used to155* access the text without impacting any break iterator operations,156* but the underlying text itself must not be altered.157*158* @param fillIn A UText to be filled in. If NULL, a new UText will be159* allocated to hold the result.160* @param status receives any error codes.161* @return The current UText for this break iterator. If an input162* UText was provided, it will always be returned.163* @stable ICU 3.4164*/165virtual UText *getUText(UText *fillIn, UErrorCode &status) const = 0;166167/**168* Change the text over which this operates. The text boundary is169* reset to the start.170* @param text The UnicodeString used to change the text.171* @stable ICU 2.0172*/173virtual void setText(const UnicodeString &text) = 0;174175/**176* Reset the break iterator to operate over the text represented by177* the UText. The iterator position is reset to the start.178*179* This function makes a shallow clone of the supplied UText. This means180* that the caller is free to immediately close or otherwise reuse the181* Utext that was passed as a parameter, but that the underlying text itself182* must not be altered while being referenced by the break iterator.183*184* All index positions returned by break iterator functions are185* native indices from the UText. For example, when breaking UTF-8186* encoded text, the break positions returned by next(), previous(), etc.187* will be UTF-8 string indices, not UTF-16 positions.188*189* @param text The UText used to change the text.190* @param status receives any error codes.191* @stable ICU 3.4192*/193virtual void setText(UText *text, UErrorCode &status) = 0;194195/**196* Change the text over which this operates. The text boundary is197* reset to the start.198* Note that setText(UText *) provides similar functionality to this function,199* and is more efficient.200* @param it The CharacterIterator used to change the text.201* @stable ICU 2.0202*/203virtual void adoptText(CharacterIterator* it) = 0;204205enum {206/**207* DONE is returned by previous() and next() after all valid208* boundaries have been returned.209* @stable ICU 2.0210*/211DONE = (int32_t)-1212};213214/**215* Sets the current iteration position to the beginning of the text, position zero.216* @return The offset of the beginning of the text, zero.217* @stable ICU 2.0218*/219virtual int32_t first(void) = 0;220221/**222* Set the iterator position to the index immediately BEYOND the last character in the text being scanned.223* @return The index immediately BEYOND the last character in the text being scanned.224* @stable ICU 2.0225*/226virtual int32_t last(void) = 0;227228/**229* Set the iterator position to the boundary preceding the current boundary.230* @return The character index of the previous text boundary or DONE if all231* boundaries have been returned.232* @stable ICU 2.0233*/234virtual int32_t previous(void) = 0;235236/**237* Advance the iterator to the boundary following the current boundary.238* @return The character index of the next text boundary or DONE if all239* boundaries have been returned.240* @stable ICU 2.0241*/242virtual int32_t next(void) = 0;243244/**245* Return character index of the current interator position within the text.246* @return The boundary most recently returned.247* @stable ICU 2.0248*/249virtual int32_t current(void) const = 0;250251/**252* Advance the iterator to the first boundary following the specified offset.253* The value returned is always greater than the offset or254* the value BreakIterator.DONE255* @param offset the offset to begin scanning.256* @return The first boundary after the specified offset.257* @stable ICU 2.0258*/259virtual int32_t following(int32_t offset) = 0;260261/**262* Set the iterator position to the first boundary preceding the specified offset.263* The value returned is always smaller than the offset or264* the value BreakIterator.DONE265* @param offset the offset to begin scanning.266* @return The first boundary before the specified offset.267* @stable ICU 2.0268*/269virtual int32_t preceding(int32_t offset) = 0;270271/**272* Return true if the specfied position is a boundary position.273* As a side effect, the current position of the iterator is set274* to the first boundary position at or following the specified offset.275* @param offset the offset to check.276* @return True if "offset" is a boundary position.277* @stable ICU 2.0278*/279virtual UBool isBoundary(int32_t offset) = 0;280281/**282* Set the iterator position to the nth boundary from the current boundary283* @param n the number of boundaries to move by. A value of 0284* does nothing. Negative values move to previous boundaries285* and positive values move to later boundaries.286* @return The new iterator position, or287* DONE if there are fewer than |n| boundaries in the specfied direction.288* @stable ICU 2.0289*/290virtual int32_t next(int32_t n) = 0;291292/**293* For RuleBasedBreakIterators, return the status tag from the294* break rule that determined the most recently295* returned break position.296* <p>297* For break iterator types that do not support a rule status,298* a default value of 0 is returned.299* <p>300* @return the status from the break rule that determined the most recently301* returned break position.302* @see RuleBaseBreakIterator::getRuleStatus()303* @see UWordBreak304* @stable ICU 52305*/306virtual int32_t getRuleStatus() const;307308/**309* For RuleBasedBreakIterators, get the status (tag) values from the break rule(s)310* that determined the most recently returned break position.311* <p>312* For break iterator types that do not support rule status,313* no values are returned.314* <p>315* The returned status value(s) are stored into an array provided by the caller.316* The values are stored in sorted (ascending) order.317* If the capacity of the output array is insufficient to hold the data,318* the output will be truncated to the available length, and a319* U_BUFFER_OVERFLOW_ERROR will be signaled.320* <p>321* @see RuleBaseBreakIterator::getRuleStatusVec322*323* @param fillInVec an array to be filled in with the status values.324* @param capacity the length of the supplied vector. A length of zero causes325* the function to return the number of status values, in the326* normal way, without attemtping to store any values.327* @param status receives error codes.328* @return The number of rule status values from rules that determined329* the most recent boundary returned by the break iterator.330* In the event of a U_BUFFER_OVERFLOW_ERROR, the return value331* is the total number of status values that were available,332* not the reduced number that were actually returned.333* @see getRuleStatus334* @stable ICU 52335*/336virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status);337338/**339* Create BreakIterator for word-breaks using the given locale.340* Returns an instance of a BreakIterator implementing word breaks.341* WordBreak is useful for word selection (ex. double click)342* @param where the locale.343* @param status the error code344* @return A BreakIterator for word-breaks. The UErrorCode& status345* parameter is used to return status information to the user.346* To check whether the construction succeeded or not, you should check347* the value of U_SUCCESS(err). If you wish more detailed information, you348* can check for informational error results which still indicate success.349* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For350* example, 'de_CH' was requested, but nothing was found there, so 'de' was351* used. U_USING_DEFAULT_WARNING indicates that the default locale data was352* used; neither the requested locale nor any of its fall back locales353* could be found.354* The caller owns the returned object and is responsible for deleting it.355* @stable ICU 2.0356*/357static BreakIterator* U_EXPORT2358createWordInstance(const Locale& where, UErrorCode& status);359360/**361* Create BreakIterator for line-breaks using specified locale.362* Returns an instance of a BreakIterator implementing line breaks. Line363* breaks are logically possible line breaks, actual line breaks are364* usually determined based on display width.365* LineBreak is useful for word wrapping text.366* @param where the locale.367* @param status The error code.368* @return A BreakIterator for line-breaks. The UErrorCode& status369* parameter is used to return status information to the user.370* To check whether the construction succeeded or not, you should check371* the value of U_SUCCESS(err). If you wish more detailed information, you372* can check for informational error results which still indicate success.373* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For374* example, 'de_CH' was requested, but nothing was found there, so 'de' was375* used. U_USING_DEFAULT_WARNING indicates that the default locale data was376* used; neither the requested locale nor any of its fall back locales377* could be found.378* The caller owns the returned object and is responsible for deleting it.379* @stable ICU 2.0380*/381static BreakIterator* U_EXPORT2382createLineInstance(const Locale& where, UErrorCode& status);383384/**385* Create BreakIterator for character-breaks using specified locale386* Returns an instance of a BreakIterator implementing character breaks.387* Character breaks are boundaries of combining character sequences.388* @param where the locale.389* @param status The error code.390* @return A BreakIterator for character-breaks. The UErrorCode& status391* parameter is used to return status information to the user.392* To check whether the construction succeeded or not, you should check393* the value of U_SUCCESS(err). If you wish more detailed information, you394* can check for informational error results which still indicate success.395* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For396* example, 'de_CH' was requested, but nothing was found there, so 'de' was397* used. U_USING_DEFAULT_WARNING indicates that the default locale data was398* used; neither the requested locale nor any of its fall back locales399* could be found.400* The caller owns the returned object and is responsible for deleting it.401* @stable ICU 2.0402*/403static BreakIterator* U_EXPORT2404createCharacterInstance(const Locale& where, UErrorCode& status);405406/**407* Create BreakIterator for sentence-breaks using specified locale408* Returns an instance of a BreakIterator implementing sentence breaks.409* @param where the locale.410* @param status The error code.411* @return A BreakIterator for sentence-breaks. The UErrorCode& status412* parameter is used to return status information to the user.413* To check whether the construction succeeded or not, you should check414* the value of U_SUCCESS(err). If you wish more detailed information, you415* can check for informational error results which still indicate success.416* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For417* example, 'de_CH' was requested, but nothing was found there, so 'de' was418* used. U_USING_DEFAULT_WARNING indicates that the default locale data was419* used; neither the requested locale nor any of its fall back locales420* could be found.421* The caller owns the returned object and is responsible for deleting it.422* @stable ICU 2.0423*/424static BreakIterator* U_EXPORT2425createSentenceInstance(const Locale& where, UErrorCode& status);426427/**428* Create BreakIterator for title-casing breaks using the specified locale429* Returns an instance of a BreakIterator implementing title breaks.430* The iterator returned locates title boundaries as described for431* Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration,432* please use Word Boundary iterator.{@link #createWordInstance }433*434* @param where the locale.435* @param status The error code.436* @return A BreakIterator for title-breaks. The UErrorCode& status437* parameter is used to return status information to the user.438* To check whether the construction succeeded or not, you should check439* the value of U_SUCCESS(err). If you wish more detailed information, you440* can check for informational error results which still indicate success.441* U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For442* example, 'de_CH' was requested, but nothing was found there, so 'de' was443* used. U_USING_DEFAULT_WARNING indicates that the default locale data was444* used; neither the requested locale nor any of its fall back locales445* could be found.446* The caller owns the returned object and is responsible for deleting it.447* @stable ICU 2.1448*/449static BreakIterator* U_EXPORT2450createTitleInstance(const Locale& where, UErrorCode& status);451452/**453* Get the set of Locales for which TextBoundaries are installed.454* <p><b>Note:</b> this will not return locales added through the register455* call. To see the registered locales too, use the getAvailableLocales456* function that returns a StringEnumeration object </p>457* @param count the output parameter of number of elements in the locale list458* @return available locales459* @stable ICU 2.0460*/461static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);462463/**464* Get name of the object for the desired Locale, in the desired langauge.465* @param objectLocale must be from getAvailableLocales.466* @param displayLocale specifies the desired locale for output.467* @param name the fill-in parameter of the return value468* Uses best match.469* @return user-displayable name470* @stable ICU 2.0471*/472static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,473const Locale& displayLocale,474UnicodeString& name);475476/**477* Get name of the object for the desired Locale, in the langauge of the478* default locale.479* @param objectLocale must be from getMatchingLocales480* @param name the fill-in parameter of the return value481* @return user-displayable name482* @stable ICU 2.0483*/484static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale,485UnicodeString& name);486487/**488* Deprecated functionality. Use clone() instead.489*490* Thread safe client-buffer-based cloning operation491* Do NOT call delete on a safeclone, since 'new' is not used to create it.492* @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated.493* If buffer is not large enough, new memory will be allocated.494* @param BufferSize reference to size of allocated space.495* If BufferSize == 0, a sufficient size for use in cloning will496* be returned ('pre-flighting')497* If BufferSize is not enough for a stack-based safe clone,498* new memory will be allocated.499* @param status to indicate whether the operation went on smoothly or there were errors500* An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any allocations were501* necessary.502* @return pointer to the new clone503*504* @deprecated ICU 52. Use clone() instead.505*/506virtual BreakIterator * createBufferClone(void *stackBuffer,507int32_t &BufferSize,508UErrorCode &status) = 0;509510#ifndef U_HIDE_DEPRECATED_API511512/**513* Determine whether the BreakIterator was created in user memory by514* createBufferClone(), and thus should not be deleted. Such objects515* must be closed by an explicit call to the destructor (not delete).516* @deprecated ICU 52. Always delete the BreakIterator.517*/518inline UBool isBufferClone(void);519520#endif /* U_HIDE_DEPRECATED_API */521522#if !UCONFIG_NO_SERVICE523/**524* Register a new break iterator of the indicated kind, to use in the given locale.525* The break iterator will be adopted. Clones of the iterator will be returned526* if a request for a break iterator of the given kind matches or falls back to527* this locale.528* Because ICU may choose to cache BreakIterators internally, this must529* be called at application startup, prior to any calls to530* BreakIterator::createXXXInstance to avoid undefined behavior.531* @param toAdopt the BreakIterator instance to be adopted532* @param locale the Locale for which this instance is to be registered533* @param kind the type of iterator for which this instance is to be registered534* @param status the in/out status code, no special meanings are assigned535* @return a registry key that can be used to unregister this instance536* @stable ICU 2.4537*/538static URegistryKey U_EXPORT2 registerInstance(BreakIterator* toAdopt,539const Locale& locale,540UBreakIteratorType kind,541UErrorCode& status);542543/**544* Unregister a previously-registered BreakIterator using the key returned from the545* register call. Key becomes invalid after a successful call and should not be used again.546* The BreakIterator corresponding to the key will be deleted.547* Because ICU may choose to cache BreakIterators internally, this should548* be called during application shutdown, after all calls to549* BreakIterator::createXXXInstance to avoid undefined behavior.550* @param key the registry key returned by a previous call to registerInstance551* @param status the in/out status code, no special meanings are assigned552* @return TRUE if the iterator for the key was successfully unregistered553* @stable ICU 2.4554*/555static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status);556557/**558* Return a StringEnumeration over the locales available at the time of the call,559* including registered locales.560* @return a StringEnumeration over the locales available at the time of the call561* @stable ICU 2.4562*/563static StringEnumeration* U_EXPORT2 getAvailableLocales(void);564#endif565566/**567* Returns the locale for this break iterator. Two flavors are available: valid and568* actual locale.569* @stable ICU 2.8570*/571Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;572573#ifndef U_HIDE_INTERNAL_API574/** Get the locale for this break iterator object. You can choose between valid and actual locale.575* @param type type of the locale we're looking for (valid or actual)576* @param status error code for the operation577* @return the locale578* @internal579*/580const char *getLocaleID(ULocDataLocaleType type, UErrorCode& status) const;581#endif /* U_HIDE_INTERNAL_API */582583/**584* Set the subject text string upon which the break iterator is operating585* without changing any other aspect of the matching state.586* The new and previous text strings must have the same content.587*588* This function is intended for use in environments where ICU is operating on589* strings that may move around in memory. It provides a mechanism for notifying590* ICU that the string has been relocated, and providing a new UText to access the591* string in its new position.592*593* Note that the break iterator implementation never copies the underlying text594* of a string being processed, but always operates directly on the original text595* provided by the user. Refreshing simply drops the references to the old text596* and replaces them with references to the new.597*598* Caution: this function is normally used only by very specialized,599* system-level code. One example use case is with garbage collection that moves600* the text in memory.601*602* @param input The new (moved) text string.603* @param status Receives errors detected by this function.604* @return *this605*606* @stable ICU 49607*/608virtual BreakIterator &refreshInputText(UText *input, UErrorCode &status) = 0;609610private:611static BreakIterator* buildInstance(const Locale& loc, const char *type, int32_t kind, UErrorCode& status);612static BreakIterator* createInstance(const Locale& loc, int32_t kind, UErrorCode& status);613static BreakIterator* makeInstance(const Locale& loc, int32_t kind, UErrorCode& status);614615friend class ICUBreakIteratorFactory;616friend class ICUBreakIteratorService;617618protected:619// Do not enclose protected default/copy constructors with #ifndef U_HIDE_INTERNAL_API620// or else the compiler will create a public ones.621/** @internal */622BreakIterator();623/** @internal */624BreakIterator (const BreakIterator &other) : UObject(other) {}625#ifndef U_HIDE_INTERNAL_API626/** @internal */627BreakIterator (const Locale& valid, const Locale& actual);628#endif /* U_HIDE_INTERNAL_API */629630private:631632/** @internal */633char actualLocale[ULOC_FULLNAME_CAPACITY];634char validLocale[ULOC_FULLNAME_CAPACITY];635636/**637* The assignment operator has no real implementation.638* It's provided to make the compiler happy. Do not call.639*/640BreakIterator& operator=(const BreakIterator&);641};642643#ifndef U_HIDE_DEPRECATED_API644645inline UBool BreakIterator::isBufferClone()646{647return FALSE;648}649650#endif /* U_HIDE_DEPRECATED_API */651652U_NAMESPACE_END653654#endif /* #if !UCONFIG_NO_BREAK_ITERATION */655656#endif // _BRKITER657//eof658659660