1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2012-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * uitercollationiterator.h
10 * created on: 2012sep23 (from utf16collationiterator.h)
11 * created by: Markus W. Scherer
14 #ifndef __UITERCOLLATIONITERATOR_H__
15 #define __UITERCOLLATIONITERATOR_H__
17 #include "unicode/utypes.h"
19 #if !UCONFIG_NO_COLLATION
21 #include "unicode/uiter.h"
23 #include "collation.h"
24 #include "collationdata.h"
25 #include "collationiterator.h"
26 #include "normalizer2impl.h"
31 * UCharIterator-based collation element and character iterator.
32 * Handles normalized text inline, with length or NUL-terminated.
33 * Unnormalized text is handled by a subclass.
35 class U_I18N_API UIterCollationIterator
: public CollationIterator
{
37 UIterCollationIterator(const CollationData
*d
, UBool numeric
, UCharIterator
&ui
)
38 : CollationIterator(d
, numeric
), iter(ui
) {}
40 virtual ~UIterCollationIterator();
42 virtual void resetToOffset(int32_t newOffset
);
44 virtual int32_t getOffset() const;
46 virtual UChar32
nextCodePoint(UErrorCode
&errorCode
);
48 virtual UChar32
previousCodePoint(UErrorCode
&errorCode
);
51 virtual uint32_t handleNextCE32(UChar32
&c
, UErrorCode
&errorCode
);
53 virtual UChar
handleGetTrailSurrogate();
55 virtual void forwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
57 virtual void backwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
63 * Incrementally checks the input text for FCD and normalizes where necessary.
65 class U_I18N_API FCDUIterCollationIterator
: public UIterCollationIterator
{
67 FCDUIterCollationIterator(const CollationData
*data
, UBool numeric
, UCharIterator
&ui
, int32_t startIndex
)
68 : UIterCollationIterator(data
, numeric
, ui
),
69 state(ITER_CHECK_FWD
), start(startIndex
),
70 nfcImpl(data
->nfcImpl
) {}
72 virtual ~FCDUIterCollationIterator();
74 virtual void resetToOffset(int32_t newOffset
);
76 virtual int32_t getOffset() const;
78 virtual UChar32
nextCodePoint(UErrorCode
&errorCode
);
80 virtual UChar32
previousCodePoint(UErrorCode
&errorCode
);
83 virtual uint32_t handleNextCE32(UChar32
&c
, UErrorCode
&errorCode
);
85 virtual UChar
handleGetTrailSurrogate();
87 virtual void forwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
89 virtual void backwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
93 * Switches to forward checking if possible.
95 void switchToForward();
98 * Extends the FCD text segment forward or normalizes around pos.
99 * @return TRUE if success
101 UBool
nextSegment(UErrorCode
&errorCode
);
104 * Switches to backward checking.
106 void switchToBackward();
109 * Extends the FCD text segment backward or normalizes around pos.
110 * @return TRUE if success
112 UBool
previousSegment(UErrorCode
&errorCode
);
114 UBool
normalize(const UnicodeString
&s
, UErrorCode
&errorCode
);
118 * The input text [start..(iter index)[ passes the FCD check.
119 * Moving forward checks incrementally.
120 * pos & limit are undefined.
124 * The input text [(iter index)..limit[ passes the FCD check.
125 * Moving backward checks incrementally.
126 * start & pos are undefined.
130 * The input text [start..limit[ passes the FCD check.
131 * pos tracks the current text index.
135 * The input text [start..limit[ failed the FCD check and was normalized.
136 * pos tracks the current index in the normalized string.
137 * The text iterator is at the limit index.
139 IN_NORM_ITER_AT_LIMIT
,
141 * The input text [start..limit[ failed the FCD check and was normalized.
142 * pos tracks the current index in the normalized string.
143 * The text iterator is at the start index.
145 IN_NORM_ITER_AT_START
154 const Normalizer2Impl
&nfcImpl
;
155 UnicodeString normalized
;
160 #endif // !UCONFIG_NO_COLLATION
161 #endif // __UITERCOLLATIONITERATOR_H__