xref: /aosp_15_r20/external/icu/libandroidicu/include/unicode/unorm.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (c) 1996-2016, International Business Machines Corporation
6*0e209d39SAndroid Build Coastguard Worker *               and others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker * File unorm.h
9*0e209d39SAndroid Build Coastguard Worker *
10*0e209d39SAndroid Build Coastguard Worker * Created by: Vladimir Weinstein 12052000
11*0e209d39SAndroid Build Coastguard Worker *
12*0e209d39SAndroid Build Coastguard Worker * Modification history :
13*0e209d39SAndroid Build Coastguard Worker *
14*0e209d39SAndroid Build Coastguard Worker * Date        Name        Description
15*0e209d39SAndroid Build Coastguard Worker * 02/01/01    synwee      Added normalization quickcheck enum and method.
16*0e209d39SAndroid Build Coastguard Worker */
17*0e209d39SAndroid Build Coastguard Worker #ifndef UNORM_H
18*0e209d39SAndroid Build Coastguard Worker #define UNORM_H
19*0e209d39SAndroid Build Coastguard Worker 
20*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
21*0e209d39SAndroid Build Coastguard Worker 
22*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_NORMALIZATION
23*0e209d39SAndroid Build Coastguard Worker 
24*0e209d39SAndroid Build Coastguard Worker #include "unicode/uiter.h"
25*0e209d39SAndroid Build Coastguard Worker #include "unicode/unorm2.h"
26*0e209d39SAndroid Build Coastguard Worker 
27*0e209d39SAndroid Build Coastguard Worker /**
28*0e209d39SAndroid Build Coastguard Worker  * \file
29*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Unicode Normalization
30*0e209d39SAndroid Build Coastguard Worker  *
31*0e209d39SAndroid Build Coastguard Worker  * Old Unicode normalization API.
32*0e209d39SAndroid Build Coastguard Worker  *
33*0e209d39SAndroid Build Coastguard Worker  * This API has been replaced by the unorm2.h API and is only available
34*0e209d39SAndroid Build Coastguard Worker  * for backward compatibility. The functions here simply delegate to the
35*0e209d39SAndroid Build Coastguard Worker  * unorm2.h functions, for example unorm2_getInstance() and unorm2_normalize().
36*0e209d39SAndroid Build Coastguard Worker  * There is one exception: The new API does not provide a replacement for unorm_compare().
37*0e209d39SAndroid Build Coastguard Worker  * Its declaration has been moved to unorm2.h.
38*0e209d39SAndroid Build Coastguard Worker  *
39*0e209d39SAndroid Build Coastguard Worker  * <code>unorm_normalize</code> transforms Unicode text into an equivalent composed or
40*0e209d39SAndroid Build Coastguard Worker  * decomposed form, allowing for easier sorting and searching of text.
41*0e209d39SAndroid Build Coastguard Worker  * <code>unorm_normalize</code> supports the standard normalization forms described in
42*0e209d39SAndroid Build Coastguard Worker  * <a href="http://www.unicode.org/unicode/reports/tr15/" target="unicode">
43*0e209d39SAndroid Build Coastguard Worker  * Unicode Standard Annex #15: Unicode Normalization Forms</a>.
44*0e209d39SAndroid Build Coastguard Worker  *
45*0e209d39SAndroid Build Coastguard Worker  * Characters with accents or other adornments can be encoded in
46*0e209d39SAndroid Build Coastguard Worker  * several different ways in Unicode.  For example, take the character A-acute.
47*0e209d39SAndroid Build Coastguard Worker  * In Unicode, this can be encoded as a single character (the
48*0e209d39SAndroid Build Coastguard Worker  * "composed" form):
49*0e209d39SAndroid Build Coastguard Worker  *
50*0e209d39SAndroid Build Coastguard Worker  * \code
51*0e209d39SAndroid Build Coastguard Worker  *      00C1    LATIN CAPITAL LETTER A WITH ACUTE
52*0e209d39SAndroid Build Coastguard Worker  * \endcode
53*0e209d39SAndroid Build Coastguard Worker  *
54*0e209d39SAndroid Build Coastguard Worker  * or as two separate characters (the "decomposed" form):
55*0e209d39SAndroid Build Coastguard Worker  *
56*0e209d39SAndroid Build Coastguard Worker  * \code
57*0e209d39SAndroid Build Coastguard Worker  *      0041    LATIN CAPITAL LETTER A
58*0e209d39SAndroid Build Coastguard Worker  *      0301    COMBINING ACUTE ACCENT
59*0e209d39SAndroid Build Coastguard Worker  * \endcode
60*0e209d39SAndroid Build Coastguard Worker  *
61*0e209d39SAndroid Build Coastguard Worker  * To a user of your program, however, both of these sequences should be
62*0e209d39SAndroid Build Coastguard Worker  * treated as the same "user-level" character "A with acute accent".  When you are searching or
63*0e209d39SAndroid Build Coastguard Worker  * comparing text, you must ensure that these two sequences are treated
64*0e209d39SAndroid Build Coastguard Worker  * equivalently.  In addition, you must handle characters with more than one
65*0e209d39SAndroid Build Coastguard Worker  * accent.  Sometimes the order of a character's combining accents is
66*0e209d39SAndroid Build Coastguard Worker  * significant, while in other cases accent sequences in different orders are
67*0e209d39SAndroid Build Coastguard Worker  * really equivalent.
68*0e209d39SAndroid Build Coastguard Worker  *
69*0e209d39SAndroid Build Coastguard Worker  * Similarly, the string "ffi" can be encoded as three separate letters:
70*0e209d39SAndroid Build Coastguard Worker  *
71*0e209d39SAndroid Build Coastguard Worker  * \code
72*0e209d39SAndroid Build Coastguard Worker  *      0066    LATIN SMALL LETTER F
73*0e209d39SAndroid Build Coastguard Worker  *      0066    LATIN SMALL LETTER F
74*0e209d39SAndroid Build Coastguard Worker  *      0069    LATIN SMALL LETTER I
75*0e209d39SAndroid Build Coastguard Worker  * \endcode
76*0e209d39SAndroid Build Coastguard Worker  *
77*0e209d39SAndroid Build Coastguard Worker  * or as the single character
78*0e209d39SAndroid Build Coastguard Worker  *
79*0e209d39SAndroid Build Coastguard Worker  * \code
80*0e209d39SAndroid Build Coastguard Worker  *      FB03    LATIN SMALL LIGATURE FFI
81*0e209d39SAndroid Build Coastguard Worker  * \endcode
82*0e209d39SAndroid Build Coastguard Worker  *
83*0e209d39SAndroid Build Coastguard Worker  * The ffi ligature is not a distinct semantic character, and strictly speaking
84*0e209d39SAndroid Build Coastguard Worker  * it shouldn't be in Unicode at all, but it was included for compatibility
85*0e209d39SAndroid Build Coastguard Worker  * with existing character sets that already provided it.  The Unicode standard
86*0e209d39SAndroid Build Coastguard Worker  * identifies such characters by giving them "compatibility" decompositions
87*0e209d39SAndroid Build Coastguard Worker  * into the corresponding semantic characters.  When sorting and searching, you
88*0e209d39SAndroid Build Coastguard Worker  * will often want to use these mappings.
89*0e209d39SAndroid Build Coastguard Worker  *
90*0e209d39SAndroid Build Coastguard Worker  * <code>unorm_normalize</code> helps solve these problems by transforming text into the
91*0e209d39SAndroid Build Coastguard Worker  * canonical composed and decomposed forms as shown in the first example above.
92*0e209d39SAndroid Build Coastguard Worker  * In addition, you can have it perform compatibility decompositions so that
93*0e209d39SAndroid Build Coastguard Worker  * you can treat compatibility characters the same as their equivalents.
94*0e209d39SAndroid Build Coastguard Worker  * Finally, <code>unorm_normalize</code> rearranges accents into the proper canonical
95*0e209d39SAndroid Build Coastguard Worker  * order, so that you do not have to worry about accent rearrangement on your
96*0e209d39SAndroid Build Coastguard Worker  * own.
97*0e209d39SAndroid Build Coastguard Worker  *
98*0e209d39SAndroid Build Coastguard Worker  * Form FCD, "Fast C or D", is also designed for collation.
99*0e209d39SAndroid Build Coastguard Worker  * It allows to work on strings that are not necessarily normalized
100*0e209d39SAndroid Build Coastguard Worker  * with an algorithm (like in collation) that works under "canonical closure", i.e., it treats precomposed
101*0e209d39SAndroid Build Coastguard Worker  * characters and their decomposed equivalents the same.
102*0e209d39SAndroid Build Coastguard Worker  *
103*0e209d39SAndroid Build Coastguard Worker  * It is not a normalization form because it does not provide for uniqueness of representation. Multiple strings
104*0e209d39SAndroid Build Coastguard Worker  * may be canonically equivalent (their NFDs are identical) and may all conform to FCD without being identical
105*0e209d39SAndroid Build Coastguard Worker  * themselves.
106*0e209d39SAndroid Build Coastguard Worker  *
107*0e209d39SAndroid Build Coastguard Worker  * The form is defined such that the "raw decomposition", the recursive canonical decomposition of each character,
108*0e209d39SAndroid Build Coastguard Worker  * results in a string that is canonically ordered. This means that precomposed characters are allowed for as long
109*0e209d39SAndroid Build Coastguard Worker  * as their decompositions do not need canonical reordering.
110*0e209d39SAndroid Build Coastguard Worker  *
111*0e209d39SAndroid Build Coastguard Worker  * Its advantage for a process like collation is that all NFD and most NFC texts - and many unnormalized texts -
112*0e209d39SAndroid Build Coastguard Worker  * already conform to FCD and do not need to be normalized (NFD) for such a process. The FCD quick check will
113*0e209d39SAndroid Build Coastguard Worker  * return UNORM_YES for most strings in practice.
114*0e209d39SAndroid Build Coastguard Worker  *
115*0e209d39SAndroid Build Coastguard Worker  * unorm_normalize(UNORM_FCD) may be implemented with UNORM_NFD.
116*0e209d39SAndroid Build Coastguard Worker  *
117*0e209d39SAndroid Build Coastguard Worker  * For more details on FCD see the collation design document:
118*0e209d39SAndroid Build Coastguard Worker  * https://htmlpreview.github.io/?https://github.com/unicode-org/icu-docs/blob/main/design/collation/ICU_collation_design.htm
119*0e209d39SAndroid Build Coastguard Worker  *
120*0e209d39SAndroid Build Coastguard Worker  * ICU collation performs either NFD or FCD normalization automatically if normalization
121*0e209d39SAndroid Build Coastguard Worker  * is turned on for the collator object.
122*0e209d39SAndroid Build Coastguard Worker  * Beyond collation and string search, normalized strings may be useful for string equivalence comparisons,
123*0e209d39SAndroid Build Coastguard Worker  * transliteration/transcription, unique representations, etc.
124*0e209d39SAndroid Build Coastguard Worker  *
125*0e209d39SAndroid Build Coastguard Worker  * The W3C generally recommends to exchange texts in NFC.
126*0e209d39SAndroid Build Coastguard Worker  * Note also that most legacy character encodings use only precomposed forms and often do not
127*0e209d39SAndroid Build Coastguard Worker  * encode any combining marks by themselves. For conversion to such character encodings the
128*0e209d39SAndroid Build Coastguard Worker  * Unicode text needs to be normalized to NFC.
129*0e209d39SAndroid Build Coastguard Worker  * For more usage examples, see the Unicode Standard Annex.
130*0e209d39SAndroid Build Coastguard Worker  */
131*0e209d39SAndroid Build Coastguard Worker 
132*0e209d39SAndroid Build Coastguard Worker // Do not conditionalize the following enum with #ifndef U_HIDE_DEPRECATED_API,
133*0e209d39SAndroid Build Coastguard Worker // it is needed for layout of Normalizer object.
134*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
135*0e209d39SAndroid Build Coastguard Worker 
136*0e209d39SAndroid Build Coastguard Worker /**
137*0e209d39SAndroid Build Coastguard Worker  * Constants for normalization modes.
138*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
139*0e209d39SAndroid Build Coastguard Worker  */
140*0e209d39SAndroid Build Coastguard Worker typedef enum {
141*0e209d39SAndroid Build Coastguard Worker   /** No decomposition/composition. @deprecated ICU 56 Use unorm2.h instead. */
142*0e209d39SAndroid Build Coastguard Worker   UNORM_NONE = 1,
143*0e209d39SAndroid Build Coastguard Worker   /** Canonical decomposition. @deprecated ICU 56 Use unorm2.h instead. */
144*0e209d39SAndroid Build Coastguard Worker   UNORM_NFD = 2,
145*0e209d39SAndroid Build Coastguard Worker   /** Compatibility decomposition. @deprecated ICU 56 Use unorm2.h instead. */
146*0e209d39SAndroid Build Coastguard Worker   UNORM_NFKD = 3,
147*0e209d39SAndroid Build Coastguard Worker   /** Canonical decomposition followed by canonical composition. @deprecated ICU 56 Use unorm2.h instead. */
148*0e209d39SAndroid Build Coastguard Worker   UNORM_NFC = 4,
149*0e209d39SAndroid Build Coastguard Worker   /** Default normalization. @deprecated ICU 56 Use unorm2.h instead. */
150*0e209d39SAndroid Build Coastguard Worker   UNORM_DEFAULT = UNORM_NFC,
151*0e209d39SAndroid Build Coastguard Worker   /** Compatibility decomposition followed by canonical composition. @deprecated ICU 56 Use unorm2.h instead. */
152*0e209d39SAndroid Build Coastguard Worker   UNORM_NFKC =5,
153*0e209d39SAndroid Build Coastguard Worker   /** "Fast C or D" form. @deprecated ICU 56 Use unorm2.h instead. */
154*0e209d39SAndroid Build Coastguard Worker   UNORM_FCD = 6,
155*0e209d39SAndroid Build Coastguard Worker 
156*0e209d39SAndroid Build Coastguard Worker   /** One more than the highest normalization mode constant. @deprecated ICU 56 Use unorm2.h instead. */
157*0e209d39SAndroid Build Coastguard Worker   UNORM_MODE_COUNT
158*0e209d39SAndroid Build Coastguard Worker } UNormalizationMode;
159*0e209d39SAndroid Build Coastguard Worker 
160*0e209d39SAndroid Build Coastguard Worker #endif  // U_FORCE_HIDE_DEPRECATED_API
161*0e209d39SAndroid Build Coastguard Worker 
162*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
163*0e209d39SAndroid Build Coastguard Worker 
164*0e209d39SAndroid Build Coastguard Worker /**
165*0e209d39SAndroid Build Coastguard Worker  * Constants for options flags for normalization.
166*0e209d39SAndroid Build Coastguard Worker  * Use 0 for default options,
167*0e209d39SAndroid Build Coastguard Worker  * including normalization according to the Unicode version
168*0e209d39SAndroid Build Coastguard Worker  * that is currently supported by ICU (see u_getUnicodeVersion).
169*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
170*0e209d39SAndroid Build Coastguard Worker  */
171*0e209d39SAndroid Build Coastguard Worker enum {
172*0e209d39SAndroid Build Coastguard Worker     /**
173*0e209d39SAndroid Build Coastguard Worker      * Options bit set value to select Unicode 3.2 normalization
174*0e209d39SAndroid Build Coastguard Worker      * (except NormalizationCorrections).
175*0e209d39SAndroid Build Coastguard Worker      * At most one Unicode version can be selected at a time.
176*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 56 Use unorm2.h instead.
177*0e209d39SAndroid Build Coastguard Worker      */
178*0e209d39SAndroid Build Coastguard Worker     UNORM_UNICODE_3_2=0x20
179*0e209d39SAndroid Build Coastguard Worker };
180*0e209d39SAndroid Build Coastguard Worker 
181*0e209d39SAndroid Build Coastguard Worker /**
182*0e209d39SAndroid Build Coastguard Worker  * Lowest-order bit number of unorm_compare() options bits corresponding to
183*0e209d39SAndroid Build Coastguard Worker  * normalization options bits.
184*0e209d39SAndroid Build Coastguard Worker  *
185*0e209d39SAndroid Build Coastguard Worker  * The options parameter for unorm_compare() uses most bits for
186*0e209d39SAndroid Build Coastguard Worker  * itself and for various comparison and folding flags.
187*0e209d39SAndroid Build Coastguard Worker  * The most significant bits, however, are shifted down and passed on
188*0e209d39SAndroid Build Coastguard Worker  * to the normalization implementation.
189*0e209d39SAndroid Build Coastguard Worker  * (That is, from unorm_compare(..., options, ...),
190*0e209d39SAndroid Build Coastguard Worker  * options>>UNORM_COMPARE_NORM_OPTIONS_SHIFT will be passed on to the
191*0e209d39SAndroid Build Coastguard Worker  * internal normalization functions.)
192*0e209d39SAndroid Build Coastguard Worker  *
193*0e209d39SAndroid Build Coastguard Worker  * @see unorm_compare
194*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
195*0e209d39SAndroid Build Coastguard Worker  */
196*0e209d39SAndroid Build Coastguard Worker #define UNORM_COMPARE_NORM_OPTIONS_SHIFT 20
197*0e209d39SAndroid Build Coastguard Worker 
198*0e209d39SAndroid Build Coastguard Worker /**
199*0e209d39SAndroid Build Coastguard Worker  * Normalize a string.
200*0e209d39SAndroid Build Coastguard Worker  * The string will be normalized according the specified normalization mode
201*0e209d39SAndroid Build Coastguard Worker  * and options.
202*0e209d39SAndroid Build Coastguard Worker  * The source and result buffers must not be the same, nor overlap.
203*0e209d39SAndroid Build Coastguard Worker  *
204*0e209d39SAndroid Build Coastguard Worker  * @param source The string to normalize.
205*0e209d39SAndroid Build Coastguard Worker  * @param sourceLength The length of source, or -1 if NUL-terminated.
206*0e209d39SAndroid Build Coastguard Worker  * @param mode The normalization mode; one of UNORM_NONE,
207*0e209d39SAndroid Build Coastguard Worker  *             UNORM_NFD, UNORM_NFC, UNORM_NFKC, UNORM_NFKD, UNORM_DEFAULT.
208*0e209d39SAndroid Build Coastguard Worker  * @param options The normalization options, ORed together (0 for no options).
209*0e209d39SAndroid Build Coastguard Worker  * @param result A pointer to a buffer to receive the result string.
210*0e209d39SAndroid Build Coastguard Worker  *               The result string is NUL-terminated if possible.
211*0e209d39SAndroid Build Coastguard Worker  * @param resultLength The maximum size of result.
212*0e209d39SAndroid Build Coastguard Worker  * @param status A pointer to a UErrorCode to receive any errors.
213*0e209d39SAndroid Build Coastguard Worker  * @return The total buffer size needed; if greater than resultLength,
214*0e209d39SAndroid Build Coastguard Worker  *         the output was truncated, and the error code is set to U_BUFFER_OVERFLOW_ERROR.
215*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
216*0e209d39SAndroid Build Coastguard Worker  */
217*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED int32_t U_EXPORT2
218*0e209d39SAndroid Build Coastguard Worker unorm_normalize(const UChar *source, int32_t sourceLength,
219*0e209d39SAndroid Build Coastguard Worker                 UNormalizationMode mode, int32_t options,
220*0e209d39SAndroid Build Coastguard Worker                 UChar *result, int32_t resultLength,
221*0e209d39SAndroid Build Coastguard Worker                 UErrorCode *status);
222*0e209d39SAndroid Build Coastguard Worker 
223*0e209d39SAndroid Build Coastguard Worker /**
224*0e209d39SAndroid Build Coastguard Worker  * Performing quick check on a string, to quickly determine if the string is
225*0e209d39SAndroid Build Coastguard Worker  * in a particular normalization format.
226*0e209d39SAndroid Build Coastguard Worker  * Three types of result can be returned UNORM_YES, UNORM_NO or
227*0e209d39SAndroid Build Coastguard Worker  * UNORM_MAYBE. Result UNORM_YES indicates that the argument
228*0e209d39SAndroid Build Coastguard Worker  * string is in the desired normalized format, UNORM_NO determines that
229*0e209d39SAndroid Build Coastguard Worker  * argument string is not in the desired normalized format. A
230*0e209d39SAndroid Build Coastguard Worker  * UNORM_MAYBE result indicates that a more thorough check is required,
231*0e209d39SAndroid Build Coastguard Worker  * the user may have to put the string in its normalized form and compare the
232*0e209d39SAndroid Build Coastguard Worker  * results.
233*0e209d39SAndroid Build Coastguard Worker  *
234*0e209d39SAndroid Build Coastguard Worker  * @param source       string for determining if it is in a normalized format
235*0e209d39SAndroid Build Coastguard Worker  * @param sourcelength length of source to test, or -1 if NUL-terminated
236*0e209d39SAndroid Build Coastguard Worker  * @param mode         which normalization form to test for
237*0e209d39SAndroid Build Coastguard Worker  * @param status       a pointer to a UErrorCode to receive any errors
238*0e209d39SAndroid Build Coastguard Worker  * @return UNORM_YES, UNORM_NO or UNORM_MAYBE
239*0e209d39SAndroid Build Coastguard Worker  *
240*0e209d39SAndroid Build Coastguard Worker  * @see unorm_isNormalized
241*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
242*0e209d39SAndroid Build Coastguard Worker  */
243*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED UNormalizationCheckResult U_EXPORT2
244*0e209d39SAndroid Build Coastguard Worker unorm_quickCheck(const UChar *source, int32_t sourcelength,
245*0e209d39SAndroid Build Coastguard Worker                  UNormalizationMode mode,
246*0e209d39SAndroid Build Coastguard Worker                  UErrorCode *status);
247*0e209d39SAndroid Build Coastguard Worker 
248*0e209d39SAndroid Build Coastguard Worker /**
249*0e209d39SAndroid Build Coastguard Worker  * Performing quick check on a string; same as unorm_quickCheck but
250*0e209d39SAndroid Build Coastguard Worker  * takes an extra options parameter like most normalization functions.
251*0e209d39SAndroid Build Coastguard Worker  *
252*0e209d39SAndroid Build Coastguard Worker  * @param src        String that is to be tested if it is in a normalization format.
253*0e209d39SAndroid Build Coastguard Worker  * @param srcLength  Length of source to test, or -1 if NUL-terminated.
254*0e209d39SAndroid Build Coastguard Worker  * @param mode       Which normalization form to test for.
255*0e209d39SAndroid Build Coastguard Worker  * @param options    The normalization options, ORed together (0 for no options).
256*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode ICU error code in/out parameter.
257*0e209d39SAndroid Build Coastguard Worker  *                   Must fulfill U_SUCCESS before the function call.
258*0e209d39SAndroid Build Coastguard Worker  * @return UNORM_YES, UNORM_NO or UNORM_MAYBE
259*0e209d39SAndroid Build Coastguard Worker  *
260*0e209d39SAndroid Build Coastguard Worker  * @see unorm_quickCheck
261*0e209d39SAndroid Build Coastguard Worker  * @see unorm_isNormalized
262*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
263*0e209d39SAndroid Build Coastguard Worker  */
264*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED UNormalizationCheckResult U_EXPORT2
265*0e209d39SAndroid Build Coastguard Worker unorm_quickCheckWithOptions(const UChar *src, int32_t srcLength,
266*0e209d39SAndroid Build Coastguard Worker                             UNormalizationMode mode, int32_t options,
267*0e209d39SAndroid Build Coastguard Worker                             UErrorCode *pErrorCode);
268*0e209d39SAndroid Build Coastguard Worker 
269*0e209d39SAndroid Build Coastguard Worker /**
270*0e209d39SAndroid Build Coastguard Worker  * Test if a string is in a given normalization form.
271*0e209d39SAndroid Build Coastguard Worker  * This is semantically equivalent to source.equals(normalize(source, mode)) .
272*0e209d39SAndroid Build Coastguard Worker  *
273*0e209d39SAndroid Build Coastguard Worker  * Unlike unorm_quickCheck(), this function returns a definitive result,
274*0e209d39SAndroid Build Coastguard Worker  * never a "maybe".
275*0e209d39SAndroid Build Coastguard Worker  * For NFD, NFKD, and FCD, both functions work exactly the same.
276*0e209d39SAndroid Build Coastguard Worker  * For NFC and NFKC where quickCheck may return "maybe", this function will
277*0e209d39SAndroid Build Coastguard Worker  * perform further tests to arrive at a true/false result.
278*0e209d39SAndroid Build Coastguard Worker  *
279*0e209d39SAndroid Build Coastguard Worker  * @param src        String that is to be tested if it is in a normalization format.
280*0e209d39SAndroid Build Coastguard Worker  * @param srcLength  Length of source to test, or -1 if NUL-terminated.
281*0e209d39SAndroid Build Coastguard Worker  * @param mode       Which normalization form to test for.
282*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode ICU error code in/out parameter.
283*0e209d39SAndroid Build Coastguard Worker  *                   Must fulfill U_SUCCESS before the function call.
284*0e209d39SAndroid Build Coastguard Worker  * @return Boolean value indicating whether the source string is in the
285*0e209d39SAndroid Build Coastguard Worker  *         "mode" normalization form.
286*0e209d39SAndroid Build Coastguard Worker  *
287*0e209d39SAndroid Build Coastguard Worker  * @see unorm_quickCheck
288*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
289*0e209d39SAndroid Build Coastguard Worker  */
290*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED UBool U_EXPORT2
291*0e209d39SAndroid Build Coastguard Worker unorm_isNormalized(const UChar *src, int32_t srcLength,
292*0e209d39SAndroid Build Coastguard Worker                    UNormalizationMode mode,
293*0e209d39SAndroid Build Coastguard Worker                    UErrorCode *pErrorCode);
294*0e209d39SAndroid Build Coastguard Worker 
295*0e209d39SAndroid Build Coastguard Worker /**
296*0e209d39SAndroid Build Coastguard Worker  * Test if a string is in a given normalization form; same as unorm_isNormalized but
297*0e209d39SAndroid Build Coastguard Worker  * takes an extra options parameter like most normalization functions.
298*0e209d39SAndroid Build Coastguard Worker  *
299*0e209d39SAndroid Build Coastguard Worker  * @param src        String that is to be tested if it is in a normalization format.
300*0e209d39SAndroid Build Coastguard Worker  * @param srcLength  Length of source to test, or -1 if NUL-terminated.
301*0e209d39SAndroid Build Coastguard Worker  * @param mode       Which normalization form to test for.
302*0e209d39SAndroid Build Coastguard Worker  * @param options    The normalization options, ORed together (0 for no options).
303*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode ICU error code in/out parameter.
304*0e209d39SAndroid Build Coastguard Worker  *                   Must fulfill U_SUCCESS before the function call.
305*0e209d39SAndroid Build Coastguard Worker  * @return Boolean value indicating whether the source string is in the
306*0e209d39SAndroid Build Coastguard Worker  *         "mode/options" normalization form.
307*0e209d39SAndroid Build Coastguard Worker  *
308*0e209d39SAndroid Build Coastguard Worker  * @see unorm_quickCheck
309*0e209d39SAndroid Build Coastguard Worker  * @see unorm_isNormalized
310*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
311*0e209d39SAndroid Build Coastguard Worker  */
312*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED UBool U_EXPORT2
313*0e209d39SAndroid Build Coastguard Worker unorm_isNormalizedWithOptions(const UChar *src, int32_t srcLength,
314*0e209d39SAndroid Build Coastguard Worker                               UNormalizationMode mode, int32_t options,
315*0e209d39SAndroid Build Coastguard Worker                               UErrorCode *pErrorCode);
316*0e209d39SAndroid Build Coastguard Worker 
317*0e209d39SAndroid Build Coastguard Worker /**
318*0e209d39SAndroid Build Coastguard Worker  * Iterative normalization forward.
319*0e209d39SAndroid Build Coastguard Worker  * This function (together with unorm_previous) is somewhat
320*0e209d39SAndroid Build Coastguard Worker  * similar to the C++ Normalizer class (see its non-static functions).
321*0e209d39SAndroid Build Coastguard Worker  *
322*0e209d39SAndroid Build Coastguard Worker  * Iterative normalization is useful when only a small portion of a longer
323*0e209d39SAndroid Build Coastguard Worker  * string/text needs to be processed.
324*0e209d39SAndroid Build Coastguard Worker  *
325*0e209d39SAndroid Build Coastguard Worker  * For example, the likelihood may be high that processing the first 10% of some
326*0e209d39SAndroid Build Coastguard Worker  * text will be sufficient to find certain data.
327*0e209d39SAndroid Build Coastguard Worker  * Another example: When one wants to concatenate two normalized strings and get a
328*0e209d39SAndroid Build Coastguard Worker  * normalized result, it is much more efficient to normalize just a small part of
329*0e209d39SAndroid Build Coastguard Worker  * the result around the concatenation place instead of re-normalizing everything.
330*0e209d39SAndroid Build Coastguard Worker  *
331*0e209d39SAndroid Build Coastguard Worker  * The input text is an instance of the C character iteration API UCharIterator.
332*0e209d39SAndroid Build Coastguard Worker  * It may wrap around a simple string, a CharacterIterator, a Replaceable, or any
333*0e209d39SAndroid Build Coastguard Worker  * other kind of text object.
334*0e209d39SAndroid Build Coastguard Worker  *
335*0e209d39SAndroid Build Coastguard Worker  * If a buffer overflow occurs, then the caller needs to reset the iterator to the
336*0e209d39SAndroid Build Coastguard Worker  * old index and call the function again with a larger buffer - if the caller cares
337*0e209d39SAndroid Build Coastguard Worker  * for the actual output.
338*0e209d39SAndroid Build Coastguard Worker  * Regardless of the output buffer, the iterator will always be moved to the next
339*0e209d39SAndroid Build Coastguard Worker  * normalization boundary.
340*0e209d39SAndroid Build Coastguard Worker  *
341*0e209d39SAndroid Build Coastguard Worker  * This function (like unorm_previous) serves two purposes:
342*0e209d39SAndroid Build Coastguard Worker  *
343*0e209d39SAndroid Build Coastguard Worker  * 1) To find the next boundary so that the normalization of the part of the text
344*0e209d39SAndroid Build Coastguard Worker  * from the current position to that boundary does not affect and is not affected
345*0e209d39SAndroid Build Coastguard Worker  * by the part of the text beyond that boundary.
346*0e209d39SAndroid Build Coastguard Worker  *
347*0e209d39SAndroid Build Coastguard Worker  * 2) To normalize the text up to the boundary.
348*0e209d39SAndroid Build Coastguard Worker  *
349*0e209d39SAndroid Build Coastguard Worker  * The second step is optional, per the doNormalize parameter.
350*0e209d39SAndroid Build Coastguard Worker  * It is omitted for operations like string concatenation, where the two adjacent
351*0e209d39SAndroid Build Coastguard Worker  * string ends need to be normalized together.
352*0e209d39SAndroid Build Coastguard Worker  * In such a case, the output buffer will just contain a copy of the text up to the
353*0e209d39SAndroid Build Coastguard Worker  * boundary.
354*0e209d39SAndroid Build Coastguard Worker  *
355*0e209d39SAndroid Build Coastguard Worker  * pNeededToNormalize is an output-only parameter. Its output value is only defined
356*0e209d39SAndroid Build Coastguard Worker  * if normalization was requested (doNormalize) and successful (especially, no
357*0e209d39SAndroid Build Coastguard Worker  * buffer overflow).
358*0e209d39SAndroid Build Coastguard Worker  * It is useful for operations like a normalizing transliterator, where one would
359*0e209d39SAndroid Build Coastguard Worker  * not want to replace a piece of text if it is not modified.
360*0e209d39SAndroid Build Coastguard Worker  *
361*0e209d39SAndroid Build Coastguard Worker  * If doNormalize==true and pNeededToNormalize!=NULL then *pNeeded... is set true
362*0e209d39SAndroid Build Coastguard Worker  * if the normalization was necessary.
363*0e209d39SAndroid Build Coastguard Worker  *
364*0e209d39SAndroid Build Coastguard Worker  * If doNormalize==false then *pNeededToNormalize will be set to false.
365*0e209d39SAndroid Build Coastguard Worker  *
366*0e209d39SAndroid Build Coastguard Worker  * If the buffer overflows, then *pNeededToNormalize will be undefined;
367*0e209d39SAndroid Build Coastguard Worker  * essentially, whenever U_FAILURE is true (like in buffer overflows), this result
368*0e209d39SAndroid Build Coastguard Worker  * will be undefined.
369*0e209d39SAndroid Build Coastguard Worker  *
370*0e209d39SAndroid Build Coastguard Worker  * @param src The input text in the form of a C character iterator.
371*0e209d39SAndroid Build Coastguard Worker  * @param dest The output buffer; can be NULL if destCapacity==0 for pure preflighting.
372*0e209d39SAndroid Build Coastguard Worker  * @param destCapacity The number of UChars that fit into dest.
373*0e209d39SAndroid Build Coastguard Worker  * @param mode The normalization mode.
374*0e209d39SAndroid Build Coastguard Worker  * @param options The normalization options, ORed together (0 for no options).
375*0e209d39SAndroid Build Coastguard Worker  * @param doNormalize Indicates if the source text up to the next boundary
376*0e209d39SAndroid Build Coastguard Worker  *                    is to be normalized (true) or just copied (false).
377*0e209d39SAndroid Build Coastguard Worker  * @param pNeededToNormalize Output flag indicating if the normalization resulted in
378*0e209d39SAndroid Build Coastguard Worker  *                           different text from the input.
379*0e209d39SAndroid Build Coastguard Worker  *                           Not defined if an error occurs including buffer overflow.
380*0e209d39SAndroid Build Coastguard Worker  *                           Always false if !doNormalize.
381*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode ICU error code in/out parameter.
382*0e209d39SAndroid Build Coastguard Worker  *                   Must fulfill U_SUCCESS before the function call.
383*0e209d39SAndroid Build Coastguard Worker  * @return Length of output (number of UChars) when successful or buffer overflow.
384*0e209d39SAndroid Build Coastguard Worker  *
385*0e209d39SAndroid Build Coastguard Worker  * @see unorm_previous
386*0e209d39SAndroid Build Coastguard Worker  * @see unorm_normalize
387*0e209d39SAndroid Build Coastguard Worker  *
388*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
389*0e209d39SAndroid Build Coastguard Worker  */
390*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED int32_t U_EXPORT2
391*0e209d39SAndroid Build Coastguard Worker unorm_next(UCharIterator *src,
392*0e209d39SAndroid Build Coastguard Worker            UChar *dest, int32_t destCapacity,
393*0e209d39SAndroid Build Coastguard Worker            UNormalizationMode mode, int32_t options,
394*0e209d39SAndroid Build Coastguard Worker            UBool doNormalize, UBool *pNeededToNormalize,
395*0e209d39SAndroid Build Coastguard Worker            UErrorCode *pErrorCode);
396*0e209d39SAndroid Build Coastguard Worker 
397*0e209d39SAndroid Build Coastguard Worker /**
398*0e209d39SAndroid Build Coastguard Worker  * Iterative normalization backward.
399*0e209d39SAndroid Build Coastguard Worker  * This function (together with unorm_next) is somewhat
400*0e209d39SAndroid Build Coastguard Worker  * similar to the C++ Normalizer class (see its non-static functions).
401*0e209d39SAndroid Build Coastguard Worker  * For all details see unorm_next.
402*0e209d39SAndroid Build Coastguard Worker  *
403*0e209d39SAndroid Build Coastguard Worker  * @param src The input text in the form of a C character iterator.
404*0e209d39SAndroid Build Coastguard Worker  * @param dest The output buffer; can be NULL if destCapacity==0 for pure preflighting.
405*0e209d39SAndroid Build Coastguard Worker  * @param destCapacity The number of UChars that fit into dest.
406*0e209d39SAndroid Build Coastguard Worker  * @param mode The normalization mode.
407*0e209d39SAndroid Build Coastguard Worker  * @param options The normalization options, ORed together (0 for no options).
408*0e209d39SAndroid Build Coastguard Worker  * @param doNormalize Indicates if the source text up to the next boundary
409*0e209d39SAndroid Build Coastguard Worker  *                    is to be normalized (true) or just copied (false).
410*0e209d39SAndroid Build Coastguard Worker  * @param pNeededToNormalize Output flag indicating if the normalization resulted in
411*0e209d39SAndroid Build Coastguard Worker  *                           different text from the input.
412*0e209d39SAndroid Build Coastguard Worker  *                           Not defined if an error occurs including buffer overflow.
413*0e209d39SAndroid Build Coastguard Worker  *                           Always false if !doNormalize.
414*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode ICU error code in/out parameter.
415*0e209d39SAndroid Build Coastguard Worker  *                   Must fulfill U_SUCCESS before the function call.
416*0e209d39SAndroid Build Coastguard Worker  * @return Length of output (number of UChars) when successful or buffer overflow.
417*0e209d39SAndroid Build Coastguard Worker  *
418*0e209d39SAndroid Build Coastguard Worker  * @see unorm_next
419*0e209d39SAndroid Build Coastguard Worker  * @see unorm_normalize
420*0e209d39SAndroid Build Coastguard Worker  *
421*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
422*0e209d39SAndroid Build Coastguard Worker  */
423*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED int32_t U_EXPORT2
424*0e209d39SAndroid Build Coastguard Worker unorm_previous(UCharIterator *src,
425*0e209d39SAndroid Build Coastguard Worker                UChar *dest, int32_t destCapacity,
426*0e209d39SAndroid Build Coastguard Worker                UNormalizationMode mode, int32_t options,
427*0e209d39SAndroid Build Coastguard Worker                UBool doNormalize, UBool *pNeededToNormalize,
428*0e209d39SAndroid Build Coastguard Worker                UErrorCode *pErrorCode);
429*0e209d39SAndroid Build Coastguard Worker 
430*0e209d39SAndroid Build Coastguard Worker /**
431*0e209d39SAndroid Build Coastguard Worker  * Concatenate normalized strings, making sure that the result is normalized as well.
432*0e209d39SAndroid Build Coastguard Worker  *
433*0e209d39SAndroid Build Coastguard Worker  * If both the left and the right strings are in
434*0e209d39SAndroid Build Coastguard Worker  * the normalization form according to "mode/options",
435*0e209d39SAndroid Build Coastguard Worker  * then the result will be
436*0e209d39SAndroid Build Coastguard Worker  *
437*0e209d39SAndroid Build Coastguard Worker  * \code
438*0e209d39SAndroid Build Coastguard Worker  *     dest=normalize(left+right, mode, options)
439*0e209d39SAndroid Build Coastguard Worker  * \endcode
440*0e209d39SAndroid Build Coastguard Worker  *
441*0e209d39SAndroid Build Coastguard Worker  * With the input strings already being normalized,
442*0e209d39SAndroid Build Coastguard Worker  * this function will use unorm_next() and unorm_previous()
443*0e209d39SAndroid Build Coastguard Worker  * to find the adjacent end pieces of the input strings.
444*0e209d39SAndroid Build Coastguard Worker  * Only the concatenation of these end pieces will be normalized and
445*0e209d39SAndroid Build Coastguard Worker  * then concatenated with the remaining parts of the input strings.
446*0e209d39SAndroid Build Coastguard Worker  *
447*0e209d39SAndroid Build Coastguard Worker  * It is allowed to have dest==left to avoid copying the entire left string.
448*0e209d39SAndroid Build Coastguard Worker  *
449*0e209d39SAndroid Build Coastguard Worker  * @param left Left source string, may be same as dest.
450*0e209d39SAndroid Build Coastguard Worker  * @param leftLength Length of left source string, or -1 if NUL-terminated.
451*0e209d39SAndroid Build Coastguard Worker  * @param right Right source string. Must not be the same as dest, nor overlap.
452*0e209d39SAndroid Build Coastguard Worker  * @param rightLength Length of right source string, or -1 if NUL-terminated.
453*0e209d39SAndroid Build Coastguard Worker  * @param dest The output buffer; can be NULL if destCapacity==0 for pure preflighting.
454*0e209d39SAndroid Build Coastguard Worker  * @param destCapacity The number of UChars that fit into dest.
455*0e209d39SAndroid Build Coastguard Worker  * @param mode The normalization mode.
456*0e209d39SAndroid Build Coastguard Worker  * @param options The normalization options, ORed together (0 for no options).
457*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode ICU error code in/out parameter.
458*0e209d39SAndroid Build Coastguard Worker  *                   Must fulfill U_SUCCESS before the function call.
459*0e209d39SAndroid Build Coastguard Worker  * @return Length of output (number of UChars) when successful or buffer overflow.
460*0e209d39SAndroid Build Coastguard Worker  *
461*0e209d39SAndroid Build Coastguard Worker  * @see unorm_normalize
462*0e209d39SAndroid Build Coastguard Worker  * @see unorm_next
463*0e209d39SAndroid Build Coastguard Worker  * @see unorm_previous
464*0e209d39SAndroid Build Coastguard Worker  *
465*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 56 Use unorm2.h instead.
466*0e209d39SAndroid Build Coastguard Worker  */
467*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED int32_t U_EXPORT2
468*0e209d39SAndroid Build Coastguard Worker unorm_concatenate(const UChar *left, int32_t leftLength,
469*0e209d39SAndroid Build Coastguard Worker                   const UChar *right, int32_t rightLength,
470*0e209d39SAndroid Build Coastguard Worker                   UChar *dest, int32_t destCapacity,
471*0e209d39SAndroid Build Coastguard Worker                   UNormalizationMode mode, int32_t options,
472*0e209d39SAndroid Build Coastguard Worker                   UErrorCode *pErrorCode);
473*0e209d39SAndroid Build Coastguard Worker 
474*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_DEPRECATED_API */
475*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_NORMALIZATION */
476*0e209d39SAndroid Build Coastguard Worker #endif
477