Debian Codegraph @

intl/icu/source/common/unicode/rbbi.h

raw
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ***************************************************************************
5 * Copyright (C) 1999-2016 International Business Machines Corporation *
6 * and others. All rights reserved. *
7 ***************************************************************************
8
9 **********************************************************************
10 * Date Name Description
11 * 10/22/99 alan Creation.
12 * 11/11/99 rgillam Complete port from Java.
13 **********************************************************************
14 */
15
16 #ifndef RBBI_H
17 #define RBBI_H
18
19 #include "unicode/utypes.h"
20
21 #if U_SHOW_CPLUSPLUS_API
22
23 /**
24 * \file
25 * \brief C++ API: Rule Based Break Iterator
26 */
27
28 #if !UCONFIG_NO_BREAK_ITERATION
29
30 #include "unicode/brkiter.h"
31 #include "unicode/udata.h"
32 #include "unicode/parseerr.h"
33 #include "unicode/schriter.h"
34
35 struct UCPTrie;
36
37 U_NAMESPACE_BEGIN
38
39 /** @internal */
40 class LanguageBreakEngine;
41 struct RBBIDataHeader;
42 class RBBIDataWrapper;
43 class UnhandledEngine;
44 class UStack;
45
46
47 #ifndef U_HIDE_INTERNAL_API
48 /**
49 * The ExternalBreakEngine class define an abstract interface for the host environment
50 * to provide a low level facility to break text for unicode text in script that the text boundary
51 * cannot be handled by upper level rule based logic, for example, for Chinese and Japanese
52 * word breaking, Thai, Khmer, Burmese, Lao and other Southeast Asian scripts.
53 * The host environment implement one or more subclass of ExternalBreakEngine and
54 * register them in the initialization time by calling
55 * RuleBasedBreakIterator::registerExternalBreakEngine(). ICU adopt and own the engine and will
56 * delete the registered external engine in proper time during the clean up
57 * event.
58 * @internal ICU 74 technology preview
59 */
60 class ExternalBreakEngine : public UObject {
61 public:
62 /**
63 * destructor
64 * @internal ICU 74 technology preview
65 */
66 virtual ~ExternalBreakEngine() {}
67
68 /**
69 * <p>Indicate whether this engine handles a particular character when
70 * the RuleBasedBreakIterator is used for a particular locale. This method is used
71 * by the RuleBasedBreakIterator to find a break engine.</p>
72 * @param c A character which begins a run that the engine might handle.
73 * @param locale The locale.
74 * @return true if this engine handles the particular character for that locale.
75 * @internal ICU 74 technology preview
76 */
77 virtual bool isFor(UChar32 c, const char* locale) const = 0;
78
79 /**
80 * <p>Indicate whether this engine handles a particular character.This method is
81 * used by the RuleBasedBreakIterator after it already find a break engine to see which
82 * characters after the first one can be handled by this break engine.</p>
83 * @param c A character that the engine might handle.
84 * @return true if this engine handles the particular character.
85 * @internal ICU 74 technology preview
86 */
87 virtual bool handles(UChar32 c) const = 0;
88
89 /**
90 * <p>Divide up a range of text handled by this break engine.</p>
91 *
92 * @param text A UText representing the text
93 * @param start The start of the range of known characters
94 * @param end The end of the range of known characters
95 * @param foundBreaks Output of C array of int32_t break positions, or
96 * nullptr
97 * @param foundBreaksCapacity The capacity of foundBreaks
98 * @param status Information on any errors encountered.
99 * @return The number of breaks found
100 * @internal ICU 74 technology preview
101 */
102 virtual int32_t fillBreaks(UText* text, int32_t start, int32_t end,
103 int32_t* foundBreaks, int32_t foundBreaksCapacity,
104 UErrorCode& status) const = 0;
105 };
106 #endif /* U_HIDE_INTERNAL_API */
107
108
109 /**
110 *
111 * A subclass of BreakIterator whose behavior is specified using a list of rules.
112 * <p>Instances of this class are most commonly created by the factory methods of
113 * BreakIterator::createWordInstance(), BreakIterator::createLineInstance(), etc.,
114 * and then used via the abstract API in class BreakIterator</p>
115 *
116 * <p>See the ICU User Guide for information on Break Iterator Rules.</p>
117 *
118 * <p>This class is not intended to be subclassed.</p>
119 */
120 class U_COMMON_API RuleBasedBreakIterator /*final*/ : public BreakIterator {
121
122 private:
123 /**
124 * The UText through which this BreakIterator accesses the text
125 * @internal (private)
126 */
127 UText fText = UTEXT_INITIALIZER;
128
129 #ifndef U_HIDE_INTERNAL_API
130 public:
131 #endif /* U_HIDE_INTERNAL_API */
132 /**
133 * The rule data for this BreakIterator instance.
134 * Not for general use; Public only for testing purposes.
135 * @internal
136 */
137 RBBIDataWrapper *fData = nullptr;
138
139 private:
140 /**
141 * The saved error code associated with this break iterator.
142 * This is the value to be returned by copyErrorTo().
143 */
144 UErrorCode fErrorCode = U_ZERO_ERROR;
145
146 /**
147 * The current position of the iterator. Pinned, 0 < fPosition <= text.length.
148 * Never has the value UBRK_DONE (-1).
149 */
150 int32_t fPosition = 0;
151
152 /**
153 * TODO:
154 */
155 int32_t fRuleStatusIndex = 0;
156
157 /**
158 * Cache of previously determined boundary positions.
159 */
160 class BreakCache;
161 BreakCache *fBreakCache = nullptr;
162
163 /**
164 * Cache of boundary positions within a region of text that has been
165 * sub-divided by dictionary based breaking.
166 */
167 class DictionaryCache;
168 DictionaryCache *fDictionaryCache = nullptr;
169
170 /**
171 *
172 * If present, UStack of LanguageBreakEngine objects that might handle
173 * dictionary characters. Searched from top to bottom to find an object to
174 * handle a given character.
175 * @internal (private)
176 */
177 UStack *fLanguageBreakEngines = nullptr;
178
179 /**
180 *
181 * If present, the special LanguageBreakEngine used for handling
182 * characters that are in the dictionary set, but not handled by any
183 * LanguageBreakEngine.
184 * @internal (private)
185 */
186 UnhandledEngine *fUnhandledBreakEngine = nullptr;
187
188 /**
189 * Counter for the number of characters encountered with the "dictionary"
190 * flag set.
191 * @internal (private)
192 */
193 uint32_t fDictionaryCharCount = 0;
194
195 /**
196 * A character iterator that refers to the same text as the UText, above.
197 * Only included for compatibility with old API, which was based on CharacterIterators.
198 * Value may be adopted from outside, or one of fSCharIter or fDCharIter, below.
199 */
200 CharacterIterator *fCharIter = &fSCharIter;
201
202 /**
203 * When the input text is provided by a UnicodeString, this will point to
204 * a characterIterator that wraps that data. Needed only for the
205 * implementation of getText(), a backwards compatibility issue.
206 */
207 UCharCharacterIterator fSCharIter {u"", 0};
208
209 /**
210 * True when iteration has run off the end, and iterator functions should return UBRK_DONE.
211 */
212 bool fDone = false;
213
214 /**
215 * Array of look-ahead tentative results.
216 */
217 int32_t *fLookAheadMatches = nullptr;
218
219 /**
220 * A flag to indicate if phrase based breaking is enabled.
221 */
222 UBool fIsPhraseBreaking = false;
223
224 //=======================================================================
225 // constructors
226 //=======================================================================
227
228 /**
229 * Constructor from a flattened set of RBBI data in malloced memory.
230 * RulesBasedBreakIterators built from a custom set of rules
231 * are created via this constructor; the rules are compiled
232 * into memory, then the break iterator is constructed here.
233 *
234 * The break iterator adopts the memory, and will
235 * free it when done.
236 * @internal (private)
237 */
238 RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status);
239
240 /**
241 * This constructor uses the udata interface to create a BreakIterator
242 * whose internal tables live in a memory-mapped file. "image" is an
243 * ICU UDataMemory handle for the pre-compiled break iterator tables.
244 * @param image handle to the memory image for the break iterator data.
245 * Ownership of the UDataMemory handle passes to the Break Iterator,
246 * which will be responsible for closing it when it is no longer needed.
247 * @param status Information on any errors encountered.
248 * @param isPhraseBreaking true if phrase based breaking is required, otherwise false.
249 * @see udata_open
250 * @see #getBinaryRules
251 * @internal (private)
252 */
253 RuleBasedBreakIterator(UDataMemory* image, UBool isPhraseBreaking, UErrorCode &status);
254
255 /** @internal */
256 friend class RBBIRuleBuilder;
257 /** @internal */
258 friend class BreakIterator;
259
260 /**
261 * Default constructor with an error code parameter.
262 * Aside from error handling, otherwise identical to the default constructor.
263 * Internally, handles common initialization for other constructors.
264 * @internal (private)
265 */
266 RuleBasedBreakIterator(UErrorCode *status);
267
268 public:
269
270 /** Default constructor. Creates an empty shell of an iterator, with no
271 * rules or text to iterate over. Object can subsequently be assigned to,
272 * but is otherwise unusable.
273 * @stable ICU 2.2
274 */
275 RuleBasedBreakIterator();
276
277 /**
278 * Copy constructor. Will produce a break iterator with the same behavior,
279 * and which iterates over the same text, as the one passed in.
280 * @param that The RuleBasedBreakIterator passed to be copied
281 * @stable ICU 2.0
282 */
283 RuleBasedBreakIterator(const RuleBasedBreakIterator& that);
284
285 /**
286 * Construct a RuleBasedBreakIterator from a set of rules supplied as a string.
287 * @param rules The break rules to be used.
288 * @param parseError In the event of a syntax error in the rules, provides the location
289 * within the rules of the problem.
290 * @param status Information on any errors encountered.
291 * @stable ICU 2.2
292 */
293 RuleBasedBreakIterator( const UnicodeString &rules,
294 UParseError &parseError,
295 UErrorCode &status);
296
297 /**
298 * Construct a RuleBasedBreakIterator from a set of precompiled binary rules.
299 * Binary rules are obtained from RulesBasedBreakIterator::getBinaryRules().
300 * Construction of a break iterator in this way is substantially faster than
301 * construction from source rules.
302 *
303 * Ownership of the storage containing the compiled rules remains with the
304 * caller of this function. The compiled rules must not be modified or
305 * deleted during the life of the break iterator.
306 *
307 * The compiled rules are not compatible across different major versions of ICU.
308 * The compiled rules are compatible only between machines with the same
309 * byte ordering (little or big endian) and the same base character set family
310 * (ASCII or EBCDIC).
311 *
312 * @see #getBinaryRules
313 * @param compiledRules A pointer to the compiled break rules to be used.
314 * @param ruleLength The length of the compiled break rules, in bytes. This
315 * corresponds to the length value produced by getBinaryRules().
316 * @param status Information on any errors encountered, including invalid
317 * binary rules.
318 * @stable ICU 4.8
319 */
320 RuleBasedBreakIterator(const uint8_t *compiledRules,
321 uint32_t ruleLength,
322 UErrorCode &status);
323
324 /**
325 * This constructor uses the udata interface to create a BreakIterator
326 * whose internal tables live in a memory-mapped file. "image" is an
327 * ICU UDataMemory handle for the pre-compiled break iterator tables.
328 * @param image handle to the memory image for the break iterator data.
329 * Ownership of the UDataMemory handle passes to the Break Iterator,
330 * which will be responsible for closing it when it is no longer needed.
331 * @param status Information on any errors encountered.
332 * @see udata_open
333 * @see #getBinaryRules
334 * @stable ICU 2.8
335 */
336 RuleBasedBreakIterator(UDataMemory* image, UErrorCode &status);
337
338 /**
339 * Destructor
340 * @stable ICU 2.0
341 */
342 virtual ~RuleBasedBreakIterator();
343
344 /**
345 * Assignment operator. Sets this iterator to have the same behavior,
346 * and iterate over the same text, as the one passed in.
347 * @param that The RuleBasedBreakItertor passed in
348 * @return the newly created RuleBasedBreakIterator
349 * @stable ICU 2.0
350 */
351 RuleBasedBreakIterator& operator=(const RuleBasedBreakIterator& that);
352
353 /**
354 * Equality operator. Returns true if both BreakIterators are of the
355 * same class, have the same behavior, and iterate over the same text.
356 * @param that The BreakIterator to be compared for equality
357 * @return true if both BreakIterators are of the
358 * same class, have the same behavior, and iterate over the same text.
359 * @stable ICU 2.0
360 */
361 virtual bool operator==(const BreakIterator& that) const override;
362
363 /**
364 * Not-equal operator. If operator== returns true, this returns false,
365 * and vice versa.
366 * @param that The BreakIterator to be compared for inequality
367 * @return true if both BreakIterators are not same.
368 * @stable ICU 2.0
369 */
370 inline bool operator!=(const BreakIterator& that) const {
371 return !operator==(that);
372 }
373
374 /**
375 * Returns a newly-constructed RuleBasedBreakIterator with the same
376 * behavior, and iterating over the same text, as this one.
377 * Differs from the copy constructor in that it is polymorphic, and
378 * will correctly clone (copy) a derived class.
379 * clone() is thread safe. Multiple threads may simultaneously
380 * clone the same source break iterator.
381 * @return a newly-constructed RuleBasedBreakIterator
382 * @stable ICU 2.0
383 */
384 virtual RuleBasedBreakIterator* clone() const override;
385
386 /**
387 * Compute a hash code for this BreakIterator
388 * @return A hash code
389 * @stable ICU 2.0
390 */
391 virtual int32_t hashCode() const;
392
393 /**
394 * Returns the description used to create this iterator
395 * @return the description used to create this iterator
396 * @stable ICU 2.0
397 */
398 virtual const UnicodeString& getRules() const;
399
400 //=======================================================================
401 // BreakIterator overrides
402 //=======================================================================
403
404 /**
405 * <p>
406 * Return a CharacterIterator over the text being analyzed.
407 * The returned character iterator is owned by the break iterator, and must
408 * not be deleted by the caller. Repeated calls to this function may
409 * return the same CharacterIterator.
410 * </p>
411 * <p>
412 * The returned character iterator must not be used concurrently with
413 * the break iterator. If concurrent operation is needed, clone the
414 * returned character iterator first and operate on the clone.
415 * </p>
416 * <p>
417 * When the break iterator is operating on text supplied via a UText,
418 * this function will fail, returning a CharacterIterator containing no text.
419 * The function getUText() provides similar functionality,
420 * is reliable, and is more efficient.
421 * </p>
422 *
423 * TODO: deprecate this function?
424 *
425 * @return An iterator over the text being analyzed.
426 * @stable ICU 2.0
427 */
428 virtual CharacterIterator& getText() const override;
429
430 /**
431 * Get a UText for the text being analyzed.
432 * The returned UText is a shallow clone of the UText used internally
433 * by the break iterator implementation. It can safely be used to
434 * access the text without impacting any break iterator operations,
435 * but the underlying text itself must not be altered.
436 *
437 * @param fillIn A UText to be filled in. If nullptr, a new UText will be
438 * allocated to hold the result.
439 * @param status receives any error codes.
440 * @return The current UText for this break iterator. If an input
441 * UText was provided, it will always be returned.
442 * @stable ICU 3.4
443 */
444 virtual UText *getUText(UText *fillIn, UErrorCode &status) const override;
445
446 /**
447 * Set the iterator to analyze a new piece of text. This function resets
448 * the current iteration position to the beginning of the text.
449 * @param newText An iterator over the text to analyze. The BreakIterator
450 * takes ownership of the character iterator. The caller MUST NOT delete it!
451 * @stable ICU 2.0
452 */
453 virtual void adoptText(CharacterIterator* newText) override;
454
455 /**
456 * Set the iterator to analyze a new piece of text. This function resets
457 * the current iteration position to the beginning of the text.
458 *
459 * The BreakIterator will retain a reference to the supplied string.
460 * The caller must not modify or delete the text while the BreakIterator
461 * retains the reference.
462 *
463 * @param newText The text to analyze.
464 * @stable ICU 2.0
465 */
466 virtual void setText(const UnicodeString& newText) override;
467
468 /**
469 * Reset the break iterator to operate over the text represented by
470 * the UText. The iterator position is reset to the start.
471 *
472 * This function makes a shallow clone of the supplied UText. This means
473 * that the caller is free to immediately close or otherwise reuse the
474 * Utext that was passed as a parameter, but that the underlying text itself
475 * must not be altered while being referenced by the break iterator.
476 *
477 * @param text The UText used to change the text.
478 * @param status Receives any error codes.
479 * @stable ICU 3.4
480 */
481 virtual void setText(UText *text, UErrorCode &status) override;
482
483 /**
484 * Sets the current iteration position to the beginning of the text, position zero.
485 * @return The offset of the beginning of the text, zero.
486 * @stable ICU 2.0
487 */
488 virtual int32_t first() override;
489
490 /**
491 * Sets the current iteration position to the end of the text.
492 * @return The text's past-the-end offset.
493 * @stable ICU 2.0
494 */
495 virtual int32_t last() override;
496
497 /**
498 * Advances the iterator either forward or backward the specified number of steps.
499 * Negative values move backward, and positive values move forward. This is
500 * equivalent to repeatedly calling next() or previous().
501 * @param n The number of steps to move. The sign indicates the direction
502 * (negative is backwards, and positive is forwards).
503 * @return The character offset of the boundary position n boundaries away from
504 * the current one.
505 * @stable ICU 2.0
506 */
507 virtual int32_t next(int32_t n) override;
508
509 /**
510 * Advances the iterator to the next boundary position.
511 * @return The position of the first boundary after this one.
512 * @stable ICU 2.0
513 */
514 virtual int32_t next() override;
515
516 /**
517 * Moves the iterator backwards, to the last boundary preceding this one.
518 * @return The position of the last boundary position preceding this one.
519 * @stable ICU 2.0
520 */
521 virtual int32_t previous() override;
522
523 /**
524 * Sets the iterator to refer to the first boundary position following
525 * the specified position.
526 * @param offset The position from which to begin searching for a break position.
527 * @return The position of the first break after the current position.
528 * @stable ICU 2.0
529 */
530 virtual int32_t following(int32_t offset) override;
531
532 /**
533 * Sets the iterator to refer to the last boundary position before the
534 * specified position.
535 * @param offset The position to begin searching for a break from.
536 * @return The position of the last boundary before the starting position.
537 * @stable ICU 2.0
538 */
539 virtual int32_t preceding(int32_t offset) override;
540
541 /**
542 * Returns true if the specified position is a boundary position. As a side
543 * effect, leaves the iterator pointing to the first boundary position at
544 * or after "offset".
545 * @param offset the offset to check.
546 * @return True if "offset" is a boundary position.
547 * @stable ICU 2.0
548 */
549 virtual UBool isBoundary(int32_t offset) override;
550
551 /**
552 * Returns the current iteration position. Note that UBRK_DONE is never
553 * returned from this function; if iteration has run to the end of a
554 * string, current() will return the length of the string while
555 * next() will return UBRK_DONE).
556 * @return The current iteration position.
557 * @stable ICU 2.0
558 */
559 virtual int32_t current() const override;
560
561 /**
562 * Return the status tag from the break rule that determined the boundary at
563 * the current iteration position. For break rules that do not specify a
564 * status, a default value of 0 is returned. If more than one break rule
565 * would cause a boundary to be located at some position in the text,
566 * the numerically largest of the applicable status values is returned.
567 * <p>
568 * Of the standard types of ICU break iterators, only word break and
569 * line break provide status values. The values are defined in
570 * the header file ubrk.h. For Word breaks, the status allows distinguishing between words
571 * that contain alphabetic letters, "words" that appear to be numbers,
572 * punctuation and spaces, words containing ideographic characters, and
573 * more. For Line Break, the status distinguishes between hard (mandatory) breaks
574 * and soft (potential) break positions.
575 * <p>
576 * <code>getRuleStatus()</code> can be called after obtaining a boundary
577 * position from <code>next()</code>, <code>previous()</code>, or
578 * any other break iterator functions that returns a boundary position.
579 * <p>
580 * Note that <code>getRuleStatus()</code> returns the value corresponding to
581 * <code>current()</code> index even after <code>next()</code> has returned DONE.
582 * <p>
583 * When creating custom break rules, one is free to define whatever
584 * status values may be convenient for the application.
585 * <p>
586 * @return the status from the break rule that determined the boundary
587 * at the current iteration position.
588 *
589 * @see UWordBreak
590 * @stable ICU 2.2
591 */
592 virtual int32_t getRuleStatus() const override;
593
594 /**
595 * Get the status (tag) values from the break rule(s) that determined the boundary
596 * at the current iteration position.
597 * <p>
598 * The returned status value(s) are stored into an array provided by the caller.
599 * The values are stored in sorted (ascending) order.
600 * If the capacity of the output array is insufficient to hold the data,
601 * the output will be truncated to the available length, and a
602 * U_BUFFER_OVERFLOW_ERROR will be signaled.
603 *
604 * @param fillInVec an array to be filled in with the status values.
605 * @param capacity the length of the supplied vector. A length of zero causes
606 * the function to return the number of status values, in the
607 * normal way, without attempting to store any values.
608 * @param status receives error codes.
609 * @return The number of rule status values from the rules that determined
610 * the boundary at the current iteration position.
611 * In the event of a U_BUFFER_OVERFLOW_ERROR, the return value
612 * is the total number of status values that were available,
613 * not the reduced number that were actually returned.
614 * @see getRuleStatus
615 * @stable ICU 3.0
616 */
617 virtual int32_t getRuleStatusVec(int32_t *fillInVec, int32_t capacity, UErrorCode &status) override;
618
619 /**
620 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
621 * This method is to implement a simple version of RTTI, since not all
622 * C++ compilers support genuine RTTI. Polymorphic operator==() and
623 * clone() methods call this method.
624 *
625 * @return The class ID for this object. All objects of a
626 * given class have the same class ID. Objects of
627 * other classes have different class IDs.
628 * @stable ICU 2.0
629 */
630 virtual UClassID getDynamicClassID() const override;
631
632 /**
633 * Returns the class ID for this class. This is useful only for
634 * comparing to a return value from getDynamicClassID(). For example:
635 *
636 * Base* polymorphic_pointer = createPolymorphicObject();
637 * if (polymorphic_pointer->getDynamicClassID() ==
638 * Derived::getStaticClassID()) ...
639 *
640 * @return The class ID for all objects of this class.
641 * @stable ICU 2.0
642 */
643 static UClassID U_EXPORT2 getStaticClassID();
644
645 #ifndef U_FORCE_HIDE_DEPRECATED_API
646 /**
647 * Deprecated functionality. Use clone() instead.
648 *
649 * Create a clone (copy) of this break iterator in memory provided
650 * by the caller. The idea is to increase performance by avoiding
651 * a storage allocation. Use of this function is NOT RECOMMENDED.
652 * Performance gains are minimal, and correct buffer management is
653 * tricky. Use clone() instead.
654 *
655 * @param stackBuffer The pointer to the memory into which the cloned object
656 * should be placed. If nullptr, allocate heap memory
657 * for the cloned object.
658 * @param BufferSize The size of the buffer. If zero, return the required
659 * buffer size, but do not clone the object. If the
660 * size was too small (but not zero), allocate heap
661 * storage for the cloned object.
662 *
663 * @param status Error status. U_SAFECLONE_ALLOCATED_WARNING will be
664 * returned if the provided buffer was too small, and
665 * the clone was therefore put on the heap.
666 *
667 * @return Pointer to the clone object. This may differ from the stackBuffer
668 * address if the byte alignment of the stack buffer was not suitable
669 * or if the stackBuffer was too small to hold the clone.
670 * @deprecated ICU 52. Use clone() instead.
671 */
672 virtual RuleBasedBreakIterator *createBufferClone(void *stackBuffer,
673 int32_t &BufferSize,
674 UErrorCode &status) override;
675 #endif // U_FORCE_HIDE_DEPRECATED_API
676
677 /**
678 * Return the binary form of compiled break rules,
679 * which can then be used to create a new break iterator at some
680 * time in the future. Creating a break iterator from pre-compiled rules
681 * is much faster than building one from the source form of the
682 * break rules.
683 *
684 * The binary data can only be used with the same version of ICU
685 * and on the same platform type (processor endian-ness)
686 *
687 * @param length Returns the length of the binary data. (Out parameter.)
688 *
689 * @return A pointer to the binary (compiled) rule data. The storage
690 * belongs to the RulesBasedBreakIterator object, not the
691 * caller, and must not be modified or deleted.
692 * @stable ICU 4.8
693 */
694 virtual const uint8_t *getBinaryRules(uint32_t &length);
695
696 /**
697 * Set the subject text string upon which the break iterator is operating
698 * without changing any other aspect of the matching state.
699 * The new and previous text strings must have the same content.
700 *
701 * This function is intended for use in environments where ICU is operating on
702 * strings that may move around in memory. It provides a mechanism for notifying
703 * ICU that the string has been relocated, and providing a new UText to access the
704 * string in its new position.
705 *
706 * Note that the break iterator implementation never copies the underlying text
707 * of a string being processed, but always operates directly on the original text
708 * provided by the user. Refreshing simply drops the references to the old text
709 * and replaces them with references to the new.
710 *
711 * Caution: this function is normally used only by very specialized,
712 * system-level code. One example use case is with garbage collection that moves
713 * the text in memory.
714 *
715 * @param input The new (moved) text string.
716 * @param status Receives errors detected by this function.
717 * @return *this
718 *
719 * @stable ICU 49
720 */
721 virtual RuleBasedBreakIterator &refreshInputText(UText *input, UErrorCode &status) override;
722
723
724 private:
725 //=======================================================================
726 // implementation
727 //=======================================================================
728 /**
729 * Iterate backwards from an arbitrary position in the input text using the
730 * synthesized Safe Reverse rules.
731 * This locates a "Safe Position" from which the forward break rules
732 * will operate correctly. A Safe Position is not necessarily a boundary itself.
733 *
734 * @param fromPosition the position in the input text to begin the iteration.
735 * @internal (private)
736 */
737 int32_t handleSafePrevious(int32_t fromPosition);
738
739 /**
740 * Find a rule-based boundary by running the state machine.
741 * Input
742 * fPosition, the position in the text to begin from.
743 * Output
744 * fPosition: the boundary following the starting position.
745 * fDictionaryCharCount the number of dictionary characters encountered.
746 * If > 0, the segment will be further subdivided
747 * fRuleStatusIndex Info from the state table indicating which rules caused the boundary.
748 *
749 * @internal (private)
750 */
751 int32_t handleNext();
752
753 /*
754 * Templatized version of handleNext() and handleSafePrevious().
755 *
756 * There will be exactly four instantiations, two each for 8 and 16 bit tables,
757 * two each for 8 and 16 bit trie.
758 * Having separate instantiations for the table types keeps conditional tests of
759 * the table type out of the inner loops, at the expense of replicated code.
760 *
761 * The template parameter for the Trie access function is a value, not a type.
762 * Doing it this way, the compiler will inline the Trie function in the
763 * expanded functions. (Both the 8 and 16 bit access functions have the same type
764 * signature)
765 */
766
767 typedef uint16_t (*PTrieFunc)(const UCPTrie *, UChar32);
768
769 template<typename RowType, PTrieFunc trieFunc>
770 int32_t handleSafePrevious(int32_t fromPosition);
771
772 template<typename RowType, PTrieFunc trieFunc>
773 int32_t handleNext();
774
775
776 /**
777 * This function returns the appropriate LanguageBreakEngine for a
778 * given character c.
779 * @param c A character in the dictionary set
780 * @param locale The locale.
781 * @internal (private)
782 */
783 const LanguageBreakEngine *getLanguageBreakEngine(UChar32 c, const char* locale);
784
785 public:
786 #ifndef U_HIDE_INTERNAL_API
787 /**
788 * Debugging function only.
789 * @internal
790 */
791 void dumpCache();
792
793 /**
794 * Debugging function only.
795 * @internal
796 */
797 void dumpTables();
798 #endif /* U_HIDE_INTERNAL_API */
799
800 #ifndef U_HIDE_INTERNAL_API
801 /**
802 * Register a new external break engine. The external break engine will be adopted.
803 * Because ICU may choose to cache break engine internally, this must
804 * be called at application startup, prior to any calls to
805 * object methods of RuleBasedBreakIterator to avoid undefined behavior.
806 * @param toAdopt the ExternalBreakEngine instance to be adopted
807 * @param status the in/out status code, no special meanings are assigned
808 * @internal ICU 74 technology preview
809 */
810 static void U_EXPORT2 registerExternalBreakEngine(
811 ExternalBreakEngine* toAdopt, UErrorCode& status);
812 #endif /* U_HIDE_INTERNAL_API */
813
814 };
815
816
817 U_NAMESPACE_END
818
819 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
820
821 #endif /* U_SHOW_CPLUSPLUS_API */
822
823 #endif