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