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