2 *******************************************************************************
3 * Copyright (C) 2012-2014, 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 "normalizer2impl.h"
28 * UCharIterator-based collation element and character iterator.
29 * Handles normalized text inline, with length or NUL-terminated.
30 * Unnormalized text is handled by a subclass.
32 class U_I18N_API UIterCollationIterator
: public CollationIterator
{
34 UIterCollationIterator(const CollationData
*d
, UBool numeric
, UCharIterator
&ui
)
35 : CollationIterator(d
, numeric
), iter(ui
) {}
37 virtual ~UIterCollationIterator();
39 virtual void resetToOffset(int32_t newOffset
);
41 virtual int32_t getOffset() const;
43 virtual UChar32
nextCodePoint(UErrorCode
&errorCode
);
45 virtual UChar32
previousCodePoint(UErrorCode
&errorCode
);
48 virtual uint32_t handleNextCE32(UChar32
&c
, UErrorCode
&errorCode
);
50 virtual UChar
handleGetTrailSurrogate();
52 virtual void forwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
54 virtual void backwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
60 * Incrementally checks the input text for FCD and normalizes where necessary.
62 class U_I18N_API FCDUIterCollationIterator
: public UIterCollationIterator
{
64 FCDUIterCollationIterator(const CollationData
*data
, UBool numeric
, UCharIterator
&ui
, int32_t startIndex
)
65 : UIterCollationIterator(data
, numeric
, ui
),
66 state(ITER_CHECK_FWD
), start(startIndex
),
67 nfcImpl(data
->nfcImpl
) {}
69 virtual ~FCDUIterCollationIterator();
71 virtual void resetToOffset(int32_t newOffset
);
73 virtual int32_t getOffset() const;
75 virtual UChar32
nextCodePoint(UErrorCode
&errorCode
);
77 virtual UChar32
previousCodePoint(UErrorCode
&errorCode
);
80 virtual uint32_t handleNextCE32(UChar32
&c
, UErrorCode
&errorCode
);
82 virtual UChar
handleGetTrailSurrogate();
84 virtual void forwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
86 virtual void backwardNumCodePoints(int32_t num
, UErrorCode
&errorCode
);
90 * Switches to forward checking if possible.
92 void switchToForward();
95 * Extends the FCD text segment forward or normalizes around pos.
96 * @return TRUE if success
98 UBool
nextSegment(UErrorCode
&errorCode
);
101 * Switches to backward checking.
103 void switchToBackward();
106 * Extends the FCD text segment backward or normalizes around pos.
107 * @return TRUE if success
109 UBool
previousSegment(UErrorCode
&errorCode
);
111 UBool
normalize(const UnicodeString
&s
, UErrorCode
&errorCode
);
115 * The input text [start..(iter index)[ passes the FCD check.
116 * Moving forward checks incrementally.
117 * pos & limit are undefined.
121 * The input text [(iter index)..limit[ passes the FCD check.
122 * Moving backward checks incrementally.
123 * start & pos are undefined.
127 * The input text [start..limit[ passes the FCD check.
128 * pos tracks the current text index.
132 * The input text [start..limit[ failed the FCD check and was normalized.
133 * pos tracks the current index in the normalized string.
134 * The text iterator is at the limit index.
136 IN_NORM_ITER_AT_LIMIT
,
138 * The input text [start..limit[ failed the FCD check and was normalized.
139 * pos tracks the current index in the normalized string.
140 * The text iterator is at the start index.
142 IN_NORM_ITER_AT_START
151 const Normalizer2Impl
&nfcImpl
;
152 UnicodeString normalized
;
157 #endif // !UCONFIG_NO_COLLATION
158 #endif // __UITERCOLLATIONITERATOR_H__