]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/filteredbrk.h
ICU-551.30.tar.gz
[apple/icu.git] / icuSources / common / unicode / filteredbrk.h
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
6 */
7
8 #ifndef FILTEREDBRK_H
9 #define FILTEREDBRK_H
10
11 #include "unicode/utypes.h"
12 #include "unicode/brkiter.h"
13
14 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILTERED_BREAK_ITERATION
15 #ifndef U_HIDE_INTERNAL_API
16
17 U_NAMESPACE_BEGIN
18
19 /**
20 * \file
21 * \brief C++ API: FilteredBreakIteratorBuilder
22 */
23
24 /**
25 * The BreakIteratorFilter is used to modify the behavior of a BreakIterator
26 * by constructing a new BreakIterator which suppresses certain segment boundaries.
27 * See http://www.unicode.org/reports/tr35/tr35-general.html#Segmentation_Exceptions .
28 * For example, a typical English Sentence Break Iterator would break on the space
29 * in the string "Mr. Smith" (resulting in two segments),
30 * but with "Mr." as an exception, a filtered break iterator
31 * would consider the string "Mr. Smith" to be a single segment.
32 *
33 * <p><b>Note:</b> An instance of {@link BreakIterator} returned by this builder
34 * class currently does not support following operations in this technology preview
35 * version:
36 * <ul>
37 * <li>{@link BreakIterator#next(int32_t) next(int32_t n)}</li>
38 * <li>{@link BreakIterator#previous(void) previous(void)}</li>
39 * <li>{@link BreakIterator#following(int32_t) following(int32_t offset)}</li>
40 * <li>{@link BreakIterator#preceding(int32_t) preceding(int32_t offset)}</li>
41 * </ul>
42 * When one of above methods is called, the corresponding method of the adopted
43 * BreakIterator will be invoked (i.e. no segment suppressions will be used).
44 * Note: This fallback behavior undoes r36410 in which these methods were changed
45 * to just return BreakIterator.DONE immediately without updating the internal state.
46 *
47 * @internal technology preview
48 */
49 class U_COMMON_API FilteredBreakIteratorBuilder : public UObject {
50 public:
51 /**
52 * destructor.
53 * @internal technology preview
54 */
55 virtual ~FilteredBreakIteratorBuilder();
56
57 /**
58 * Construct a FilteredBreakIteratorBuilder based on rules in a locale.
59 * The rules are taken from CLDR exception data for the locale,
60 * see http://www.unicode.org/reports/tr35/tr35-general.html#Segmentation_Exceptions
61 * This is the equivalent of calling createInstance(UErrorCode&)
62 * and then repeatedly calling addNoBreakAfter(...) with the contents
63 * of the CLDR exception data.
64 * @param where the locale.
65 * @param status The error code.
66 * @return the new builder
67 * @internal technology preview
68 */
69 static FilteredBreakIteratorBuilder *createInstance(const Locale& where, UErrorCode& status);
70
71 /**
72 * Construct an empty FilteredBreakIteratorBuilder.
73 * In this state, it will not suppress any segment boundaries.
74 * @param status The error code.
75 * @return the new builder
76 * @internal technology preview
77 */
78 static FilteredBreakIteratorBuilder *createInstance(UErrorCode &status);
79
80 /**
81 * Suppress a certain string from being the end of a segment.
82 * For example, suppressing "Mr.", then segments ending in "Mr." will not be returned
83 * by the iterator.
84 * @param string the string to suppress, such as "Mr."
85 * @param status error code
86 * @return returns TRUE if the string was not present and now added,
87 * FALSE if the call was a no-op because the string was already being suppressed.
88 * @internal technology preview
89 */
90 virtual UBool suppressBreakAfter(const UnicodeString& string, UErrorCode& status) = 0;
91
92 /**
93 * Stop suppressing a certain string from being the end of the segment.
94 * This function does not create any new segment boundaries, but only serves to un-do
95 * the effect of earlier calls to suppressBreakAfter, or to un-do the effect of
96 * locale data which may be suppressing certain strings.
97 * @param exception the exception to remove
98 * @param status error code
99 * @return returns TRUE if the string was present and now removed,
100 * FALSE if the call was a no-op because the string was not being suppressed.
101 * @internal technology preview
102 */
103 virtual UBool unsuppressBreakAfter(const UnicodeString& string, UErrorCode& status) = 0;
104
105 /**
106 * Wrap (adopt) an existing break iterator in a new filtered instance.
107 * The resulting BreakIterator is owned by the caller.
108 * The BreakIteratorFilter may be destroyed before the BreakIterator is destroyed.
109 * Note that the adoptBreakIterator is adopted by the new BreakIterator
110 * and should no longer be used by the caller.
111 * The FilteredBreakIteratorBuilder may be reused.
112 * @param adoptBreakIterator the break iterator to adopt
113 * @param status error code
114 * @return the new BreakIterator, owned by the caller.
115 * @internal technology preview
116 */
117 virtual BreakIterator *build(BreakIterator* adoptBreakIterator, UErrorCode& status) = 0;
118
119 protected:
120 /**
121 * For subclass use
122 * @internal technology preview
123 */
124 FilteredBreakIteratorBuilder();
125 };
126
127
128 U_NAMESPACE_END
129
130 #endif /* U_HIDE_INTERNAL_API */
131 #endif // #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILTERED_BREAK_ITERATION
132
133 #endif // #ifndef FILTEREDBRK_H