]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ******************************************************************************** | |
57a6839d | 3 | * Copyright (C) 1997-2014, International Business Machines |
b75a7d8f A |
4 | * Corporation and others. All Rights Reserved. |
5 | ******************************************************************************** | |
6 | * | |
7 | * File brkiter.h | |
8 | * | |
9 | * Modification History: | |
10 | * | |
11 | * Date Name Description | |
12 | * 02/18/97 aliu Added typedef for TextCount. Made DONE const. | |
13 | * 05/07/97 aliu Fixed DLL declaration. | |
14 | * 07/09/97 jfitz Renamed BreakIterator and interface synced with JDK | |
15 | * 08/11/98 helena Sync-up JDK1.2. | |
16 | * 01/13/2000 helena Added UErrorCode parameter to createXXXInstance methods. | |
17 | ******************************************************************************** | |
18 | */ | |
19 | ||
20 | #ifndef BRKITER_H | |
21 | #define BRKITER_H | |
22 | ||
23 | #include "unicode/utypes.h" | |
24 | ||
73c04bcf A |
25 | /** |
26 | * \file | |
27 | * \brief C++ API: Break Iterator. | |
28 | */ | |
46f4442e | 29 | |
b75a7d8f A |
30 | #if UCONFIG_NO_BREAK_ITERATION |
31 | ||
32 | U_NAMESPACE_BEGIN | |
33 | ||
34 | /* | |
35 | * Allow the declaration of APIs with pointers to BreakIterator | |
36 | * even when break iteration is removed from the build. | |
37 | */ | |
38 | class BreakIterator; | |
39 | ||
40 | U_NAMESPACE_END | |
41 | ||
42 | #else | |
43 | ||
44 | #include "unicode/uobject.h" | |
45 | #include "unicode/unistr.h" | |
46 | #include "unicode/chariter.h" | |
47 | #include "unicode/locid.h" | |
48 | #include "unicode/ubrk.h" | |
49 | #include "unicode/strenum.h" | |
73c04bcf A |
50 | #include "unicode/utext.h" |
51 | #include "unicode/umisc.h" | |
b75a7d8f A |
52 | |
53 | U_NAMESPACE_BEGIN | |
54 | ||
b75a7d8f A |
55 | /** |
56 | * The BreakIterator class implements methods for finding the location | |
57 | * of boundaries in text. BreakIterator is an abstract base class. | |
58 | * Instances of BreakIterator maintain a current position and scan over | |
59 | * text returning the index of characters where boundaries occur. | |
73c04bcf | 60 | * <p> |
b75a7d8f A |
61 | * Line boundary analysis determines where a text string can be broken |
62 | * when line-wrapping. The mechanism correctly handles punctuation and | |
63 | * hyphenated words. | |
73c04bcf | 64 | * <p> |
b75a7d8f A |
65 | * Sentence boundary analysis allows selection with correct |
66 | * interpretation of periods within numbers and abbreviations, and | |
67 | * trailing punctuation marks such as quotation marks and parentheses. | |
73c04bcf | 68 | * <p> |
b75a7d8f A |
69 | * Word boundary analysis is used by search and replace functions, as |
70 | * well as within text editing applications that allow the user to | |
71 | * select words with a double click. Word selection provides correct | |
72 | * interpretation of punctuation marks within and following | |
73 | * words. Characters that are not part of a word, such as symbols or | |
74 | * punctuation marks, have word-breaks on both sides. | |
73c04bcf | 75 | * <p> |
b75a7d8f A |
76 | * Character boundary analysis allows users to interact with |
77 | * characters as they expect to, for example, when moving the cursor | |
78 | * through a text string. Character boundary analysis provides correct | |
79 | * navigation of through character strings, regardless of how the | |
80 | * character is stored. For example, an accented character might be | |
81 | * stored as a base character and a diacritical mark. What users | |
82 | * consider to be a character can differ between languages. | |
73c04bcf A |
83 | * <p> |
84 | * The text boundary positions are found according to the rules | |
85 | * described in Unicode Standard Annex #29, Text Boundaries, and | |
86 | * Unicode Standard Annex #14, Line Breaking Properties. These | |
87 | * are available at http://www.unicode.org/reports/tr14/ and | |
88 | * http://www.unicode.org/reports/tr29/. | |
89 | * <p> | |
90 | * In addition to the C++ API defined in this header file, a | |
91 | * plain C API with equivalent functionality is defined in the | |
92 | * file ubrk.h | |
93 | * <p> | |
729e4ab9 | 94 | * Code snippets illustrating the use of the Break Iterator APIs |
46f4442e A |
95 | * are available in the ICU User Guide, |
96 | * http://icu-project.org/userguide/boundaryAnalysis.html | |
729e4ab9 | 97 | * and in the sample program icu/source/samples/break/break.cpp |
b75a7d8f | 98 | * |
b75a7d8f A |
99 | */ |
100 | class U_COMMON_API BreakIterator : public UObject { | |
101 | public: | |
102 | /** | |
103 | * destructor | |
104 | * @stable ICU 2.0 | |
105 | */ | |
106 | virtual ~BreakIterator(); | |
107 | ||
108 | /** | |
109 | * Return true if another object is semantically equal to this | |
110 | * one. The other object should be an instance of the same subclass of | |
111 | * BreakIterator. Objects of different subclasses are considered | |
112 | * unequal. | |
113 | * <P> | |
114 | * Return true if this BreakIterator is at the same position in the | |
115 | * same text, and is the same class and type (word, line, etc.) of | |
116 | * BreakIterator, as the argument. Text is considered the same if | |
117 | * it contains the same characters, it need not be the same | |
118 | * object, and styles are not considered. | |
119 | * @stable ICU 2.0 | |
120 | */ | |
121 | virtual UBool operator==(const BreakIterator&) const = 0; | |
122 | ||
123 | /** | |
124 | * Returns the complement of the result of operator== | |
125 | * @param rhs The BreakIterator to be compared for inequality | |
126 | * @return the complement of the result of operator== | |
127 | * @stable ICU 2.0 | |
128 | */ | |
129 | UBool operator!=(const BreakIterator& rhs) const { return !operator==(rhs); } | |
130 | ||
131 | /** | |
132 | * Return a polymorphic copy of this object. This is an abstract | |
133 | * method which subclasses implement. | |
134 | * @stable ICU 2.0 | |
135 | */ | |
136 | virtual BreakIterator* clone(void) const = 0; | |
137 | ||
138 | /** | |
139 | * Return a polymorphic class ID for this object. Different subclasses | |
140 | * will return distinct unequal values. | |
141 | * @stable ICU 2.0 | |
142 | */ | |
143 | virtual UClassID getDynamicClassID(void) const = 0; | |
144 | ||
145 | /** | |
146 | * Return a CharacterIterator over the text being analyzed. | |
b75a7d8f A |
147 | * @stable ICU 2.0 |
148 | */ | |
73c04bcf A |
149 | virtual CharacterIterator& getText(void) const = 0; |
150 | ||
151 | ||
152 | /** | |
153 | * Get a UText for the text being analyzed. | |
154 | * The returned UText is a shallow clone of the UText used internally | |
155 | * by the break iterator implementation. It can safely be used to | |
156 | * access the text without impacting any break iterator operations, | |
157 | * but the underlying text itself must not be altered. | |
158 | * | |
159 | * @param fillIn A UText to be filled in. If NULL, a new UText will be | |
160 | * allocated to hold the result. | |
161 | * @param status receives any error codes. | |
162 | * @return The current UText for this break iterator. If an input | |
163 | * UText was provided, it will always be returned. | |
46f4442e | 164 | * @stable ICU 3.4 |
73c04bcf A |
165 | */ |
166 | virtual UText *getUText(UText *fillIn, UErrorCode &status) const = 0; | |
b75a7d8f A |
167 | |
168 | /** | |
169 | * Change the text over which this operates. The text boundary is | |
170 | * reset to the start. | |
171 | * @param text The UnicodeString used to change the text. | |
172 | * @stable ICU 2.0 | |
173 | */ | |
174 | virtual void setText(const UnicodeString &text) = 0; | |
175 | ||
73c04bcf | 176 | /** |
46f4442e | 177 | * Reset the break iterator to operate over the text represented by |
73c04bcf A |
178 | * the UText. The iterator position is reset to the start. |
179 | * | |
180 | * This function makes a shallow clone of the supplied UText. This means | |
181 | * that the caller is free to immediately close or otherwise reuse the | |
182 | * Utext that was passed as a parameter, but that the underlying text itself | |
183 | * must not be altered while being referenced by the break iterator. | |
184 | * | |
51004dcb A |
185 | * All index positions returned by break iterator functions are |
186 | * native indices from the UText. For example, when breaking UTF-8 | |
187 | * encoded text, the break positions returned by next(), previous(), etc. | |
188 | * will be UTF-8 string indices, not UTF-16 positions. | |
189 | * | |
73c04bcf A |
190 | * @param text The UText used to change the text. |
191 | * @param status receives any error codes. | |
46f4442e | 192 | * @stable ICU 3.4 |
73c04bcf A |
193 | */ |
194 | virtual void setText(UText *text, UErrorCode &status) = 0; | |
195 | ||
b75a7d8f A |
196 | /** |
197 | * Change the text over which this operates. The text boundary is | |
198 | * reset to the start. | |
73c04bcf A |
199 | * Note that setText(UText *) provides similar functionality to this function, |
200 | * and is more efficient. | |
b75a7d8f A |
201 | * @param it The CharacterIterator used to change the text. |
202 | * @stable ICU 2.0 | |
203 | */ | |
204 | virtual void adoptText(CharacterIterator* it) = 0; | |
205 | ||
73c04bcf A |
206 | enum { |
207 | /** | |
208 | * DONE is returned by previous() and next() after all valid | |
209 | * boundaries have been returned. | |
210 | * @stable ICU 2.0 | |
211 | */ | |
212 | DONE = (int32_t)-1 | |
213 | }; | |
b75a7d8f A |
214 | |
215 | /** | |
b331163b A |
216 | * Sets the current iteration position to the beginning of the text, position zero. |
217 | * @return The offset of the beginning of the text, zero. | |
b75a7d8f A |
218 | * @stable ICU 2.0 |
219 | */ | |
220 | virtual int32_t first(void) = 0; | |
221 | ||
222 | /** | |
51004dcb A |
223 | * Set the iterator position to the index immediately BEYOND the last character in the text being scanned. |
224 | * @return The index immediately BEYOND the last character in the text being scanned. | |
b75a7d8f A |
225 | * @stable ICU 2.0 |
226 | */ | |
227 | virtual int32_t last(void) = 0; | |
228 | ||
229 | /** | |
51004dcb | 230 | * Set the iterator position to the boundary preceding the current boundary. |
b75a7d8f A |
231 | * @return The character index of the previous text boundary or DONE if all |
232 | * boundaries have been returned. | |
233 | * @stable ICU 2.0 | |
234 | */ | |
235 | virtual int32_t previous(void) = 0; | |
236 | ||
237 | /** | |
51004dcb | 238 | * Advance the iterator to the boundary following the current boundary. |
b75a7d8f A |
239 | * @return The character index of the next text boundary or DONE if all |
240 | * boundaries have been returned. | |
241 | * @stable ICU 2.0 | |
242 | */ | |
243 | virtual int32_t next(void) = 0; | |
244 | ||
245 | /** | |
246 | * Return character index of the current interator position within the text. | |
247 | * @return The boundary most recently returned. | |
248 | * @stable ICU 2.0 | |
249 | */ | |
250 | virtual int32_t current(void) const = 0; | |
251 | ||
252 | /** | |
51004dcb | 253 | * Advance the iterator to the first boundary following the specified offset. |
b75a7d8f A |
254 | * The value returned is always greater than the offset or |
255 | * the value BreakIterator.DONE | |
256 | * @param offset the offset to begin scanning. | |
257 | * @return The first boundary after the specified offset. | |
258 | * @stable ICU 2.0 | |
259 | */ | |
260 | virtual int32_t following(int32_t offset) = 0; | |
261 | ||
262 | /** | |
51004dcb | 263 | * Set the iterator position to the first boundary preceding the specified offset. |
b75a7d8f A |
264 | * The value returned is always smaller than the offset or |
265 | * the value BreakIterator.DONE | |
266 | * @param offset the offset to begin scanning. | |
267 | * @return The first boundary before the specified offset. | |
268 | * @stable ICU 2.0 | |
269 | */ | |
270 | virtual int32_t preceding(int32_t offset) = 0; | |
271 | ||
272 | /** | |
273 | * Return true if the specfied position is a boundary position. | |
274 | * As a side effect, the current position of the iterator is set | |
275 | * to the first boundary position at or following the specified offset. | |
276 | * @param offset the offset to check. | |
277 | * @return True if "offset" is a boundary position. | |
278 | * @stable ICU 2.0 | |
279 | */ | |
280 | virtual UBool isBoundary(int32_t offset) = 0; | |
281 | ||
282 | /** | |
51004dcb A |
283 | * Set the iterator position to the nth boundary from the current boundary |
284 | * @param n the number of boundaries to move by. A value of 0 | |
b75a7d8f A |
285 | * does nothing. Negative values move to previous boundaries |
286 | * and positive values move to later boundaries. | |
51004dcb | 287 | * @return The new iterator position, or |
b75a7d8f A |
288 | * DONE if there are fewer than |n| boundaries in the specfied direction. |
289 | * @stable ICU 2.0 | |
290 | */ | |
291 | virtual int32_t next(int32_t n) = 0; | |
292 | ||
57a6839d A |
293 | /** |
294 | * For RuleBasedBreakIterators, return the status tag from the | |
295 | * break rule that determined the most recently | |
296 | * returned break position. | |
297 | * <p> | |
298 | * For break iterator types that do not support a rule status, | |
299 | * a default value of 0 is returned. | |
300 | * <p> | |
301 | * @return the status from the break rule that determined the most recently | |
302 | * returned break position. | |
303 | * @see RuleBaseBreakIterator::getRuleStatus() | |
304 | * @see UWordBreak | |
b331163b | 305 | * @stable ICU 52 |
57a6839d A |
306 | */ |
307 | virtual int32_t getRuleStatus() const; | |
308 | ||
309 | /** | |
310 | * For RuleBasedBreakIterators, get the status (tag) values from the break rule(s) | |
311 | * that determined the most recently returned break position. | |
312 | * <p> | |
313 | * For break iterator types that do not support rule status, | |
314 | * no values are returned. | |
315 | * <p> | |
316 | * The returned status value(s) are stored into an array provided by the caller. | |
317 | * The values are stored in sorted (ascending) order. | |
318 | * If the capacity of the output array is insufficient to hold the data, | |
319 | * the output will be truncated to the available length, and a | |
320 | * U_BUFFER_OVERFLOW_ERROR will be signaled. | |
321 | * <p> | |
322 | * @see RuleBaseBreakIterator::getRuleStatusVec | |
323 | * | |
324 | * @param fillInVec an array to be filled in with the status values. | |
325 | * @param capacity the length of the supplied vector. A length of zero causes | |
326 | * the function to return the number of status values, in the | |
327 | * normal way, without attemtping to store any values. | |
328 | * @param status receives error codes. | |
329 | * @return The number of rule status values from rules that determined | |
330 | * the most recent boundary returned by the break iterator. | |
331 | * In the event of a U_BUFFER_OVERFLOW_ERROR, the return value | |
332 | * is the total number of status values that were available, | |
333 | * not the reduced number that were actually returned. | |
334 | * @see getRuleStatus | |
b331163b | 335 | * @stable ICU 52 |
57a6839d A |
336 | */ |
337 | virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status); | |
338 | ||
b75a7d8f A |
339 | /** |
340 | * Create BreakIterator for word-breaks using the given locale. | |
341 | * Returns an instance of a BreakIterator implementing word breaks. | |
342 | * WordBreak is useful for word selection (ex. double click) | |
343 | * @param where the locale. | |
344 | * @param status the error code | |
345 | * @return A BreakIterator for word-breaks. The UErrorCode& status | |
346 | * parameter is used to return status information to the user. | |
347 | * To check whether the construction succeeded or not, you should check | |
348 | * the value of U_SUCCESS(err). If you wish more detailed information, you | |
349 | * can check for informational error results which still indicate success. | |
350 | * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For | |
351 | * example, 'de_CH' was requested, but nothing was found there, so 'de' was | |
352 | * used. U_USING_DEFAULT_WARNING indicates that the default locale data was | |
353 | * used; neither the requested locale nor any of its fall back locales | |
354 | * could be found. | |
355 | * The caller owns the returned object and is responsible for deleting it. | |
356 | * @stable ICU 2.0 | |
357 | */ | |
374ca955 A |
358 | static BreakIterator* U_EXPORT2 |
359 | createWordInstance(const Locale& where, UErrorCode& status); | |
b75a7d8f A |
360 | |
361 | /** | |
362 | * Create BreakIterator for line-breaks using specified locale. | |
363 | * Returns an instance of a BreakIterator implementing line breaks. Line | |
364 | * breaks are logically possible line breaks, actual line breaks are | |
365 | * usually determined based on display width. | |
366 | * LineBreak is useful for word wrapping text. | |
367 | * @param where the locale. | |
368 | * @param status The error code. | |
369 | * @return A BreakIterator for line-breaks. The UErrorCode& status | |
370 | * parameter is used to return status information to the user. | |
371 | * To check whether the construction succeeded or not, you should check | |
372 | * the value of U_SUCCESS(err). If you wish more detailed information, you | |
373 | * can check for informational error results which still indicate success. | |
374 | * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For | |
375 | * example, 'de_CH' was requested, but nothing was found there, so 'de' was | |
376 | * used. U_USING_DEFAULT_WARNING indicates that the default locale data was | |
377 | * used; neither the requested locale nor any of its fall back locales | |
378 | * could be found. | |
379 | * The caller owns the returned object and is responsible for deleting it. | |
380 | * @stable ICU 2.0 | |
381 | */ | |
374ca955 A |
382 | static BreakIterator* U_EXPORT2 |
383 | createLineInstance(const Locale& where, UErrorCode& status); | |
b75a7d8f A |
384 | |
385 | /** | |
386 | * Create BreakIterator for character-breaks using specified locale | |
387 | * Returns an instance of a BreakIterator implementing character breaks. | |
388 | * Character breaks are boundaries of combining character sequences. | |
389 | * @param where the locale. | |
390 | * @param status The error code. | |
391 | * @return A BreakIterator for character-breaks. The UErrorCode& status | |
392 | * parameter is used to return status information to the user. | |
393 | * To check whether the construction succeeded or not, you should check | |
394 | * the value of U_SUCCESS(err). If you wish more detailed information, you | |
395 | * can check for informational error results which still indicate success. | |
396 | * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For | |
397 | * example, 'de_CH' was requested, but nothing was found there, so 'de' was | |
398 | * used. U_USING_DEFAULT_WARNING indicates that the default locale data was | |
399 | * used; neither the requested locale nor any of its fall back locales | |
400 | * could be found. | |
401 | * The caller owns the returned object and is responsible for deleting it. | |
402 | * @stable ICU 2.0 | |
403 | */ | |
374ca955 A |
404 | static BreakIterator* U_EXPORT2 |
405 | createCharacterInstance(const Locale& where, UErrorCode& status); | |
b75a7d8f A |
406 | |
407 | /** | |
408 | * Create BreakIterator for sentence-breaks using specified locale | |
409 | * Returns an instance of a BreakIterator implementing sentence breaks. | |
410 | * @param where the locale. | |
411 | * @param status The error code. | |
412 | * @return A BreakIterator for sentence-breaks. The UErrorCode& status | |
413 | * parameter is used to return status information to the user. | |
414 | * To check whether the construction succeeded or not, you should check | |
415 | * the value of U_SUCCESS(err). If you wish more detailed information, you | |
416 | * can check for informational error results which still indicate success. | |
417 | * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For | |
418 | * example, 'de_CH' was requested, but nothing was found there, so 'de' was | |
419 | * used. U_USING_DEFAULT_WARNING indicates that the default locale data was | |
420 | * used; neither the requested locale nor any of its fall back locales | |
421 | * could be found. | |
422 | * The caller owns the returned object and is responsible for deleting it. | |
423 | * @stable ICU 2.0 | |
424 | */ | |
374ca955 A |
425 | static BreakIterator* U_EXPORT2 |
426 | createSentenceInstance(const Locale& where, UErrorCode& status); | |
b75a7d8f A |
427 | |
428 | /** | |
429 | * Create BreakIterator for title-casing breaks using the specified locale | |
430 | * Returns an instance of a BreakIterator implementing title breaks. | |
374ca955 | 431 | * The iterator returned locates title boundaries as described for |
b75a7d8f | 432 | * Unicode 3.2 only. For Unicode 4.0 and above title boundary iteration, |
374ca955 | 433 | * please use Word Boundary iterator.{@link #createWordInstance } |
b75a7d8f A |
434 | * |
435 | * @param where the locale. | |
436 | * @param status The error code. | |
437 | * @return A BreakIterator for title-breaks. The UErrorCode& status | |
438 | * parameter is used to return status information to the user. | |
439 | * To check whether the construction succeeded or not, you should check | |
440 | * the value of U_SUCCESS(err). If you wish more detailed information, you | |
441 | * can check for informational error results which still indicate success. | |
442 | * U_USING_FALLBACK_WARNING indicates that a fall back locale was used. For | |
443 | * example, 'de_CH' was requested, but nothing was found there, so 'de' was | |
444 | * used. U_USING_DEFAULT_WARNING indicates that the default locale data was | |
445 | * used; neither the requested locale nor any of its fall back locales | |
446 | * could be found. | |
447 | * The caller owns the returned object and is responsible for deleting it. | |
448 | * @stable ICU 2.1 | |
449 | */ | |
374ca955 A |
450 | static BreakIterator* U_EXPORT2 |
451 | createTitleInstance(const Locale& where, UErrorCode& status); | |
b75a7d8f A |
452 | |
453 | /** | |
454 | * Get the set of Locales for which TextBoundaries are installed. | |
455 | * <p><b>Note:</b> this will not return locales added through the register | |
374ca955 A |
456 | * call. To see the registered locales too, use the getAvailableLocales |
457 | * function that returns a StringEnumeration object </p> | |
b75a7d8f A |
458 | * @param count the output parameter of number of elements in the locale list |
459 | * @return available locales | |
460 | * @stable ICU 2.0 | |
461 | */ | |
374ca955 | 462 | static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); |
b75a7d8f A |
463 | |
464 | /** | |
465 | * Get name of the object for the desired Locale, in the desired langauge. | |
466 | * @param objectLocale must be from getAvailableLocales. | |
467 | * @param displayLocale specifies the desired locale for output. | |
468 | * @param name the fill-in parameter of the return value | |
469 | * Uses best match. | |
470 | * @return user-displayable name | |
471 | * @stable ICU 2.0 | |
472 | */ | |
374ca955 | 473 | static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale, |
b75a7d8f A |
474 | const Locale& displayLocale, |
475 | UnicodeString& name); | |
476 | ||
477 | /** | |
478 | * Get name of the object for the desired Locale, in the langauge of the | |
479 | * default locale. | |
480 | * @param objectLocale must be from getMatchingLocales | |
481 | * @param name the fill-in parameter of the return value | |
482 | * @return user-displayable name | |
483 | * @stable ICU 2.0 | |
484 | */ | |
374ca955 | 485 | static UnicodeString& U_EXPORT2 getDisplayName(const Locale& objectLocale, |
b75a7d8f A |
486 | UnicodeString& name); |
487 | ||
488 | /** | |
57a6839d A |
489 | * Deprecated functionality. Use clone() instead. |
490 | * | |
b75a7d8f A |
491 | * Thread safe client-buffer-based cloning operation |
492 | * Do NOT call delete on a safeclone, since 'new' is not used to create it. | |
493 | * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated. | |
494 | * If buffer is not large enough, new memory will be allocated. | |
495 | * @param BufferSize reference to size of allocated space. | |
496 | * If BufferSize == 0, a sufficient size for use in cloning will | |
497 | * be returned ('pre-flighting') | |
498 | * If BufferSize is not enough for a stack-based safe clone, | |
499 | * new memory will be allocated. | |
500 | * @param status to indicate whether the operation went on smoothly or there were errors | |
501 | * An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any allocations were | |
502 | * necessary. | |
503 | * @return pointer to the new clone | |
504 | * | |
57a6839d | 505 | * @deprecated ICU 52. Use clone() instead. |
b75a7d8f A |
506 | */ |
507 | virtual BreakIterator * createBufferClone(void *stackBuffer, | |
508 | int32_t &BufferSize, | |
509 | UErrorCode &status) = 0; | |
510 | ||
57a6839d A |
511 | #ifndef U_HIDE_DEPRECATED_API |
512 | ||
b75a7d8f A |
513 | /** |
514 | * Determine whether the BreakIterator was created in user memory by | |
515 | * createBufferClone(), and thus should not be deleted. Such objects | |
516 | * must be closed by an explicit call to the destructor (not delete). | |
57a6839d | 517 | * @deprecated ICU 52. Always delete the BreakIterator. |
b75a7d8f A |
518 | */ |
519 | inline UBool isBufferClone(void); | |
520 | ||
57a6839d A |
521 | #endif /* U_HIDE_DEPRECATED_API */ |
522 | ||
374ca955 | 523 | #if !UCONFIG_NO_SERVICE |
b75a7d8f A |
524 | /** |
525 | * Register a new break iterator of the indicated kind, to use in the given locale. | |
374ca955 | 526 | * The break iterator will be adopted. Clones of the iterator will be returned |
b75a7d8f A |
527 | * if a request for a break iterator of the given kind matches or falls back to |
528 | * this locale. | |
57a6839d A |
529 | * Because ICU may choose to cache BreakIterators internally, this must |
530 | * be called at application startup, prior to any calls to | |
531 | * BreakIterator::createXXXInstance to avoid undefined behavior. | |
b75a7d8f A |
532 | * @param toAdopt the BreakIterator instance to be adopted |
533 | * @param locale the Locale for which this instance is to be registered | |
534 | * @param kind the type of iterator for which this instance is to be registered | |
535 | * @param status the in/out status code, no special meanings are assigned | |
536 | * @return a registry key that can be used to unregister this instance | |
374ca955 | 537 | * @stable ICU 2.4 |
b75a7d8f | 538 | */ |
374ca955 A |
539 | static URegistryKey U_EXPORT2 registerInstance(BreakIterator* toAdopt, |
540 | const Locale& locale, | |
541 | UBreakIteratorType kind, | |
542 | UErrorCode& status); | |
b75a7d8f A |
543 | |
544 | /** | |
545 | * Unregister a previously-registered BreakIterator using the key returned from the | |
546 | * register call. Key becomes invalid after a successful call and should not be used again. | |
547 | * The BreakIterator corresponding to the key will be deleted. | |
57a6839d A |
548 | * Because ICU may choose to cache BreakIterators internally, this should |
549 | * be called during application shutdown, after all calls to | |
550 | * BreakIterator::createXXXInstance to avoid undefined behavior. | |
b75a7d8f A |
551 | * @param key the registry key returned by a previous call to registerInstance |
552 | * @param status the in/out status code, no special meanings are assigned | |
553 | * @return TRUE if the iterator for the key was successfully unregistered | |
374ca955 | 554 | * @stable ICU 2.4 |
b75a7d8f | 555 | */ |
374ca955 | 556 | static UBool U_EXPORT2 unregister(URegistryKey key, UErrorCode& status); |
b75a7d8f A |
557 | |
558 | /** | |
374ca955 | 559 | * Return a StringEnumeration over the locales available at the time of the call, |
b75a7d8f A |
560 | * including registered locales. |
561 | * @return a StringEnumeration over the locales available at the time of the call | |
374ca955 | 562 | * @stable ICU 2.4 |
b75a7d8f | 563 | */ |
374ca955 A |
564 | static StringEnumeration* U_EXPORT2 getAvailableLocales(void); |
565 | #endif | |
b75a7d8f | 566 | |
374ca955 A |
567 | /** |
568 | * Returns the locale for this break iterator. Two flavors are available: valid and | |
569 | * actual locale. | |
73c04bcf | 570 | * @stable ICU 2.8 |
374ca955 A |
571 | */ |
572 | Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; | |
b75a7d8f | 573 | |
4388f060 | 574 | #ifndef U_HIDE_INTERNAL_API |
374ca955 A |
575 | /** Get the locale for this break iterator object. You can choose between valid and actual locale. |
576 | * @param type type of the locale we're looking for (valid or actual) | |
577 | * @param status error code for the operation | |
578 | * @return the locale | |
579 | * @internal | |
580 | */ | |
581 | const char *getLocaleID(ULocDataLocaleType type, UErrorCode& status) const; | |
4388f060 A |
582 | #endif /* U_HIDE_INTERNAL_API */ |
583 | ||
584 | /** | |
585 | * Set the subject text string upon which the break iterator is operating | |
586 | * without changing any other aspect of the matching state. | |
587 | * The new and previous text strings must have the same content. | |
588 | * | |
589 | * This function is intended for use in environments where ICU is operating on | |
590 | * strings that may move around in memory. It provides a mechanism for notifying | |
591 | * ICU that the string has been relocated, and providing a new UText to access the | |
592 | * string in its new position. | |
593 | * | |
594 | * Note that the break iterator implementation never copies the underlying text | |
595 | * of a string being processed, but always operates directly on the original text | |
596 | * provided by the user. Refreshing simply drops the references to the old text | |
597 | * and replaces them with references to the new. | |
598 | * | |
599 | * Caution: this function is normally used only by very specialized, | |
600 | * system-level code. One example use case is with garbage collection that moves | |
601 | * the text in memory. | |
602 | * | |
603 | * @param input The new (moved) text string. | |
604 | * @param status Receives errors detected by this function. | |
605 | * @return *this | |
606 | * | |
51004dcb | 607 | * @stable ICU 49 |
4388f060 A |
608 | */ |
609 | virtual BreakIterator &refreshInputText(UText *input, UErrorCode &status) = 0; | |
374ca955 A |
610 | |
611 | private: | |
73c04bcf A |
612 | static BreakIterator* buildInstance(const Locale& loc, const char *type, int32_t kind, UErrorCode& status); |
613 | static BreakIterator* createInstance(const Locale& loc, int32_t kind, UErrorCode& status); | |
b75a7d8f A |
614 | static BreakIterator* makeInstance(const Locale& loc, int32_t kind, UErrorCode& status); |
615 | ||
616 | friend class ICUBreakIteratorFactory; | |
617 | friend class ICUBreakIteratorService; | |
618 | ||
619 | protected: | |
4388f060 A |
620 | // Do not enclose protected default/copy constructors with #ifndef U_HIDE_INTERNAL_API |
621 | // or else the compiler will create a public ones. | |
b75a7d8f A |
622 | /** @internal */ |
623 | BreakIterator(); | |
624 | /** @internal */ | |
57a6839d | 625 | BreakIterator (const BreakIterator &other) : UObject(other) {} |
b75a7d8f | 626 | /** @internal */ |
57a6839d | 627 | BreakIterator (const Locale& valid, const Locale& actual); |
b75a7d8f | 628 | private: |
374ca955 A |
629 | |
630 | /** @internal */ | |
631 | char actualLocale[ULOC_FULLNAME_CAPACITY]; | |
632 | char validLocale[ULOC_FULLNAME_CAPACITY]; | |
633 | ||
b75a7d8f A |
634 | /** |
635 | * The assignment operator has no real implementation. | |
636 | * It's provided to make the compiler happy. Do not call. | |
637 | */ | |
73c04bcf | 638 | BreakIterator& operator=(const BreakIterator&); |
b75a7d8f A |
639 | }; |
640 | ||
57a6839d A |
641 | #ifndef U_HIDE_DEPRECATED_API |
642 | ||
b75a7d8f A |
643 | inline UBool BreakIterator::isBufferClone() |
644 | { | |
57a6839d | 645 | return FALSE; |
b75a7d8f A |
646 | } |
647 | ||
57a6839d A |
648 | #endif /* U_HIDE_DEPRECATED_API */ |
649 | ||
b75a7d8f A |
650 | U_NAMESPACE_END |
651 | ||
652 | #endif /* #if !UCONFIG_NO_BREAK_ITERATION */ | |
653 | ||
654 | #endif // _BRKITER | |
655 | //eof |