Indicate whether this engine handles a particular character when 70 * the RuleBasedBreakIterator is used for a particular locale. This method is used 71 * by the RuleBasedBreakIterator to find a break engine.
Indicate whether this engine handles a particular character.This method is 81 * used by the RuleBasedBreakIterator after it already find a break engine to see which 82 * characters after the first one can be handled by this break engine.
Divide up a range of text handled by this break engine.
Instances of this class are most commonly created by the factory methods of 113 * BreakIterator::createWordInstance(), BreakIterator::createLineInstance(), etc., 114 * 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.
406 * Return a CharacterIterator over the text being analyzed. 407 * The returned character iterator is owned by the break iterator, and must 408 * not be deleted by the caller. Repeated calls to this function may 409 * return the same CharacterIterator. 410 *
412 * The returned character iterator must not be used concurrently with 413 * the break iterator. If concurrent operation is needed, clone the 414 * returned character iterator first and operate on the clone. 415 *
417 * When the break iterator is operating on text supplied via a UText, 418 * this function will fail, returning a CharacterIterator containing no text. 419 * The function getUText() provides similar functionality, 420 * is reliable, and is more efficient. 421 *
570 * Of the standard types of ICU break iterators, only word break and 571 * line break provide status values. The values are defined in 572 * the header file ubrk.h. For Word breaks, the status allows distinguishing between words 573 * that contain alphabetic letters, "words" that appear to be numbers, 574 * punctuation and spaces, words containing ideographic characters, and 575 * more. For Line Break, the status distinguishes between hard (mandatory) breaks 576 * and soft (potential) break positions. 577 *
578 * getRuleStatus() can be called after obtaining a boundary 579 * position from next(), previous(), or 580 * any other break iterator functions that returns a boundary position. 581 *
getRuleStatus()
next()
previous()
582 * Note that getRuleStatus() returns the value corresponding to 583 * current() index even after next() has returned DONE. 584 *
current()
585 * When creating custom break rules, one is free to define whatever 586 * status values may be convenient for the application. 587 *
588 * @return the status from the break rule that determined the boundary 589 * at the current iteration position. 590 * 591 * @see UWordBreak 592 * @stable ICU 2.2 593 */ 594 virtual int32_t getRuleStatus() const override; 595 596 /** 597 * Get the status (tag) values from the break rule(s) that determined the boundary 598 * at the current iteration position. 599 *
600 * The returned status value(s) are stored into an array provided by the caller. 601 * The values are stored in sorted (ascending) order. 602 * If the capacity of the output array is insufficient to hold the data, 603 * the output will be truncated to the available length, and a 604 * U_BUFFER_OVERFLOW_ERROR will be signaled. 605 * 606 * @param fillInVec an array to be filled in with the status values. 607 * @param capacity the length of the supplied vector. A length of zero causes 608 * the function to return the number of status values, in the 609 * normal way, without attempting to store any values. 610 * @param status receives error codes. 611 * @return The number of rule status values from the rules that determined 612 * the boundary at the current iteration position. 613 * In the event of a U_BUFFER_OVERFLOW_ERROR, the return value 614 * is the total number of status values that were available, 615 * not the reduced number that were actually returned. 616 * @see getRuleStatus 617 * @stable ICU 3.0 618 */ 619 virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status) override; 620 621 /** 622 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. 623 * This method is to implement a simple version of RTTI, since not all 624 * C++ compilers support genuine RTTI. Polymorphic operator==() and 625 * clone() methods call this method. 626 * 627 * @return The class ID for this object. All objects of a 628 * given class have the same class ID. Objects of 629 * other classes have different class IDs. 630 * @stable ICU 2.0 631 */ 632 virtual UClassID getDynamicClassID(void) const override; 633 634 /** 635 * Returns the class ID for this class. This is useful only for 636 * comparing to a return value from getDynamicClassID(). For example: 637 * 638 * Base* polymorphic_pointer = createPolymorphicObject(); 639 * if (polymorphic_pointer->getDynamicClassID() == 640 * Derived::getStaticClassID()) ... 641 * 642 * @return The class ID for all objects of this class. 643 * @stable ICU 2.0 644 */ 645 static UClassID U_EXPORT2 getStaticClassID(void); 646 647 #ifndef U_FORCE_HIDE_DEPRECATED_API 648 /** 649 * Deprecated functionality. Use clone() instead. 650 * 651 * Create a clone (copy) of this break iterator in memory provided 652 * by the caller. The idea is to increase performance by avoiding 653 * a storage allocation. Use of this function is NOT RECOMMENDED. 654 * Performance gains are minimal, and correct buffer management is 655 * tricky. Use clone() instead. 656 * 657 * @param stackBuffer The pointer to the memory into which the cloned object 658 * should be placed. If nullptr, allocate heap memory 659 * for the cloned object. 660 * @param BufferSize The size of the buffer. If zero, return the required 661 * buffer size, but do not clone the object. If the 662 * size was too small (but not zero), allocate heap 663 * storage for the cloned object. 664 * 665 * @param status Error status. U_SAFECLONE_ALLOCATED_WARNING will be 666 * returned if the provided buffer was too small, and 667 * the clone was therefore put on the heap. 668 * 669 * @return Pointer to the clone object. This may differ from the stackBuffer 670 * address if the byte alignment of the stack buffer was not suitable 671 * or if the stackBuffer was too small to hold the clone. 672 * @deprecated ICU 52. Use clone() instead. 673 */ 674 virtual RuleBasedBreakIterator *createBufferClone(void *stackBuffer, 675 int32_t &BufferSize, 676 UErrorCode &status) override; 677 #endif // U_FORCE_HIDE_DEPRECATED_API 678 679 /** 680 * Return the binary form of compiled break rules, 681 * which can then be used to create a new break iterator at some 682 * time in the future. Creating a break iterator from pre-compiled rules 683 * is much faster than building one from the source form of the 684 * break rules. 685 * 686 * The binary data can only be used with the same version of ICU 687 * and on the same platform type (processor endian-ness) 688 * 689 * @param length Returns the length of the binary data. (Out parameter.) 690 * 691 * @return A pointer to the binary (compiled) rule data. The storage 692 * belongs to the RulesBasedBreakIterator object, not the 693 * caller, and must not be modified or deleted. 694 * @stable ICU 4.8 695 */ 696 virtual const uint8_t *getBinaryRules(uint32_t &length); 697 698 /** 699 * Set the subject text string upon which the break iterator is operating 700 * without changing any other aspect of the matching state. 701 * The new and previous text strings must have the same content. 702 * 703 * This function is intended for use in environments where ICU is operating on 704 * strings that may move around in memory. It provides a mechanism for notifying 705 * ICU that the string has been relocated, and providing a new UText to access the 706 * string in its new position. 707 * 708 * Note that the break iterator implementation never copies the underlying text 709 * of a string being processed, but always operates directly on the original text 710 * provided by the user. Refreshing simply drops the references to the old text 711 * and replaces them with references to the new. 712 * 713 * Caution: this function is normally used only by very specialized, 714 * system-level code. One example use case is with garbage collection that moves 715 * the text in memory. 716 * 717 * @param input The new (moved) text string. 718 * @param status Receives errors detected by this function. 719 * @return *this 720 * 721 * @stable ICU 49 722 */ 723 virtual RuleBasedBreakIterator &refreshInputText(UText *input, UErrorCode &status) override; 724 725 726 private: 727 //======================================================================= 728 // implementation 729 //======================================================================= 730 /** 731 * Iterate backwards from an arbitrary position in the input text using the 732 * synthesized Safe Reverse rules. 733 * This locates a "Safe Position" from which the forward break rules 734 * will operate correctly. A Safe Position is not necessarily a boundary itself. 735 * 736 * @param fromPosition the position in the input text to begin the iteration. 737 * @internal (private) 738 */ 739 int32_t handleSafePrevious(int32_t fromPosition); 740 741 /** 742 * Find a rule-based boundary by running the state machine. 743 * Input 744 * fPosition, the position in the text to begin from. 745 * Output 746 * fPosition: the boundary following the starting position. 747 * fDictionaryCharCount the number of dictionary characters encountered. 748 * If > 0, the segment will be further subdivided 749 * fRuleStatusIndex Info from the state table indicating which rules caused the boundary. 750 * 751 * @internal (private) 752 */ 753 int32_t handleNext(); 754 755 /* 756 * Templatized version of handleNext() and handleSafePrevious(). 757 * 758 * There will be exactly four instantiations, two each for 8 and 16 bit tables, 759 * two each for 8 and 16 bit trie. 760 * Having separate instantiations for the table types keeps conditional tests of 761 * the table type out of the inner loops, at the expense of replicated code. 762 * 763 * The template parameter for the Trie access function is a value, not a type. 764 * Doing it this way, the compiler will inline the Trie function in the 765 * expanded functions. (Both the 8 and 16 bit access functions have the same type 766 * signature) 767 */ 768 769 typedef uint16_t (*PTrieFunc)(const UCPTrie *, UChar32); 770 771 template 772 int32_t handleSafePrevious(int32_t fromPosition); 773 774 template 775 int32_t handleNext(); 776 777 778 /** 779 * This function returns the appropriate LanguageBreakEngine for a 780 * given character c. 781 * @param c A character in the dictionary set 782 * @param locale The locale. 783 * @internal (private) 784 */ 785 const LanguageBreakEngine *getLanguageBreakEngine(UChar32 c, const char* locale); 786 787 public: 788 #ifndef U_HIDE_INTERNAL_API 789 /** 790 * Debugging function only. 791 * @internal 792 */ 793 void dumpCache(); 794 795 /** 796 * Debugging function only. 797 * @internal 798 */ 799 void dumpTables(); 800 #endif /* U_HIDE_INTERNAL_API */ 801 802 #ifndef U_HIDE_DRAFT_API 803 /** 804 * Register a new external break engine. The external break engine will be adopted. 805 * Because ICU may choose to cache break engine internally, this must 806 * be called at application startup, prior to any calls to 807 * object methods of RuleBasedBreakIterator to avoid undefined behavior. 808 * @param toAdopt the ExternalBreakEngine instance to be adopted 809 * @param status the in/out status code, no special meanings are assigned 810 * @internal ICU 74 technology preview 811 */ 812 static void U_EXPORT2 registerExternalBreakEngine( 813 ExternalBreakEngine* toAdopt, UErrorCode& status); 814 #endif /* U_HIDE_DRAFT_API */ 815 816 }; 817 818 819 U_NAMESPACE_END 820 821 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */ 822 823 #endif /* U_SHOW_CPLUSPLUS_API */ 824 825 #endif