2 *******************************************************************************
3 * Copyright (C) 2012-2016, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * uitercollationiterator.h
8 * created on: 2012sep23 (from utf16collationiterator.h)
9 * created by: Markus W. Scherer
12 #ifndef __UITERCOLLATIONITERATOR_H__
13 #define __UITERCOLLATIONITERATOR_H__
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_COLLATION
19 #include "unicode/uiter.h"
21 #include "collation.h"
22 #include "collationdata.h"
23 #include "collationiterator.h"
24 #include "normalizer2impl.h"
29 * UCharIterator-based collation element and character iterator.
30 * Handles normalized text inline, with length or NUL-terminated.
31 * Unnormalized text is handled by a subclass.
33 class U_I18N_API UIterCollationIterator
: public CollationIterator
{
35 UIterCollationIterator(const CollationData
*d
, UBool numeric
, UCharIterator
&ui
)
36 : CollationIterator(d
, numeric
), iter(ui
) {}
38 virtual ~UIterCollationIterator();
40 virtual void resetToOffset(int32_t newOffset
);
42 virtual int32_t getOffset() const;
44 virtual UChar32
nextCodePoint(UErrorCode
&errorCode
);
46 virtual UChar32
previousCodePoint(UErrorCode
&errorCode
);
49 virtual uint32_t handleNextCE32(UChar32
&c
, UErrorCode
&errorCode
);
51 virtual UChar
handleGetTrailSurrogate();
53 virtual void forwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
55 virtual void backwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
61 * Incrementally checks the input text for FCD and normalizes where necessary.
63 class U_I18N_API FCDUIterCollationIterator
: public UIterCollationIterator
{
65 FCDUIterCollationIterator(const CollationData
*data
, UBool numeric
, UCharIterator
&ui
, int32_t startIndex
)
66 : UIterCollationIterator(data
, numeric
, ui
),
67 state(ITER_CHECK_FWD
), start(startIndex
),
68 nfcImpl(data
->nfcImpl
) {}
70 virtual ~FCDUIterCollationIterator();
72 virtual void resetToOffset(int32_t newOffset
);
74 virtual int32_t getOffset() const;
76 virtual UChar32
nextCodePoint(UErrorCode
&errorCode
);
78 virtual UChar32
previousCodePoint(UErrorCode
&errorCode
);
81 virtual uint32_t handleNextCE32(UChar32
&c
, UErrorCode
&errorCode
);
83 virtual UChar
handleGetTrailSurrogate();
85 virtual void forwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
87 virtual void backwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
91 * Switches to forward checking if possible.
93 void switchToForward();
96 * Extends the FCD text segment forward or normalizes around pos.
97 * @return TRUE if success
99 UBool
nextSegment(UErrorCode
&errorCode
);
102 * Switches to backward checking.
104 void switchToBackward();
107 * Extends the FCD text segment backward or normalizes around pos.
108 * @return TRUE if success
110 UBool
previousSegment(UErrorCode
&errorCode
);
112 UBool
normalize(const UnicodeString
&s
, UErrorCode
&errorCode
);
116 * The input text [start..(iter index)[ passes the FCD check.
117 * Moving forward checks incrementally.
118 * pos & limit are undefined.
122 * The input text [(iter index)..limit[ passes the FCD check.
123 * Moving backward checks incrementally.
124 * start & pos are undefined.
128 * The input text [start..limit[ passes the FCD check.
129 * pos tracks the current text index.
133 * The input text [start..limit[ failed the FCD check and was normalized.
134 * pos tracks the current index in the normalized string.
135 * The text iterator is at the limit index.
137 IN_NORM_ITER_AT_LIMIT
,
139 * The input text [start..limit[ failed the FCD check and was normalized.
140 * pos tracks the current index in the normalized string.
141 * The text iterator is at the start index.
143 IN_NORM_ITER_AT_START
152 const Normalizer2Impl
&nfcImpl
;
153 UnicodeString normalized
;
158 #endif // !UCONFIG_NO_COLLATION
159 #endif // __UITERCOLLATIONITERATOR_H__