1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /* 4 ******************************************************************************** 5 * Copyright (C) 1997-2015, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ******************************************************************************** 8 */ 9 10 #ifndef FILTEREDBRK_H 11 #define FILTEREDBRK_H 12 13 #include "unicode/utypes.h" 14 #include "unicode/brkiter.h" 15 16 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILTERED_BREAK_ITERATION 17 18 U_NAMESPACE_BEGIN 19 20 /** 21 * \file 22 * \brief C++ API: FilteredBreakIteratorBuilder 23 */ 24 25 /** 26 * The BreakIteratorFilter is used to modify the behavior of a BreakIterator 27 * by constructing a new BreakIterator which suppresses certain segment boundaries. 28 * See http://www.unicode.org/reports/tr35/tr35-general.html#Segmentation_Exceptions . 29 * For example, a typical English Sentence Break Iterator would break on the space 30 * in the string "Mr. Smith" (resulting in two segments), 31 * but with "Mr." as an exception, a filtered break iterator 32 * would consider the string "Mr. Smith" to be a single segment. 33 * 34 * @stable ICU 56 35 */ 36 class U_COMMON_API FilteredBreakIteratorBuilder : public UObject { 37 public: 38 /** 39 * destructor. 40 * @stable ICU 56 41 */ 42 virtual ~FilteredBreakIteratorBuilder(); 43 44 /** 45 * Construct a FilteredBreakIteratorBuilder based on rules in a locale. 46 * The rules are taken from CLDR exception data for the locale, 47 * see http://www.unicode.org/reports/tr35/tr35-general.html#Segmentation_Exceptions 48 * This is the equivalent of calling createInstance(UErrorCode&) 49 * and then repeatedly calling addNoBreakAfter(...) with the contents 50 * of the CLDR exception data. 51 * @param where the locale. 52 * @param status The error code. 53 * @return the new builder 54 * @stable ICU 56 55 */ 56 static FilteredBreakIteratorBuilder *createInstance(const Locale& where, UErrorCode& status); 57 58 #ifndef U_HIDE_DEPRECATED_API 59 /** 60 * This function has been deprecated in favor of createEmptyInstance, which has 61 * identical behavior. 62 * @param status The error code. 63 * @return the new builder 64 * @deprecated ICU 60 use createEmptyInstance instead 65 * @see createEmptyInstance() 66 */ 67 static FilteredBreakIteratorBuilder *createInstance(UErrorCode &status); 68 #endif /* U_HIDE_DEPRECATED_API */ 69 70 /** 71 * Construct an empty FilteredBreakIteratorBuilder. 72 * In this state, it will not suppress any segment boundaries. 73 * @param status The error code. 74 * @return the new builder 75 * @stable ICU 60 76 */ 77 static FilteredBreakIteratorBuilder *createEmptyInstance(UErrorCode &status); 78 79 /** 80 * Suppress a certain string from being the end of a segment. 81 * For example, suppressing "Mr.", then segments ending in "Mr." will not be returned 82 * by the iterator. 83 * @param string the string to suppress, such as "Mr." 84 * @param status error code 85 * @return returns TRUE if the string was not present and now added, 86 * FALSE if the call was a no-op because the string was already being suppressed. 87 * @stable ICU 56 88 */ 89 virtual UBool suppressBreakAfter(const UnicodeString& string, UErrorCode& status) = 0; 90 91 /** 92 * Stop suppressing a certain string from being the end of the segment. 93 * This function does not create any new segment boundaries, but only serves to un-do 94 * the effect of earlier calls to suppressBreakAfter, or to un-do the effect of 95 * locale data which may be suppressing certain strings. 96 * @param string the exception to remove 97 * @param status error code 98 * @return returns TRUE if the string was present and now removed, 99 * FALSE if the call was a no-op because the string was not being suppressed. 100 * @stable ICU 56 101 */ 102 virtual UBool unsuppressBreakAfter(const UnicodeString& string, UErrorCode& status) = 0; 103 104 /** 105 * This function has been deprecated in favor of wrapIteratorWithFilter() 106 * The behavior is identical. 107 * @param adoptBreakIterator the break iterator to adopt 108 * @param status error code 109 * @return the new BreakIterator, owned by the caller. 110 * @deprecated ICU 60 use wrapIteratorWithFilter() instead 111 * @see wrapBreakIteratorWithFilter() 112 */ 113 virtual BreakIterator *build(BreakIterator* adoptBreakIterator, UErrorCode& status) = 0; 114 115 /** 116 * Wrap (adopt) an existing break iterator in a new filtered instance. 117 * The resulting BreakIterator is owned by the caller. 118 * The BreakIteratorFilter may be destroyed before the BreakIterator is destroyed. 119 * Note that the adoptBreakIterator is adopted by the new BreakIterator 120 * and should no longer be used by the caller. 121 * The FilteredBreakIteratorBuilder may be reused. 122 * This function is an alias for build() 123 * @param adoptBreakIterator the break iterator to adopt 124 * @param status error code 125 * @return the new BreakIterator, owned by the caller. 126 * @stable ICU 60 127 */ wrapIteratorWithFilter(BreakIterator * adoptBreakIterator,UErrorCode & status)128 inline BreakIterator *wrapIteratorWithFilter(BreakIterator* adoptBreakIterator, UErrorCode& status) { 129 return build(adoptBreakIterator, status); 130 } 131 132 protected: 133 /** 134 * For subclass use 135 * @stable ICU 56 136 */ 137 FilteredBreakIteratorBuilder(); 138 }; 139 140 141 U_NAMESPACE_END 142 143 #endif // #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILTERED_BREAK_ITERATION 144 145 #endif // #ifndef FILTEREDBRK_H 146