Instances of this class are most commonly created by the factory methods of * BreakIterator::createWordInstance(), BreakIterator::createLineInstance(), etc., * and then used via the abstract API in class BreakIterator
See the ICU User Guide for information on Break Iterator Rules.
This class is not intended to be subclassed.
* Return a CharacterIterator over the text being analyzed. * The returned character iterator is owned by the break iterator, and must * not be deleted by the caller. Repeated calls to this function may * return the same CharacterIterator. *
* The returned character iterator must not be used concurrently with * the break iterator. If concurrent operation is needed, clone the * returned character iterator first and operate on the clone. *
* When the break iterator is operating on text supplied via a UText, * this function will fail. Lacking any way to signal failures, it * returns an CharacterIterator containing no text. * The function getUText() provides similar functionality, * is reliable, and is more efficient. *
* Of the standard types of ICU break iterators, only word break and * line break provide status values. The values are defined in * the header file ubrk.h. For Word breaks, the status allows distinguishing between words * that contain alphabetic letters, "words" that appear to be numbers, * punctuation and spaces, words containing ideographic characters, and * more. For Line Break, the status distinguishes between hard (mandatory) breaks * and soft (potential) break positions. *
* getRuleStatus() can be called after obtaining a boundary * position from next(), previous(), or * any other break iterator functions that returns a boundary position. *
getRuleStatus()
next()
previous()
* Note that getRuleStatus() returns the value corresponding to * current() index even after next() has returned DONE. *
current()
* When creating custom break rules, one is free to define whatever * status values may be convenient for the application. *
* @return the status from the break rule that determined the boundary * at the current iteration position. * * @see UWordBreak * @stable ICU 2.2 */ virtual int32_t getRuleStatus() const; /** * Get the status (tag) values from the break rule(s) that determined the boundary * at the current iteration position. *
* 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. * * @param fillInVec an array to be filled in with the status values. * @param 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. * @param status receives error codes. * @return The number of rule status values from the rules that determined * the boundary at the current iteration position. * In the event of a U_BUFFER_OVERFLOW_ERROR, the return value * is the total number of status values that were available, * not the reduced number that were actually returned. * @see getRuleStatus * @stable ICU 3.0 */ virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status); /** * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. * This method is to implement a simple version of RTTI, since not all * C++ compilers support genuine RTTI. Polymorphic operator==() and * clone() methods call this method. * * @return The class ID for this object. All objects of a * given class have the same class ID. Objects of * other classes have different class IDs. * @stable ICU 2.0 */ virtual UClassID getDynamicClassID(void) const; /** * Returns the class ID for this class. This is useful only for * comparing to a return value from getDynamicClassID(). For example: * * Base* polymorphic_pointer = createPolymorphicObject(); * if (polymorphic_pointer->getDynamicClassID() == * Derived::getStaticClassID()) ... * * @return The class ID for all objects of this class. * @stable ICU 2.0 */ static UClassID U_EXPORT2 getStaticClassID(void); #ifndef U_FORCE_HIDE_DEPRECATED_API /** * Deprecated functionality. Use clone() instead. * * Create a clone (copy) of this break iterator in memory provided * by the caller. The idea is to increase performance by avoiding * a storage allocation. Use of this function is NOT RECOMMENDED. * Performance gains are minimal, and correct buffer management is * tricky. Use clone() instead. * * @param stackBuffer The pointer to the memory into which the cloned object * should be placed. If NULL, allocate heap memory * for the cloned object. * @param BufferSize The size of the buffer. If zero, return the required * buffer size, but do not clone the object. If the * size was too small (but not zero), allocate heap * storage for the cloned object. * * @param status Error status. U_SAFECLONE_ALLOCATED_WARNING will be * returned if the provided buffer was too small, and * the clone was therefore put on the heap. * * @return Pointer to the clone object. This may differ from the stackBuffer * address if the byte alignment of the stack buffer was not suitable * or if the stackBuffer was too small to hold the clone. * @deprecated ICU 52. Use clone() instead. */ virtual RuleBasedBreakIterator *createBufferClone(void *stackBuffer, int32_t &BufferSize, UErrorCode &status); #endif // U_FORCE_HIDE_DEPRECATED_API /** * Return the binary form of compiled break rules, * which can then be used to create a new break iterator at some * time in the future. Creating a break iterator from pre-compiled rules * is much faster than building one from the source form of the * break rules. * * The binary data can only be used with the same version of ICU * and on the same platform type (processor endian-ness) * * @param length Returns the length of the binary data. (Out parameter.) * * @return A pointer to the binary (compiled) rule data. The storage * belongs to the RulesBasedBreakIterator object, not the * caller, and must not be modified or deleted. * @stable ICU 4.8 */ virtual const uint8_t *getBinaryRules(uint32_t &length); /** * Set the subject text string upon which the break iterator is operating * without changing any other aspect of the matching state. * The new and previous text strings must have the same content. * * This function is intended for use in environments where ICU is operating on * strings that may move around in memory. It provides a mechanism for notifying * ICU that the string has been relocated, and providing a new UText to access the * string in its new position. * * Note that the break iterator implementation never copies the underlying text * of a string being processed, but always operates directly on the original text * provided by the user. Refreshing simply drops the references to the old text * and replaces them with references to the new. * * Caution: this function is normally used only by very specialized, * system-level code. One example use case is with garbage collection that moves * the text in memory. * * @param input The new (moved) text string. * @param status Receives errors detected by this function. * @return *this * * @stable ICU 49 */ virtual RuleBasedBreakIterator &refreshInputText(UText *input, UErrorCode &status); private: //======================================================================= // implementation //======================================================================= /** * Dumps caches and performs other actions associated with a complete change * in text or iteration position. * @internal (private) */ void reset(void); /** * Common initialization function, used by constructors and bufferClone. * @internal (private) */ void init(UErrorCode &status); /** * Iterate backwards from an arbitrary position in the input text using the * synthesized Safe Reverse rules. * This locates a "Safe Position" from which the forward break rules * will operate correctly. A Safe Position is not necessarily a boundary itself. * * @param fromPosition the position in the input text to begin the iteration. * @internal (private) */ int32_t handleSafePrevious(int32_t fromPosition); /** * Find a rule-based boundary by running the state machine. * Input * fPosition, the position in the text to begin from. * Output * fPosition: the boundary following the starting position. * fDictionaryCharCount the number of dictionary characters encountered. * If > 0, the segment will be further subdivided * fRuleStatusIndex Info from the state table indicating which rules caused the boundary. * * @internal (private) */ int32_t handleNext(); /** * This function returns the appropriate LanguageBreakEngine for a * given character c. * @param c A character in the dictionary set * @internal (private) */ const LanguageBreakEngine *getLanguageBreakEngine(UChar32 c); public: #ifndef U_HIDE_INTERNAL_API /** * Debugging function only. * @internal */ void dumpCache(); /** * Debugging function only. * @internal */ void dumpTables(); #endif /* U_HIDE_INTERNAL_API */ }; //------------------------------------------------------------------------------ // // Inline Functions Definitions ... // //------------------------------------------------------------------------------ inline UBool RuleBasedBreakIterator::operator!=(const BreakIterator& that) const { return !operator==(that); } U_NAMESPACE_END #endif /* #if !UCONFIG_NO_BREAK_ITERATION */ #endif /* U_SHOW_CPLUSPLUS_API */ #endif