]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/unicode/normlzr.h
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / common / unicode / normlzr.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/*
4 ********************************************************************
374ca955 5 * COPYRIGHT:
2ca993e8 6 * Copyright (c) 1996-2015, International Business Machines Corporation and
b75a7d8f
A
7 * others. All Rights Reserved.
8 ********************************************************************
9 */
10
11#ifndef NORMLZR_H
12#define NORMLZR_H
13
14#include "unicode/utypes.h"
15
73c04bcf
A
16/**
17 * \file
18 * \brief C++ API: Unicode Normalization
19 */
20
b75a7d8f
A
21#if !UCONFIG_NO_NORMALIZATION
22
b75a7d8f 23#include "unicode/chariter.h"
729e4ab9
A
24#include "unicode/normalizer2.h"
25#include "unicode/unistr.h"
b75a7d8f 26#include "unicode/unorm.h"
729e4ab9 27#include "unicode/uobject.h"
b75a7d8f 28
f3c0d7a5 29#if U_SHOW_CPLUSPLUS_API
b75a7d8f
A
30U_NAMESPACE_BEGIN
31/**
2ca993e8 32 * Old Unicode normalization API.
b75a7d8f 33 *
2ca993e8 34 * This API has been replaced by the Normalizer2 class and is only available
729e4ab9
A
35 * for backward compatibility. This class simply delegates to the Normalizer2 class.
36 * There is one exception: The new API does not provide a replacement for Normalizer::compare().
37 *
2ca993e8
A
38 * The Normalizer class supports the standard normalization forms described in
39 * <a href="http://www.unicode.org/unicode/reports/tr15/" target="unicode">
40 * Unicode Standard Annex #15: Unicode Normalization Forms</a>.
41 *
b75a7d8f
A
42 * The Normalizer class consists of two parts:
43 * - static functions that normalize strings or test if strings are normalized
44 * - a Normalizer object is an iterator that takes any kind of text and
45 * provides iteration over its normalized form
46 *
47 * The Normalizer class is not suitable for subclassing.
48 *
b75a7d8f
A
49 * For basic information about normalization forms and details about the C API
50 * please see the documentation in unorm.h.
51 *
52 * The iterator API with the Normalizer constructors and the non-static functions
729e4ab9 53 * use a CharacterIterator as input. It is possible to pass a string which
b75a7d8f
A
54 * is then internally wrapped in a CharacterIterator.
55 * The input text is not normalized all at once, but incrementally where needed
56 * (providing efficient random access).
57 * This allows to pass in a large text but spend only a small amount of time
58 * normalizing a small part of that text.
59 * However, if the entire text is normalized, then the iterator will be
60 * slower than normalizing the entire text at once and iterating over the result.
61 * A possible use of the Normalizer iterator is also to report an index into the
62 * original text that is close to where the normalized characters come from.
63 *
64 * <em>Important:</em> The iterator API was cleaned up significantly for ICU 2.0.
65 * The earlier implementation reported the getIndex() inconsistently,
66 * and previous() could not be used after setIndex(), next(), first(), and current().
67 *
68 * Normalizer allows to start normalizing from anywhere in the input text by
69 * calling setIndexOnly(), first(), or last().
70 * Without calling any of these, the iterator will start at the beginning of the text.
71 *
72 * At any time, next() returns the next normalized code point (UChar32),
73 * with post-increment semantics (like CharacterIterator::next32PostInc()).
74 * previous() returns the previous normalized code point (UChar32),
75 * with pre-decrement semantics (like CharacterIterator::previous32()).
76 *
77 * current() returns the current code point
78 * (respectively the one at the newly set index) without moving
79 * the getIndex(). Note that if the text at the current position
80 * needs to be normalized, then these functions will do that.
81 * (This is why current() is not const.)
82 * It is more efficient to call setIndexOnly() instead, which does not
83 * normalize.
84 *
85 * getIndex() always refers to the position in the input text where the normalized
86 * code points are returned from. It does not always change with each returned
87 * code point.
88 * The code point that is returned from any of the functions
89 * corresponds to text at or after getIndex(), according to the
90 * function's iteration semantics (post-increment or pre-decrement).
91 *
92 * next() returns a code point from at or after the getIndex()
93 * from before the next() call. After the next() call, the getIndex()
94 * might have moved to where the next code point will be returned from
95 * (from a next() or current() call).
96 * This is semantically equivalent to array access with array[index++]
97 * (post-increment semantics).
98 *
99 * previous() returns a code point from at or after the getIndex()
100 * from after the previous() call.
101 * This is semantically equivalent to array access with array[--index]
102 * (pre-decrement semantics).
103 *
104 * Internally, the Normalizer iterator normalizes a small piece of text
105 * starting at the getIndex() and ending at a following "safe" index.
106 * The normalized results is stored in an internal string buffer, and
107 * the code points are iterated from there.
108 * With multiple iteration calls, this is repeated until the next piece
109 * of text needs to be normalized, and the getIndex() needs to be moved.
110 *
111 * The following "safe" index, the internal buffer, and the secondary
112 * iteration index into that buffer are not exposed on the API.
113 * This also means that it is currently not practical to return to
114 * a particular, arbitrary position in the text because one would need to
115 * know, and be able to set, in addition to the getIndex(), at least also the
116 * current index into the internal buffer.
117 * It is currently only possible to observe when getIndex() changes
118 * (with careful consideration of the iteration semantics),
119 * at which time the internal index will be 0.
120 * For example, if getIndex() is different after next() than before it,
121 * then the internal index is 0 and one can return to this getIndex()
122 * later with setIndexOnly().
123 *
729e4ab9
A
124 * Note: While the setIndex() and getIndex() refer to indices in the
125 * underlying Unicode input text, the next() and previous() methods
126 * iterate through characters in the normalized output.
127 * This means that there is not necessarily a one-to-one correspondence
128 * between characters returned by next() and previous() and the indices
129 * passed to and returned from setIndex() and getIndex().
130 * It is for this reason that Normalizer does not implement the CharacterIterator interface.
131 *
b75a7d8f
A
132 * @author Laura Werner, Mark Davis, Markus Scherer
133 * @stable ICU 2.0
134 */
135class U_COMMON_API Normalizer : public UObject {
136public:
2ca993e8 137#ifndef U_HIDE_DEPRECATED_API
b75a7d8f
A
138 /**
139 * If DONE is returned from an iteration function that returns a code point,
140 * then there are no more normalization results available.
2ca993e8 141 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
142 */
143 enum {
144 DONE=0xffff
145 };
146
147 // Constructors
148
149 /**
150 * Creates a new <code>Normalizer</code> object for iterating over the
151 * normalized form of a given string.
152 * <p>
153 * @param str The string to be normalized. The normalization
154 * will start at the beginning of the string.
155 *
156 * @param mode The normalization mode.
2ca993e8 157 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
158 */
159 Normalizer(const UnicodeString& str, UNormalizationMode mode);
374ca955 160
b75a7d8f
A
161 /**
162 * Creates a new <code>Normalizer</code> object for iterating over the
163 * normalized form of a given string.
164 * <p>
165 * @param str The string to be normalized. The normalization
166 * will start at the beginning of the string.
167 *
168 * @param length Length of the string, or -1 if NUL-terminated.
169 * @param mode The normalization mode.
2ca993e8 170 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 171 */
f3c0d7a5 172 Normalizer(ConstChar16Ptr str, int32_t length, UNormalizationMode mode);
b75a7d8f
A
173
174 /**
175 * Creates a new <code>Normalizer</code> object for iterating over the
176 * normalized form of the given text.
177 * <p>
178 * @param iter The input text to be normalized. The normalization
179 * will start at the beginning of the string.
180 *
181 * @param mode The normalization mode.
2ca993e8 182 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
183 */
184 Normalizer(const CharacterIterator& iter, UNormalizationMode mode);
f3c0d7a5 185#endif /* U_HIDE_DEPRECATED_API */
b75a7d8f
A
186
187 /**
188 * Copy constructor.
189 * @param copy The object to be copied.
2ca993e8 190 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
191 */
192 Normalizer(const Normalizer& copy);
193
194 /**
195 * Destructor
2ca993e8 196 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 197 */
374ca955 198 virtual ~Normalizer();
b75a7d8f
A
199
200
201 //-------------------------------------------------------------------------
202 // Static utility methods
203 //-------------------------------------------------------------------------
204
2ca993e8 205#ifndef U_HIDE_DEPRECATED_API
b75a7d8f
A
206 /**
207 * Normalizes a <code>UnicodeString</code> according to the specified normalization mode.
208 * This is a wrapper for unorm_normalize(), using UnicodeString's.
209 *
210 * The <code>options</code> parameter specifies which optional
211 * <code>Normalizer</code> features are to be enabled for this operation.
212 *
213 * @param source the input string to be normalized.
214 * @param mode the normalization mode
215 * @param options the optional features to be enabled (0 for no options)
216 * @param result The normalized string (on output).
217 * @param status The error code.
2ca993e8 218 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 219 */
374ca955 220 static void U_EXPORT2 normalize(const UnicodeString& source,
b75a7d8f
A
221 UNormalizationMode mode, int32_t options,
222 UnicodeString& result,
223 UErrorCode &status);
224
225 /**
226 * Compose a <code>UnicodeString</code>.
227 * This is equivalent to normalize() with mode UNORM_NFC or UNORM_NFKC.
228 * This is a wrapper for unorm_normalize(), using UnicodeString's.
229 *
230 * The <code>options</code> parameter specifies which optional
231 * <code>Normalizer</code> features are to be enabled for this operation.
232 *
233 * @param source the string to be composed.
234 * @param compat Perform compatibility decomposition before composition.
235 * If this argument is <code>FALSE</code>, only canonical
236 * decomposition will be performed.
237 * @param options the optional features to be enabled (0 for no options)
238 * @param result The composed string (on output).
239 * @param status The error code.
2ca993e8 240 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 241 */
374ca955 242 static void U_EXPORT2 compose(const UnicodeString& source,
b75a7d8f
A
243 UBool compat, int32_t options,
244 UnicodeString& result,
245 UErrorCode &status);
246
247 /**
248 * Static method to decompose a <code>UnicodeString</code>.
249 * This is equivalent to normalize() with mode UNORM_NFD or UNORM_NFKD.
250 * This is a wrapper for unorm_normalize(), using UnicodeString's.
251 *
252 * The <code>options</code> parameter specifies which optional
253 * <code>Normalizer</code> features are to be enabled for this operation.
254 *
255 * @param source the string to be decomposed.
256 * @param compat Perform compatibility decomposition.
257 * If this argument is <code>FALSE</code>, only canonical
258 * decomposition will be performed.
259 * @param options the optional features to be enabled (0 for no options)
260 * @param result The decomposed string (on output).
261 * @param status The error code.
2ca993e8 262 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 263 */
374ca955 264 static void U_EXPORT2 decompose(const UnicodeString& source,
b75a7d8f
A
265 UBool compat, int32_t options,
266 UnicodeString& result,
267 UErrorCode &status);
268
269 /**
374ca955 270 * Performing quick check on a string, to quickly determine if the string is
b75a7d8f
A
271 * in a particular normalization format.
272 * This is a wrapper for unorm_quickCheck(), using a UnicodeString.
273 *
274 * Three types of result can be returned UNORM_YES, UNORM_NO or
275 * UNORM_MAYBE. Result UNORM_YES indicates that the argument
276 * string is in the desired normalized format, UNORM_NO determines that
374ca955
A
277 * argument string is not in the desired normalized format. A
278 * UNORM_MAYBE result indicates that a more thorough check is required,
279 * the user may have to put the string in its normalized form and compare the
b75a7d8f
A
280 * results.
281 * @param source string for determining if it is in a normalized format
282 * @param mode normalization format
283 * @param status A reference to a UErrorCode to receive any errors
284 * @return UNORM_YES, UNORM_NO or UNORM_MAYBE
285 *
286 * @see isNormalized
2ca993e8 287 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
288 */
289 static inline UNormalizationCheckResult
290 quickCheck(const UnicodeString &source, UNormalizationMode mode, UErrorCode &status);
291
292 /**
293 * Performing quick check on a string; same as the other version of quickCheck
294 * but takes an extra options parameter like most normalization functions.
295 *
296 * @param source string for determining if it is in a normalized format
297 * @param mode normalization format
298 * @param options the optional features to be enabled (0 for no options)
299 * @param status A reference to a UErrorCode to receive any errors
300 * @return UNORM_YES, UNORM_NO or UNORM_MAYBE
301 *
302 * @see isNormalized
2ca993e8 303 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 304 */
729e4ab9 305 static UNormalizationCheckResult
b75a7d8f
A
306 quickCheck(const UnicodeString &source, UNormalizationMode mode, int32_t options, UErrorCode &status);
307
308 /**
309 * Test if a string is in a given normalization form.
310 * This is semantically equivalent to source.equals(normalize(source, mode)) .
311 *
312 * Unlike unorm_quickCheck(), this function returns a definitive result,
313 * never a "maybe".
314 * For NFD, NFKD, and FCD, both functions work exactly the same.
315 * For NFC and NFKC where quickCheck may return "maybe", this function will
316 * perform further tests to arrive at a TRUE/FALSE result.
317 *
318 * @param src String that is to be tested if it is in a normalization format.
319 * @param mode Which normalization form to test for.
320 * @param errorCode ICU error code in/out parameter.
321 * Must fulfill U_SUCCESS before the function call.
322 * @return Boolean value indicating whether the source string is in the
323 * "mode" normalization form.
324 *
325 * @see quickCheck
2ca993e8 326 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
327 */
328 static inline UBool
329 isNormalized(const UnicodeString &src, UNormalizationMode mode, UErrorCode &errorCode);
330
331 /**
332 * Test if a string is in a given normalization form; same as the other version of isNormalized
333 * but takes an extra options parameter like most normalization functions.
334 *
335 * @param src String that is to be tested if it is in a normalization format.
336 * @param mode Which normalization form to test for.
337 * @param options the optional features to be enabled (0 for no options)
338 * @param errorCode ICU error code in/out parameter.
339 * Must fulfill U_SUCCESS before the function call.
340 * @return Boolean value indicating whether the source string is in the
341 * "mode" normalization form.
342 *
343 * @see quickCheck
2ca993e8 344 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 345 */
729e4ab9 346 static UBool
b75a7d8f
A
347 isNormalized(const UnicodeString &src, UNormalizationMode mode, int32_t options, UErrorCode &errorCode);
348
349 /**
350 * Concatenate normalized strings, making sure that the result is normalized as well.
351 *
352 * If both the left and the right strings are in
353 * the normalization form according to "mode/options",
354 * then the result will be
355 *
356 * \code
357 * dest=normalize(left+right, mode, options)
358 * \endcode
359 *
360 * For details see unorm_concatenate in unorm.h.
361 *
362 * @param left Left source string.
363 * @param right Right source string.
364 * @param result The output string.
365 * @param mode The normalization mode.
366 * @param options A bit set of normalization options.
367 * @param errorCode ICU error code in/out parameter.
368 * Must fulfill U_SUCCESS before the function call.
369 * @return result
370 *
371 * @see unorm_concatenate
372 * @see normalize
373 * @see unorm_next
374 * @see unorm_previous
375 *
2ca993e8 376 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
377 */
378 static UnicodeString &
4388f060 379 U_EXPORT2 concatenate(const UnicodeString &left, const UnicodeString &right,
b75a7d8f
A
380 UnicodeString &result,
381 UNormalizationMode mode, int32_t options,
382 UErrorCode &errorCode);
2ca993e8 383#endif /* U_HIDE_DEPRECATED_API */
b75a7d8f
A
384
385 /**
386 * Compare two strings for canonical equivalence.
387 * Further options include case-insensitive comparison and
388 * code point order (as opposed to code unit order).
389 *
390 * Canonical equivalence between two strings is defined as their normalized
391 * forms (NFD or NFC) being identical.
392 * This function compares strings incrementally instead of normalizing
393 * (and optionally case-folding) both strings entirely,
394 * improving performance significantly.
395 *
396 * Bulk normalization is only necessary if the strings do not fulfill the FCD
397 * conditions. Only in this case, and only if the strings are relatively long,
398 * is memory allocated temporarily.
399 * For FCD strings and short non-FCD strings there is no memory allocation.
400 *
401 * Semantically, this is equivalent to
402 * strcmp[CodePointOrder](NFD(foldCase(s1)), NFD(foldCase(s2)))
403 * where code point order and foldCase are all optional.
404 *
405 * UAX 21 2.5 Caseless Matching specifies that for a canonical caseless match
406 * the case folding must be performed first, then the normalization.
407 *
408 * @param s1 First source string.
409 * @param s2 Second source string.
410 *
411 * @param options A bit set of options:
412 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
413 * Case-sensitive comparison in code unit order, and the input strings
414 * are quick-checked for FCD.
415 *
416 * - UNORM_INPUT_IS_FCD
417 * Set if the caller knows that both s1 and s2 fulfill the FCD conditions.
418 * If not set, the function will quickCheck for FCD
419 * and normalize if necessary.
420 *
421 * - U_COMPARE_CODE_POINT_ORDER
422 * Set to choose code point order instead of code unit order
423 * (see u_strCompare for details).
424 *
425 * - U_COMPARE_IGNORE_CASE
426 * Set to compare strings case-insensitively using case folding,
427 * instead of case-sensitively.
428 * If set, then the following case folding options are used.
429 *
430 * - Options as used with case-insensitive comparisons, currently:
431 *
432 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
433 * (see u_strCaseCompare for details)
434 *
435 * - regular normalization options shifted left by UNORM_COMPARE_NORM_OPTIONS_SHIFT
436 *
437 * @param errorCode ICU error code in/out parameter.
438 * Must fulfill U_SUCCESS before the function call.
439 * @return <0 or 0 or >0 as usual for string comparisons
440 *
441 * @see unorm_compare
442 * @see normalize
443 * @see UNORM_FCD
444 * @see u_strCompare
445 * @see u_strCaseCompare
446 *
374ca955 447 * @stable ICU 2.2
b75a7d8f
A
448 */
449 static inline int32_t
450 compare(const UnicodeString &s1, const UnicodeString &s2,
451 uint32_t options,
452 UErrorCode &errorCode);
453
2ca993e8 454#ifndef U_HIDE_DEPRECATED_API
b75a7d8f
A
455 //-------------------------------------------------------------------------
456 // Iteration API
457 //-------------------------------------------------------------------------
374ca955 458
b75a7d8f
A
459 /**
460 * Return the current character in the normalized text.
461 * current() may need to normalize some text at getIndex().
462 * The getIndex() is not changed.
463 *
464 * @return the current normalized code point
2ca993e8 465 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
466 */
467 UChar32 current(void);
468
469 /**
470 * Return the first character in the normalized text.
471 * This is equivalent to setIndexOnly(startIndex()) followed by next().
472 * (Post-increment semantics.)
473 *
474 * @return the first normalized code point
2ca993e8 475 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
476 */
477 UChar32 first(void);
478
479 /**
480 * Return the last character in the normalized text.
481 * This is equivalent to setIndexOnly(endIndex()) followed by previous().
482 * (Pre-decrement semantics.)
483 *
484 * @return the last normalized code point
2ca993e8 485 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
486 */
487 UChar32 last(void);
488
489 /**
490 * Return the next character in the normalized text.
491 * (Post-increment semantics.)
492 * If the end of the text has already been reached, DONE is returned.
493 * The DONE value could be confused with a U+FFFF non-character code point
494 * in the text. If this is possible, you can test getIndex()<endIndex()
495 * before calling next(), or (getIndex()<endIndex() || last()!=DONE)
496 * after calling next(). (Calling last() will change the iterator state!)
497 *
498 * The C API unorm_next() is more efficient and does not have this ambiguity.
499 *
500 * @return the next normalized code point
2ca993e8 501 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
502 */
503 UChar32 next(void);
504
505 /**
506 * Return the previous character in the normalized text and decrement.
507 * (Pre-decrement semantics.)
508 * If the beginning of the text has already been reached, DONE is returned.
509 * The DONE value could be confused with a U+FFFF non-character code point
510 * in the text. If this is possible, you can test
511 * (getIndex()>startIndex() || first()!=DONE). (Calling first() will change
512 * the iterator state!)
513 *
514 * The C API unorm_previous() is more efficient and does not have this ambiguity.
515 *
516 * @return the previous normalized code point
2ca993e8 517 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
518 */
519 UChar32 previous(void);
520
521 /**
522 * Set the iteration position in the input text that is being normalized,
523 * without any immediate normalization.
524 * After setIndexOnly(), getIndex() will return the same index that is
525 * specified here.
526 *
527 * @param index the desired index in the input text.
2ca993e8 528 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
529 */
530 void setIndexOnly(int32_t index);
531
532 /**
533 * Reset the index to the beginning of the text.
534 * This is equivalent to setIndexOnly(startIndex)).
2ca993e8 535 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
536 */
537 void reset(void);
538
539 /**
540 * Retrieve the current iteration position in the input text that is
541 * being normalized.
542 *
543 * A following call to next() will return a normalized code point from
544 * the input text at or after this index.
545 *
546 * After a call to previous(), getIndex() will point at or before the
547 * position in the input text where the normalized code point
548 * was returned from with previous().
549 *
550 * @return the current index in the input text
2ca993e8 551 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
552 */
553 int32_t getIndex(void) const;
554
555 /**
556 * Retrieve the index of the start of the input text. This is the begin index
557 * of the <code>CharacterIterator</code> or the start (i.e. index 0) of the string
558 * over which this <code>Normalizer</code> is iterating.
559 *
560 * @return the smallest index in the input text where the Normalizer operates
2ca993e8 561 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
562 */
563 int32_t startIndex(void) const;
564
565 /**
566 * Retrieve the index of the end of the input text. This is the end index
567 * of the <code>CharacterIterator</code> or the length of the string
568 * over which this <code>Normalizer</code> is iterating.
569 * This end index is exclusive, i.e., the Normalizer operates only on characters
570 * before this index.
571 *
572 * @return the first index in the input text where the Normalizer does not operate
2ca993e8 573 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
574 */
575 int32_t endIndex(void) const;
576
577 /**
578 * Returns TRUE when both iterators refer to the same character in the same
579 * input text.
580 *
581 * @param that a Normalizer object to compare this one to
582 * @return comparison result
2ca993e8 583 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
584 */
585 UBool operator==(const Normalizer& that) const;
586
587 /**
588 * Returns FALSE when both iterators refer to the same character in the same
589 * input text.
590 *
591 * @param that a Normalizer object to compare this one to
592 * @return comparison result
2ca993e8 593 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
594 */
595 inline UBool operator!=(const Normalizer& that) const;
596
597 /**
598 * Returns a pointer to a new Normalizer that is a clone of this one.
599 * The caller is responsible for deleting the new clone.
374ca955 600 * @return a pointer to a new Normalizer
2ca993e8 601 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
602 */
603 Normalizer* clone(void) const;
604
605 /**
606 * Generates a hash code for this iterator.
607 *
608 * @return the hash code
2ca993e8 609 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
610 */
611 int32_t hashCode(void) const;
612
613 //-------------------------------------------------------------------------
614 // Property access methods
615 //-------------------------------------------------------------------------
616
617 /**
618 * Set the normalization mode for this object.
619 * <p>
620 * <b>Note:</b>If the normalization mode is changed while iterating
374ca955 621 * over a string, calls to {@link #next() } and {@link #previous() } may
b75a7d8f
A
622 * return previously buffers characters in the old normalization mode
623 * until the iteration is able to re-sync at the next base character.
374ca955
A
624 * It is safest to call {@link #setIndexOnly }, {@link #reset() },
625 * {@link #setText }, {@link #first() },
626 * {@link #last() }, etc. after calling <code>setMode</code>.
b75a7d8f
A
627 * <p>
628 * @param newMode the new mode for this <code>Normalizer</code>.
629 * @see #getUMode
2ca993e8 630 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
631 */
632 void setMode(UNormalizationMode newMode);
633
634 /**
635 * Return the normalization mode for this object.
636 *
637 * This is an unusual name because there used to be a getMode() that
638 * returned a different type.
639 *
640 * @return the mode for this <code>Normalizer</code>
641 * @see #setMode
2ca993e8 642 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
643 */
644 UNormalizationMode getUMode(void) const;
645
646 /**
647 * Set options that affect this <code>Normalizer</code>'s operation.
648 * Options do not change the basic composition or decomposition operation
649 * that is being performed, but they control whether
650 * certain optional portions of the operation are done.
651 * Currently the only available option is obsolete.
652 *
653 * It is possible to specify multiple options that are all turned on or off.
654 *
655 * @param option the option(s) whose value is/are to be set.
656 * @param value the new setting for the option. Use <code>TRUE</code> to
657 * turn the option(s) on and <code>FALSE</code> to turn it/them off.
658 *
659 * @see #getOption
2ca993e8 660 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 661 */
374ca955 662 void setOption(int32_t option,
b75a7d8f
A
663 UBool value);
664
665 /**
666 * Determine whether an option is turned on or off.
667 * If multiple options are specified, then the result is TRUE if any
668 * of them are set.
669 * <p>
670 * @param option the option(s) that are to be checked
671 * @return TRUE if any of the option(s) are set
672 * @see #setOption
2ca993e8 673 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
674 */
675 UBool getOption(int32_t option) const;
676
677 /**
678 * Set the input text over which this <code>Normalizer</code> will iterate.
679 * The iteration position is set to the beginning.
680 *
681 * @param newText a string that replaces the current input text
682 * @param status a UErrorCode
2ca993e8 683 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 684 */
374ca955 685 void setText(const UnicodeString& newText,
b75a7d8f
A
686 UErrorCode &status);
687
688 /**
689 * Set the input text over which this <code>Normalizer</code> will iterate.
690 * The iteration position is set to the beginning.
691 *
692 * @param newText a CharacterIterator object that replaces the current input text
693 * @param status a UErrorCode
2ca993e8 694 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 695 */
374ca955 696 void setText(const CharacterIterator& newText,
b75a7d8f
A
697 UErrorCode &status);
698
699 /**
700 * Set the input text over which this <code>Normalizer</code> will iterate.
701 * The iteration position is set to the beginning.
702 *
703 * @param newText a string that replaces the current input text
704 * @param length the length of the string, or -1 if NUL-terminated
705 * @param status a UErrorCode
2ca993e8 706 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 707 */
f3c0d7a5 708 void setText(ConstChar16Ptr newText,
b75a7d8f
A
709 int32_t length,
710 UErrorCode &status);
711 /**
712 * Copies the input text into the UnicodeString argument.
713 *
714 * @param result Receives a copy of the text under iteration.
2ca993e8 715 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f
A
716 */
717 void getText(UnicodeString& result);
718
719 /**
374ca955
A
720 * ICU "poor man's RTTI", returns a UClassID for this class.
721 * @returns a UClassID for this class.
2ca993e8 722 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 723 */
374ca955 724 static UClassID U_EXPORT2 getStaticClassID();
2ca993e8 725#endif /* U_HIDE_DEPRECATED_API */
b75a7d8f
A
726
727 /**
374ca955
A
728 * ICU "poor man's RTTI", returns a UClassID for the actual class.
729 * @return a UClassID for the actual class.
2ca993e8 730 * @deprecated ICU 56 Use Normalizer2 instead.
b75a7d8f 731 */
374ca955 732 virtual UClassID getDynamicClassID() const;
b75a7d8f
A
733
734private:
735 //-------------------------------------------------------------------------
736 // Private functions
737 //-------------------------------------------------------------------------
738
739 Normalizer(); // default constructor not implemented
740 Normalizer &operator=(const Normalizer &that); // assignment operator not implemented
741
742 // Private utility methods for iteration
743 // For documentation, see the source code
744 UBool nextNormalize();
745 UBool previousNormalize();
746
729e4ab9 747 void init();
b75a7d8f
A
748 void clearBuffer(void);
749
750 //-------------------------------------------------------------------------
751 // Private data
752 //-------------------------------------------------------------------------
753
729e4ab9
A
754 FilteredNormalizer2*fFilteredNorm2; // owned if not NULL
755 const Normalizer2 *fNorm2; // not owned; may be equal to fFilteredNorm2
f3c0d7a5 756 UNormalizationMode fUMode; // deprecated
b75a7d8f
A
757 int32_t fOptions;
758
759 // The input text and our position in it
729e4ab9 760 CharacterIterator *text;
b75a7d8f
A
761
762 // The normalization buffer is the result of normalization
763 // of the source in [currentIndex..nextIndex[ .
764 int32_t currentIndex, nextIndex;
765
766 // A buffer for holding intermediate results
767 UnicodeString buffer;
768 int32_t bufferPos;
b75a7d8f
A
769};
770
771//-------------------------------------------------------------------------
772// Inline implementations
773//-------------------------------------------------------------------------
774
2ca993e8 775#ifndef U_HIDE_DEPRECATED_API
b75a7d8f
A
776inline UBool
777Normalizer::operator!= (const Normalizer& other) const
778{ return ! operator==(other); }
779
780inline UNormalizationCheckResult
781Normalizer::quickCheck(const UnicodeString& source,
374ca955 782 UNormalizationMode mode,
b75a7d8f 783 UErrorCode &status) {
729e4ab9 784 return quickCheck(source, mode, 0, status);
b75a7d8f
A
785}
786
787inline UBool
788Normalizer::isNormalized(const UnicodeString& source,
374ca955 789 UNormalizationMode mode,
b75a7d8f 790 UErrorCode &status) {
729e4ab9 791 return isNormalized(source, mode, 0, status);
b75a7d8f 792}
2ca993e8 793#endif /* U_HIDE_DEPRECATED_API */
b75a7d8f
A
794
795inline int32_t
796Normalizer::compare(const UnicodeString &s1, const UnicodeString &s2,
797 uint32_t options,
798 UErrorCode &errorCode) {
799 // all argument checking is done in unorm_compare
f3c0d7a5
A
800 return unorm_compare(toUCharPtr(s1.getBuffer()), s1.length(),
801 toUCharPtr(s2.getBuffer()), s2.length(),
b75a7d8f
A
802 options,
803 &errorCode);
804}
805
806U_NAMESPACE_END
f3c0d7a5 807#endif // U_SHOW_CPLUSPLUS_API
b75a7d8f
A
808
809#endif /* #if !UCONFIG_NO_NORMALIZATION */
810
811#endif // NORMLZR_H