intl/icu/source/common/unicode/unorm.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial