intl/icu/source/i18n/unicode/uspoof.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) 2008-2013, International Business Machines Corporation
michael@0 4 * and others. All Rights Reserved.
michael@0 5 ***************************************************************************
michael@0 6 * file name: uspoof.h
michael@0 7 * encoding: US-ASCII
michael@0 8 * tab size: 8 (not used)
michael@0 9 * indentation:4
michael@0 10 *
michael@0 11 * created on: 2008Feb13
michael@0 12 * created by: Andy Heninger
michael@0 13 *
michael@0 14 * Unicode Spoof Detection
michael@0 15 */
michael@0 16
michael@0 17 #ifndef USPOOF_H
michael@0 18 #define USPOOF_H
michael@0 19
michael@0 20 #include "unicode/utypes.h"
michael@0 21 #include "unicode/uset.h"
michael@0 22 #include "unicode/parseerr.h"
michael@0 23 #include "unicode/localpointer.h"
michael@0 24
michael@0 25 #if !UCONFIG_NO_NORMALIZATION
michael@0 26
michael@0 27
michael@0 28 #if U_SHOW_CPLUSPLUS_API
michael@0 29 #include "unicode/unistr.h"
michael@0 30 #include "unicode/uniset.h"
michael@0 31 #endif
michael@0 32
michael@0 33
michael@0 34 /**
michael@0 35 * \file
michael@0 36 * \brief Unicode Security and Spoofing Detection, C API.
michael@0 37 *
michael@0 38 * These functions are intended to check strings, typically
michael@0 39 * identifiers of some type, such as URLs, for the presence of
michael@0 40 * characters that are likely to be visually confusing -
michael@0 41 * for cases where the displayed form of an identifier may
michael@0 42 * not be what it appears to be.
michael@0 43 *
michael@0 44 * Unicode Technical Report #36, http://unicode.org/reports/tr36, and
michael@0 45 * Unicode Technical Standard #39, http://unicode.org/reports/tr39
michael@0 46 * "Unicode security considerations", give more background on
michael@0 47 * security an spoofing issues with Unicode identifiers.
michael@0 48 * The tests and checks provided by this module implement the recommendations
michael@0 49 * from those Unicode documents.
michael@0 50 *
michael@0 51 * The tests available on identifiers fall into two general categories:
michael@0 52 * -# Single identifier tests. Check whether an identifier is
michael@0 53 * potentially confusable with any other string, or is suspicious
michael@0 54 * for other reasons.
michael@0 55 * -# Two identifier tests. Check whether two specific identifiers are confusable.
michael@0 56 * This does not consider whether either of strings is potentially
michael@0 57 * confusable with any string other than the exact one specified.
michael@0 58 *
michael@0 59 * The steps to perform confusability testing are
michael@0 60 * -# Open a USpoofChecker.
michael@0 61 * -# Configure the USPoofChecker for the desired set of tests. The tests that will
michael@0 62 * be performed are specified by a set of USpoofChecks flags.
michael@0 63 * -# Perform the checks using the pre-configured USpoofChecker. The results indicate
michael@0 64 * which (if any) of the selected tests have identified possible problems with the identifier.
michael@0 65 * Results are reported as a set of USpoofChecks flags; this mirrors the form in which
michael@0 66 * the set of tests to perform was originally specified to the USpoofChecker.
michael@0 67 *
michael@0 68 * A USpoofChecker may be used repeatedly to perform checks on any number of identifiers.
michael@0 69 *
michael@0 70 * Thread Safety: The test functions for checking a single identifier, or for testing
michael@0 71 * whether two identifiers are possible confusable, are thread safe.
michael@0 72 * They may called concurrently, from multiple threads, using the same USpoofChecker instance.
michael@0 73 *
michael@0 74 * More generally, the standard ICU thread safety rules apply: functions that take a
michael@0 75 * const USpoofChecker parameter are thread safe. Those that take a non-const
michael@0 76 * USpoofChecier are not thread safe.
michael@0 77 *
michael@0 78 *
michael@0 79 * Descriptions of the available checks.
michael@0 80 *
michael@0 81 * When testing whether pairs of identifiers are confusable, with the uspoof_areConfusable()
michael@0 82 * family of functions, the relevant tests are
michael@0 83 *
michael@0 84 * -# USPOOF_SINGLE_SCRIPT_CONFUSABLE: All of the characters from the two identifiers are
michael@0 85 * from a single script, and the two identifiers are visually confusable.
michael@0 86 * -# USPOOF_MIXED_SCRIPT_CONFUSABLE: At least one of the identifiers contains characters
michael@0 87 * from more than one script, and the two identifiers are visually confusable.
michael@0 88 * -# USPOOF_WHOLE_SCRIPT_CONFUSABLE: Each of the two identifiers is of a single script, but
michael@0 89 * the two identifiers are from different scripts, and they are visually confusable.
michael@0 90 *
michael@0 91 * The safest approach is to enable all three of these checks as a group.
michael@0 92 *
michael@0 93 * USPOOF_ANY_CASE is a modifier for the above tests. If the identifiers being checked can
michael@0 94 * be of mixed case and are used in a case-sensitive manner, this option should be specified.
michael@0 95 *
michael@0 96 * If the identifiers being checked are used in a case-insensitive manner, and if they are
michael@0 97 * displayed to users in lower-case form only, the USPOOF_ANY_CASE option should not be
michael@0 98 * specified. Confusabality issues involving upper case letters will not be reported.
michael@0 99 *
michael@0 100 * When performing tests on a single identifier, with the uspoof_check() family of functions,
michael@0 101 * the relevant tests are:
michael@0 102 *
michael@0 103 * -# USPOOF_MIXED_SCRIPT_CONFUSABLE: the identifier contains characters from multiple
michael@0 104 * scripts, and there exists an identifier of a single script that is visually confusable.
michael@0 105 * -# USPOOF_WHOLE_SCRIPT_CONFUSABLE: the identifier consists of characters from a single
michael@0 106 * script, and there exists a visually confusable identifier.
michael@0 107 * The visually confusable identifier also consists of characters from a single script.
michael@0 108 * but not the same script as the identifier being checked.
michael@0 109 * -# USPOOF_ANY_CASE: modifies the mixed script and whole script confusables tests. If
michael@0 110 * specified, the checks will consider confusable characters of any case. If this flag is not
michael@0 111 * set, the test is performed assuming case folded identifiers.
michael@0 112 * -# USPOOF_SINGLE_SCRIPT: check that the identifier contains only characters from a
michael@0 113 * single script. (Characters from the 'common' and 'inherited' scripts are ignored.)
michael@0 114 * This is not a test for confusable identifiers
michael@0 115 * -# USPOOF_INVISIBLE: check an identifier for the presence of invisible characters,
michael@0 116 * such as zero-width spaces, or character sequences that are
michael@0 117 * likely not to display, such as multiple occurrences of the same
michael@0 118 * non-spacing mark. This check does not test the input string as a whole
michael@0 119 * for conformance to any particular syntax for identifiers.
michael@0 120 * -# USPOOF_CHAR_LIMIT: check that an identifier contains only characters from a specified set
michael@0 121 * of acceptable characters. See uspoof_setAllowedChars() and
michael@0 122 * uspoof_setAllowedLocales().
michael@0 123 *
michael@0 124 * Note on Scripts:
michael@0 125 * Characters from the Unicode Scripts "Common" and "Inherited" are ignored when considering
michael@0 126 * the script of an identifier. Common characters include digits and symbols that
michael@0 127 * are normally used with text from more than one script.
michael@0 128 *
michael@0 129 * Identifier Skeletons: A skeleton is a transformation of an identifier, such that
michael@0 130 * all identifiers that are confusable with each other have the same skeleton.
michael@0 131 * Using skeletons, it is possible to build a dictionary data structure for
michael@0 132 * a set of identifiers, and then quickly test whether a new identifier is
michael@0 133 * confusable with an identifier already in the set. The uspoof_getSkeleton()
michael@0 134 * family of functions will produce the skeleton from an identifier.
michael@0 135 *
michael@0 136 * Note that skeletons are not guaranteed to be stable between versions
michael@0 137 * of Unicode or ICU, so an applications should not rely on creating a permanent,
michael@0 138 * or difficult to update, database of skeletons. Instabilities result from
michael@0 139 * identifying new pairs or sequences of characters that are visually
michael@0 140 * confusable, and thus must be mapped to the same skeleton character(s).
michael@0 141 *
michael@0 142 */
michael@0 143
michael@0 144 struct USpoofChecker;
michael@0 145 typedef struct USpoofChecker USpoofChecker; /**< typedef for C of USpoofChecker */
michael@0 146
michael@0 147 /**
michael@0 148 * Enum for the kinds of checks that USpoofChecker can perform.
michael@0 149 * These enum values are used both to select the set of checks that
michael@0 150 * will be performed, and to report results from the check function.
michael@0 151 *
michael@0 152 * @stable ICU 4.2
michael@0 153 */
michael@0 154 typedef enum USpoofChecks {
michael@0 155 /** Single script confusable test.
michael@0 156 * When testing whether two identifiers are confusable, report that they are if
michael@0 157 * both are from the same script and they are visually confusable.
michael@0 158 * Note: this test is not applicable to a check of a single identifier.
michael@0 159 */
michael@0 160 USPOOF_SINGLE_SCRIPT_CONFUSABLE = 1,
michael@0 161
michael@0 162 /** Mixed script confusable test.
michael@0 163 * When checking a single identifier, report a problem if
michael@0 164 * the identifier contains multiple scripts, and
michael@0 165 * is confusable with some other identifier in a single script
michael@0 166 * When testing whether two identifiers are confusable, report that they are if
michael@0 167 * the two IDs are visually confusable,
michael@0 168 * and at least one contains characters from more than one script.
michael@0 169 */
michael@0 170 USPOOF_MIXED_SCRIPT_CONFUSABLE = 2,
michael@0 171
michael@0 172 /** Whole script confusable test.
michael@0 173 * When checking a single identifier, report a problem if
michael@0 174 * The identifier is of a single script, and
michael@0 175 * there exists a confusable identifier in another script.
michael@0 176 * When testing whether two identifiers are confusable, report that they are if
michael@0 177 * each is of a single script,
michael@0 178 * the scripts of the two identifiers are different, and
michael@0 179 * the identifiers are visually confusable.
michael@0 180 */
michael@0 181 USPOOF_WHOLE_SCRIPT_CONFUSABLE = 4,
michael@0 182
michael@0 183 /** Any Case Modifier for confusable identifier tests.
michael@0 184 If specified, consider all characters, of any case, when looking for confusables.
michael@0 185 If USPOOF_ANY_CASE is not specified, identifiers being checked are assumed to have been
michael@0 186 case folded. Upper case confusable characters will not be checked.
michael@0 187 Selects between Lower Case Confusable and
michael@0 188 Any Case Confusable. */
michael@0 189 USPOOF_ANY_CASE = 8,
michael@0 190
michael@0 191 /**
michael@0 192 * Check that an identifier is no looser than the specified RestrictionLevel.
michael@0 193 * The default if uspoof_setRestrctionLevel() is not called is HIGHLY_RESTRICTIVE.
michael@0 194 *
michael@0 195 * If USPOOF_AUX_INFO is enabled the actual restriction level of the
michael@0 196 * identifier being tested will also be returned by uspoof_check().
michael@0 197 *
michael@0 198 * @see URestrictionLevel
michael@0 199 * @see uspoof_setRestrictionLevel
michael@0 200 * @see USPOOF_AUX_INFO
michael@0 201 *
michael@0 202 * @stable ICU 51
michael@0 203 */
michael@0 204 USPOOF_RESTRICTION_LEVEL = 16,
michael@0 205
michael@0 206 #ifndef U_HIDE_DEPRECATED_API
michael@0 207 /** Check that an identifier contains only characters from a
michael@0 208 * single script (plus chars from the common and inherited scripts.)
michael@0 209 * Applies to checks of a single identifier check only.
michael@0 210 * @deprecated ICU 51 Use RESTRICTION_LEVEL instead.
michael@0 211 */
michael@0 212 USPOOF_SINGLE_SCRIPT = USPOOF_RESTRICTION_LEVEL,
michael@0 213 #endif /* U_HIDE_DEPRECATED_API */
michael@0 214
michael@0 215 /** Check an identifier for the presence of invisible characters,
michael@0 216 * such as zero-width spaces, or character sequences that are
michael@0 217 * likely not to display, such as multiple occurrences of the same
michael@0 218 * non-spacing mark. This check does not test the input string as a whole
michael@0 219 * for conformance to any particular syntax for identifiers.
michael@0 220 */
michael@0 221 USPOOF_INVISIBLE = 32,
michael@0 222
michael@0 223 /** Check that an identifier contains only characters from a specified set
michael@0 224 * of acceptable characters. See uspoof_setAllowedChars() and
michael@0 225 * uspoof_setAllowedLocales().
michael@0 226 */
michael@0 227 USPOOF_CHAR_LIMIT = 64,
michael@0 228
michael@0 229 #ifndef U_HIDE_DRAFT_API
michael@0 230 /**
michael@0 231 * Check that an identifier does not include decimal digits from
michael@0 232 * more than one numbering system.
michael@0 233 *
michael@0 234 * @draft ICU 51
michael@0 235 */
michael@0 236 USPOOF_MIXED_NUMBERS = 128,
michael@0 237 #endif /* U_HIDE_DRAFT_API */
michael@0 238
michael@0 239 /**
michael@0 240 * Enable all spoof checks.
michael@0 241 *
michael@0 242 * @stable ICU 4.6
michael@0 243 */
michael@0 244 USPOOF_ALL_CHECKS = 0xFFFF,
michael@0 245
michael@0 246 #ifndef U_HIDE_DRAFT_API
michael@0 247 /**
michael@0 248 * Enable the return of auxillary (non-error) information in the
michael@0 249 * upper bits of the check results value.
michael@0 250 *
michael@0 251 * If this "check" is not enabled, the results of uspoof_check() will be zero when an
michael@0 252 * identifier passes all of the enabled checks.
michael@0 253 *
michael@0 254 * If this "check" is enabled, (uspoof_check() & USPOOF_ALL_CHECKS) will be zero
michael@0 255 * when an identifier passes all checks.
michael@0 256 *
michael@0 257 * @draft ICU 51
michael@0 258 */
michael@0 259 USPOOF_AUX_INFO = 0x40000000
michael@0 260 #endif /* U_HIDE_DRAFT_API */
michael@0 261
michael@0 262 } USpoofChecks;
michael@0 263
michael@0 264
michael@0 265 #ifndef U_HIDE_DRAFT_API
michael@0 266 /**
michael@0 267 * Constants from UAX #39 for use in setRestrictionLevel(), and
michael@0 268 * for returned identifier restriction levels in check results.
michael@0 269 * @draft ICU 51
michael@0 270 */
michael@0 271 typedef enum URestrictionLevel {
michael@0 272 /**
michael@0 273 * Only ASCII characters: U+0000..U+007F
michael@0 274 *
michael@0 275 * @draft ICU 51
michael@0 276 */
michael@0 277 USPOOF_ASCII = 0x10000000,
michael@0 278 /**
michael@0 279 * All characters in each identifier must be from a single script, or from the combinations: Latin + Han +
michael@0 280 * Hiragana + Katakana; Latin + Han + Bopomofo; or Latin + Han + Hangul. Note that this level will satisfy the
michael@0 281 * vast majority of Latin-script users; also that TR36 has ASCII instead of Latin.
michael@0 282 *
michael@0 283 * @draft ICU 51
michael@0 284 */
michael@0 285 USPOOF_HIGHLY_RESTRICTIVE = 0x20000000,
michael@0 286 /**
michael@0 287 * Allow Latin with other scripts except Cyrillic, Greek, Cherokee Otherwise, the same as Highly Restrictive
michael@0 288 *
michael@0 289 * @draft ICU 51
michael@0 290 */
michael@0 291 USPOOF_MODERATELY_RESTRICTIVE = 0x30000000,
michael@0 292 /**
michael@0 293 * Allow arbitrary mixtures of scripts. Otherwise, the same as Moderately Restrictive.
michael@0 294 *
michael@0 295 * @draft ICU 51
michael@0 296 */
michael@0 297 USPOOF_MINIMALLY_RESTRICTIVE = 0x40000000,
michael@0 298 /**
michael@0 299 * Any valid identifiers, including characters outside of the Identifier Profile.
michael@0 300 *
michael@0 301 * @draft ICU 51
michael@0 302 */
michael@0 303 USPOOF_UNRESTRICTIVE = 0x50000000
michael@0 304 } URestrictionLevel;
michael@0 305 #endif /* U_HIDE_DRAFT_API */
michael@0 306
michael@0 307 /**
michael@0 308 * Create a Unicode Spoof Checker, configured to perform all
michael@0 309 * checks except for USPOOF_LOCALE_LIMIT and USPOOF_CHAR_LIMIT.
michael@0 310 * Note that additional checks may be added in the future,
michael@0 311 * resulting in the changes to the default checking behavior.
michael@0 312 *
michael@0 313 * @param status The error code, set if this function encounters a problem.
michael@0 314 * @return the newly created Spoof Checker
michael@0 315 * @stable ICU 4.2
michael@0 316 */
michael@0 317 U_STABLE USpoofChecker * U_EXPORT2
michael@0 318 uspoof_open(UErrorCode *status);
michael@0 319
michael@0 320
michael@0 321 /**
michael@0 322 * Open a Spoof checker from its serialized from, stored in 32-bit-aligned memory.
michael@0 323 * Inverse of uspoof_serialize().
michael@0 324 * The memory containing the serialized data must remain valid and unchanged
michael@0 325 * as long as the spoof checker, or any cloned copies of the spoof checker,
michael@0 326 * are in use. Ownership of the memory remains with the caller.
michael@0 327 * The spoof checker (and any clones) must be closed prior to deleting the
michael@0 328 * serialized data.
michael@0 329 *
michael@0 330 * @param data a pointer to 32-bit-aligned memory containing the serialized form of spoof data
michael@0 331 * @param length the number of bytes available at data;
michael@0 332 * can be more than necessary
michael@0 333 * @param pActualLength receives the actual number of bytes at data taken up by the data;
michael@0 334 * can be NULL
michael@0 335 * @param pErrorCode ICU error code
michael@0 336 * @return the spoof checker.
michael@0 337 *
michael@0 338 * @see uspoof_open
michael@0 339 * @see uspoof_serialize
michael@0 340 * @stable ICU 4.2
michael@0 341 */
michael@0 342 U_STABLE USpoofChecker * U_EXPORT2
michael@0 343 uspoof_openFromSerialized(const void *data, int32_t length, int32_t *pActualLength,
michael@0 344 UErrorCode *pErrorCode);
michael@0 345
michael@0 346 /**
michael@0 347 * Open a Spoof Checker from the source form of the spoof data.
michael@0 348 * The Three inputs correspond to the Unicode data files confusables.txt
michael@0 349 * confusablesWholeScript.txt and xidmdifications.txt as described in
michael@0 350 * Unicode UAX #39. The syntax of the source data is as described in UAX #39 for
michael@0 351 * these files, and the content of these files is acceptable input.
michael@0 352 *
michael@0 353 * The character encoding of the (char *) input text is UTF-8.
michael@0 354 *
michael@0 355 * @param confusables a pointer to the confusable characters definitions,
michael@0 356 * as found in file confusables.txt from unicode.org.
michael@0 357 * @param confusablesLen The length of the confusables text, or -1 if the
michael@0 358 * input string is zero terminated.
michael@0 359 * @param confusablesWholeScript
michael@0 360 * a pointer to the whole script confusables definitions,
michael@0 361 * as found in the file confusablesWholeScript.txt from unicode.org.
michael@0 362 * @param confusablesWholeScriptLen The length of the whole script confusables text, or
michael@0 363 * -1 if the input string is zero terminated.
michael@0 364 * @param errType In the event of an error in the input, indicates
michael@0 365 * which of the input files contains the error.
michael@0 366 * The value is one of USPOOF_SINGLE_SCRIPT_CONFUSABLE or
michael@0 367 * USPOOF_WHOLE_SCRIPT_CONFUSABLE, or
michael@0 368 * zero if no errors are found.
michael@0 369 * @param pe In the event of an error in the input, receives the position
michael@0 370 * in the input text (line, offset) of the error.
michael@0 371 * @param status an in/out ICU UErrorCode. Among the possible errors is
michael@0 372 * U_PARSE_ERROR, which is used to report syntax errors
michael@0 373 * in the input.
michael@0 374 * @return A spoof checker that uses the rules from the input files.
michael@0 375 * @stable ICU 4.2
michael@0 376 */
michael@0 377 U_STABLE USpoofChecker * U_EXPORT2
michael@0 378 uspoof_openFromSource(const char *confusables, int32_t confusablesLen,
michael@0 379 const char *confusablesWholeScript, int32_t confusablesWholeScriptLen,
michael@0 380 int32_t *errType, UParseError *pe, UErrorCode *status);
michael@0 381
michael@0 382
michael@0 383 /**
michael@0 384 * Close a Spoof Checker, freeing any memory that was being held by
michael@0 385 * its implementation.
michael@0 386 * @stable ICU 4.2
michael@0 387 */
michael@0 388 U_STABLE void U_EXPORT2
michael@0 389 uspoof_close(USpoofChecker *sc);
michael@0 390
michael@0 391 #if U_SHOW_CPLUSPLUS_API
michael@0 392
michael@0 393 U_NAMESPACE_BEGIN
michael@0 394
michael@0 395 /**
michael@0 396 * \class LocalUSpoofCheckerPointer
michael@0 397 * "Smart pointer" class, closes a USpoofChecker via uspoof_close().
michael@0 398 * For most methods see the LocalPointerBase base class.
michael@0 399 *
michael@0 400 * @see LocalPointerBase
michael@0 401 * @see LocalPointer
michael@0 402 * @stable ICU 4.4
michael@0 403 */
michael@0 404 U_DEFINE_LOCAL_OPEN_POINTER(LocalUSpoofCheckerPointer, USpoofChecker, uspoof_close);
michael@0 405
michael@0 406 U_NAMESPACE_END
michael@0 407
michael@0 408 #endif
michael@0 409
michael@0 410 /**
michael@0 411 * Clone a Spoof Checker. The clone will be set to perform the same checks
michael@0 412 * as the original source.
michael@0 413 *
michael@0 414 * @param sc The source USpoofChecker
michael@0 415 * @param status The error code, set if this function encounters a problem.
michael@0 416 * @return
michael@0 417 * @stable ICU 4.2
michael@0 418 */
michael@0 419 U_STABLE USpoofChecker * U_EXPORT2
michael@0 420 uspoof_clone(const USpoofChecker *sc, UErrorCode *status);
michael@0 421
michael@0 422
michael@0 423 /**
michael@0 424 * Specify the set of checks that will be performed by the check
michael@0 425 * functions of this Spoof Checker.
michael@0 426 *
michael@0 427 * @param sc The USpoofChecker
michael@0 428 * @param checks The set of checks that this spoof checker will perform.
michael@0 429 * The value is a bit set, obtained by OR-ing together
michael@0 430 * values from enum USpoofChecks.
michael@0 431 * @param status The error code, set if this function encounters a problem.
michael@0 432 * @stable ICU 4.2
michael@0 433 *
michael@0 434 */
michael@0 435 U_STABLE void U_EXPORT2
michael@0 436 uspoof_setChecks(USpoofChecker *sc, int32_t checks, UErrorCode *status);
michael@0 437
michael@0 438 /**
michael@0 439 * Get the set of checks that this Spoof Checker has been configured to perform.
michael@0 440 *
michael@0 441 * @param sc The USpoofChecker
michael@0 442 * @param status The error code, set if this function encounters a problem.
michael@0 443 * @return The set of checks that this spoof checker will perform.
michael@0 444 * The value is a bit set, obtained by OR-ing together
michael@0 445 * values from enum USpoofChecks.
michael@0 446 * @stable ICU 4.2
michael@0 447 *
michael@0 448 */
michael@0 449 U_STABLE int32_t U_EXPORT2
michael@0 450 uspoof_getChecks(const USpoofChecker *sc, UErrorCode *status);
michael@0 451
michael@0 452 #ifndef U_HIDE_DRAFT_API
michael@0 453 /**
michael@0 454 * Set the loosest restriction level allowed. The default if this function
michael@0 455 * is not called is HIGHLY_RESTRICTIVE.
michael@0 456 * Calling this function also enables the RESTRICTION_LEVEL check.
michael@0 457 * @param restrictionLevel The loosest restriction level allowed.
michael@0 458 * @see URestrictionLevel
michael@0 459 * @draft ICU 51
michael@0 460 */
michael@0 461 U_DRAFT void U_EXPORT2
michael@0 462 uspoof_setRestrictionLevel(USpoofChecker *sc, URestrictionLevel restrictionLevel);
michael@0 463
michael@0 464
michael@0 465 /**
michael@0 466 * Get the Restriction Level that will be tested if the checks include RESTRICTION_LEVEL.
michael@0 467 *
michael@0 468 * @return The restriction level
michael@0 469 * @see URestrictionLevel
michael@0 470 * @draft ICU 51
michael@0 471 */
michael@0 472 U_DRAFT URestrictionLevel U_EXPORT2
michael@0 473 uspoof_getRestrictionLevel(const USpoofChecker *sc);
michael@0 474 #endif /* U_HIDE_DRAFT_API */
michael@0 475
michael@0 476 /**
michael@0 477 * Limit characters that are acceptable in identifiers being checked to those
michael@0 478 * normally used with the languages associated with the specified locales.
michael@0 479 * Any previously specified list of locales is replaced by the new settings.
michael@0 480 *
michael@0 481 * A set of languages is determined from the locale(s), and
michael@0 482 * from those a set of acceptable Unicode scripts is determined.
michael@0 483 * Characters from this set of scripts, along with characters from
michael@0 484 * the "common" and "inherited" Unicode Script categories
michael@0 485 * will be permitted.
michael@0 486 *
michael@0 487 * Supplying an empty string removes all restrictions;
michael@0 488 * characters from any script will be allowed.
michael@0 489 *
michael@0 490 * The USPOOF_CHAR_LIMIT test is automatically enabled for this
michael@0 491 * USpoofChecker when calling this function with a non-empty list
michael@0 492 * of locales.
michael@0 493 *
michael@0 494 * The Unicode Set of characters that will be allowed is accessible
michael@0 495 * via the uspoof_getAllowedChars() function. uspoof_setAllowedLocales()
michael@0 496 * will <i>replace</i> any previously applied set of allowed characters.
michael@0 497 *
michael@0 498 * Adjustments, such as additions or deletions of certain classes of characters,
michael@0 499 * can be made to the result of uspoof_setAllowedLocales() by
michael@0 500 * fetching the resulting set with uspoof_getAllowedChars(),
michael@0 501 * manipulating it with the Unicode Set API, then resetting the
michael@0 502 * spoof detectors limits with uspoof_setAllowedChars()
michael@0 503 *
michael@0 504 * @param sc The USpoofChecker
michael@0 505 * @param localesList A list list of locales, from which the language
michael@0 506 * and associated script are extracted. The locales
michael@0 507 * are comma-separated if there is more than one.
michael@0 508 * White space may not appear within an individual locale,
michael@0 509 * but is ignored otherwise.
michael@0 510 * The locales are syntactically like those from the
michael@0 511 * HTTP Accept-Language header.
michael@0 512 * If the localesList is empty, no restrictions will be placed on
michael@0 513 * the allowed characters.
michael@0 514 *
michael@0 515 * @param status The error code, set if this function encounters a problem.
michael@0 516 * @stable ICU 4.2
michael@0 517 */
michael@0 518 U_STABLE void U_EXPORT2
michael@0 519 uspoof_setAllowedLocales(USpoofChecker *sc, const char *localesList, UErrorCode *status);
michael@0 520
michael@0 521 /**
michael@0 522 * Get a list of locales for the scripts that are acceptable in strings
michael@0 523 * to be checked. If no limitations on scripts have been specified,
michael@0 524 * an empty string will be returned.
michael@0 525 *
michael@0 526 * uspoof_setAllowedChars() will reset the list of allowed to be empty.
michael@0 527 *
michael@0 528 * The format of the returned list is the same as that supplied to
michael@0 529 * uspoof_setAllowedLocales(), but returned list may not be identical
michael@0 530 * to the originally specified string; the string may be reformatted,
michael@0 531 * and information other than languages from
michael@0 532 * the originally specified locales may be omitted.
michael@0 533 *
michael@0 534 * @param sc The USpoofChecker
michael@0 535 * @param status The error code, set if this function encounters a problem.
michael@0 536 * @return A string containing a list of locales corresponding
michael@0 537 * to the acceptable scripts, formatted like an
michael@0 538 * HTTP Accept Language value.
michael@0 539 *
michael@0 540 * @stable ICU 4.2
michael@0 541 */
michael@0 542 U_STABLE const char * U_EXPORT2
michael@0 543 uspoof_getAllowedLocales(USpoofChecker *sc, UErrorCode *status);
michael@0 544
michael@0 545
michael@0 546 /**
michael@0 547 * Limit the acceptable characters to those specified by a Unicode Set.
michael@0 548 * Any previously specified character limit is
michael@0 549 * is replaced by the new settings. This includes limits on
michael@0 550 * characters that were set with the uspoof_setAllowedLocales() function.
michael@0 551 *
michael@0 552 * The USPOOF_CHAR_LIMIT test is automatically enabled for this
michael@0 553 * USpoofChecker by this function.
michael@0 554 *
michael@0 555 * @param sc The USpoofChecker
michael@0 556 * @param chars A Unicode Set containing the list of
michael@0 557 * characters that are permitted. Ownership of the set
michael@0 558 * remains with the caller. The incoming set is cloned by
michael@0 559 * this function, so there are no restrictions on modifying
michael@0 560 * or deleting the USet after calling this function.
michael@0 561 * @param status The error code, set if this function encounters a problem.
michael@0 562 * @stable ICU 4.2
michael@0 563 */
michael@0 564 U_STABLE void U_EXPORT2
michael@0 565 uspoof_setAllowedChars(USpoofChecker *sc, const USet *chars, UErrorCode *status);
michael@0 566
michael@0 567
michael@0 568 /**
michael@0 569 * Get a USet for the characters permitted in an identifier.
michael@0 570 * This corresponds to the limits imposed by the Set Allowed Characters
michael@0 571 * functions. Limitations imposed by other checks will not be
michael@0 572 * reflected in the set returned by this function.
michael@0 573 *
michael@0 574 * The returned set will be frozen, meaning that it cannot be modified
michael@0 575 * by the caller.
michael@0 576 *
michael@0 577 * Ownership of the returned set remains with the Spoof Detector. The
michael@0 578 * returned set will become invalid if the spoof detector is closed,
michael@0 579 * or if a new set of allowed characters is specified.
michael@0 580 *
michael@0 581 *
michael@0 582 * @param sc The USpoofChecker
michael@0 583 * @param status The error code, set if this function encounters a problem.
michael@0 584 * @return A USet containing the characters that are permitted by
michael@0 585 * the USPOOF_CHAR_LIMIT test.
michael@0 586 * @stable ICU 4.2
michael@0 587 */
michael@0 588 U_STABLE const USet * U_EXPORT2
michael@0 589 uspoof_getAllowedChars(const USpoofChecker *sc, UErrorCode *status);
michael@0 590
michael@0 591
michael@0 592 #if U_SHOW_CPLUSPLUS_API
michael@0 593 /**
michael@0 594 * Limit the acceptable characters to those specified by a Unicode Set.
michael@0 595 * Any previously specified character limit is
michael@0 596 * is replaced by the new settings. This includes limits on
michael@0 597 * characters that were set with the uspoof_setAllowedLocales() function.
michael@0 598 *
michael@0 599 * The USPOOF_CHAR_LIMIT test is automatically enabled for this
michael@0 600 * USoofChecker by this function.
michael@0 601 *
michael@0 602 * @param sc The USpoofChecker
michael@0 603 * @param chars A Unicode Set containing the list of
michael@0 604 * characters that are permitted. Ownership of the set
michael@0 605 * remains with the caller. The incoming set is cloned by
michael@0 606 * this function, so there are no restrictions on modifying
michael@0 607 * or deleting the UnicodeSet after calling this function.
michael@0 608 * @param status The error code, set if this function encounters a problem.
michael@0 609 * @stable ICU 4.2
michael@0 610 */
michael@0 611 U_STABLE void U_EXPORT2
michael@0 612 uspoof_setAllowedUnicodeSet(USpoofChecker *sc, const icu::UnicodeSet *chars, UErrorCode *status);
michael@0 613
michael@0 614
michael@0 615 /**
michael@0 616 * Get a UnicodeSet for the characters permitted in an identifier.
michael@0 617 * This corresponds to the limits imposed by the Set Allowed Characters /
michael@0 618 * UnicodeSet functions. Limitations imposed by other checks will not be
michael@0 619 * reflected in the set returned by this function.
michael@0 620 *
michael@0 621 * The returned set will be frozen, meaning that it cannot be modified
michael@0 622 * by the caller.
michael@0 623 *
michael@0 624 * Ownership of the returned set remains with the Spoof Detector. The
michael@0 625 * returned set will become invalid if the spoof detector is closed,
michael@0 626 * or if a new set of allowed characters is specified.
michael@0 627 *
michael@0 628 *
michael@0 629 * @param sc The USpoofChecker
michael@0 630 * @param status The error code, set if this function encounters a problem.
michael@0 631 * @return A UnicodeSet containing the characters that are permitted by
michael@0 632 * the USPOOF_CHAR_LIMIT test.
michael@0 633 * @stable ICU 4.2
michael@0 634 */
michael@0 635 U_STABLE const icu::UnicodeSet * U_EXPORT2
michael@0 636 uspoof_getAllowedUnicodeSet(const USpoofChecker *sc, UErrorCode *status);
michael@0 637 #endif
michael@0 638
michael@0 639
michael@0 640 /**
michael@0 641 * Check the specified string for possible security issues.
michael@0 642 * The text to be checked will typically be an identifier of some sort.
michael@0 643 * The set of checks to be performed is specified with uspoof_setChecks().
michael@0 644 *
michael@0 645 * @param sc The USpoofChecker
michael@0 646 * @param id The identifier to be checked for possible security issues,
michael@0 647 * in UTF-16 format.
michael@0 648 * @param length the length of the string to be checked, expressed in
michael@0 649 * 16 bit UTF-16 code units, or -1 if the string is
michael@0 650 * zero terminated.
michael@0 651 * @param position An out parameter.
michael@0 652 * Originally, the index of the first string position that failed a check.
michael@0 653 * Now, always returns zero.
michael@0 654 * This parameter may be null.
michael@0 655 * @param status The error code, set if an error occurred while attempting to
michael@0 656 * perform the check.
michael@0 657 * Spoofing or security issues detected with the input string are
michael@0 658 * not reported here, but through the function's return value.
michael@0 659 * @return An integer value with bits set for any potential security
michael@0 660 * or spoofing issues detected. The bits are defined by
michael@0 661 * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
michael@0 662 * will be zero if the input string passes all of the
michael@0 663 * enabled checks.
michael@0 664 * @stable ICU 4.2
michael@0 665 */
michael@0 666 U_STABLE int32_t U_EXPORT2
michael@0 667 uspoof_check(const USpoofChecker *sc,
michael@0 668 const UChar *id, int32_t length,
michael@0 669 int32_t *position,
michael@0 670 UErrorCode *status);
michael@0 671
michael@0 672
michael@0 673 /**
michael@0 674 * Check the specified string for possible security issues.
michael@0 675 * The text to be checked will typically be an identifier of some sort.
michael@0 676 * The set of checks to be performed is specified with uspoof_setChecks().
michael@0 677 *
michael@0 678 * @param sc The USpoofChecker
michael@0 679 * @param id A identifier to be checked for possible security issues, in UTF8 format.
michael@0 680 * @param length the length of the string to be checked, or -1 if the string is
michael@0 681 * zero terminated.
michael@0 682 * @param position An out parameter.
michael@0 683 * Originally, the index of the first string position that failed a check.
michael@0 684 * Now, always returns zero.
michael@0 685 * This parameter may be null.
michael@0 686 * @deprecated ICU 51
michael@0 687 * @param status The error code, set if an error occurred while attempting to
michael@0 688 * perform the check.
michael@0 689 * Spoofing or security issues detected with the input string are
michael@0 690 * not reported here, but through the function's return value.
michael@0 691 * If the input contains invalid UTF-8 sequences,
michael@0 692 * a status of U_INVALID_CHAR_FOUND will be returned.
michael@0 693 * @return An integer value with bits set for any potential security
michael@0 694 * or spoofing issues detected. The bits are defined by
michael@0 695 * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
michael@0 696 * will be zero if the input string passes all of the
michael@0 697 * enabled checks.
michael@0 698 * @stable ICU 4.2
michael@0 699 */
michael@0 700 U_STABLE int32_t U_EXPORT2
michael@0 701 uspoof_checkUTF8(const USpoofChecker *sc,
michael@0 702 const char *id, int32_t length,
michael@0 703 int32_t *position,
michael@0 704 UErrorCode *status);
michael@0 705
michael@0 706
michael@0 707 #if U_SHOW_CPLUSPLUS_API
michael@0 708 /**
michael@0 709 * Check the specified string for possible security issues.
michael@0 710 * The text to be checked will typically be an identifier of some sort.
michael@0 711 * The set of checks to be performed is specified with uspoof_setChecks().
michael@0 712 *
michael@0 713 * @param sc The USpoofChecker
michael@0 714 * @param id A identifier to be checked for possible security issues.
michael@0 715 * @param position An out parameter.
michael@0 716 * Originally, the index of the first string position that failed a check.
michael@0 717 * Now, always returns zero.
michael@0 718 * This parameter may be null.
michael@0 719 * @deprecated ICU 51
michael@0 720 * @param status The error code, set if an error occurred while attempting to
michael@0 721 * perform the check.
michael@0 722 * Spoofing or security issues detected with the input string are
michael@0 723 * not reported here, but through the function's return value.
michael@0 724 * @return An integer value with bits set for any potential security
michael@0 725 * or spoofing issues detected. The bits are defined by
michael@0 726 * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
michael@0 727 * will be zero if the input string passes all of the
michael@0 728 * enabled checks.
michael@0 729 * @stable ICU 4.2
michael@0 730 */
michael@0 731 U_STABLE int32_t U_EXPORT2
michael@0 732 uspoof_checkUnicodeString(const USpoofChecker *sc,
michael@0 733 const icu::UnicodeString &id,
michael@0 734 int32_t *position,
michael@0 735 UErrorCode *status);
michael@0 736
michael@0 737 #endif
michael@0 738
michael@0 739
michael@0 740 /**
michael@0 741 * Check the whether two specified strings are visually confusable.
michael@0 742 * The types of confusability to be tested - single script, mixed script,
michael@0 743 * or whole script - are determined by the check options set for the
michael@0 744 * USpoofChecker.
michael@0 745 *
michael@0 746 * The tests to be performed are controlled by the flags
michael@0 747 * USPOOF_SINGLE_SCRIPT_CONFUSABLE
michael@0 748 * USPOOF_MIXED_SCRIPT_CONFUSABLE
michael@0 749 * USPOOF_WHOLE_SCRIPT_CONFUSABLE
michael@0 750 * At least one of these tests must be selected.
michael@0 751 *
michael@0 752 * USPOOF_ANY_CASE is a modifier for the tests. Select it if the identifiers
michael@0 753 * may be of mixed case.
michael@0 754 * If identifiers are case folded for comparison and
michael@0 755 * display to the user, do not select the USPOOF_ANY_CASE option.
michael@0 756 *
michael@0 757 *
michael@0 758 * @param sc The USpoofChecker
michael@0 759 * @param id1 The first of the two identifiers to be compared for
michael@0 760 * confusability. The strings are in UTF-16 format.
michael@0 761 * @param length1 the length of the first identifer, expressed in
michael@0 762 * 16 bit UTF-16 code units, or -1 if the string is
michael@0 763 * nul terminated.
michael@0 764 * @param id2 The second of the two identifiers to be compared for
michael@0 765 * confusability. The identifiers are in UTF-16 format.
michael@0 766 * @param length2 The length of the second identifiers, expressed in
michael@0 767 * 16 bit UTF-16 code units, or -1 if the string is
michael@0 768 * nul terminated.
michael@0 769 * @param status The error code, set if an error occurred while attempting to
michael@0 770 * perform the check.
michael@0 771 * Confusability of the identifiers is not reported here,
michael@0 772 * but through this function's return value.
michael@0 773 * @return An integer value with bit(s) set corresponding to
michael@0 774 * the type of confusability found, as defined by
michael@0 775 * enum USpoofChecks. Zero is returned if the identifiers
michael@0 776 * are not confusable.
michael@0 777 * @stable ICU 4.2
michael@0 778 */
michael@0 779 U_STABLE int32_t U_EXPORT2
michael@0 780 uspoof_areConfusable(const USpoofChecker *sc,
michael@0 781 const UChar *id1, int32_t length1,
michael@0 782 const UChar *id2, int32_t length2,
michael@0 783 UErrorCode *status);
michael@0 784
michael@0 785
michael@0 786
michael@0 787 /**
michael@0 788 * Check the whether two specified strings are visually confusable.
michael@0 789 * The types of confusability to be tested - single script, mixed script,
michael@0 790 * or whole script - are determined by the check options set for the
michael@0 791 * USpoofChecker.
michael@0 792 *
michael@0 793 * @param sc The USpoofChecker
michael@0 794 * @param id1 The first of the two identifiers to be compared for
michael@0 795 * confusability. The strings are in UTF-8 format.
michael@0 796 * @param length1 the length of the first identifiers, in bytes, or -1
michael@0 797 * if the string is nul terminated.
michael@0 798 * @param id2 The second of the two identifiers to be compared for
michael@0 799 * confusability. The strings are in UTF-8 format.
michael@0 800 * @param length2 The length of the second string in bytes, or -1
michael@0 801 * if the string is nul terminated.
michael@0 802 * @param status The error code, set if an error occurred while attempting to
michael@0 803 * perform the check.
michael@0 804 * Confusability of the strings is not reported here,
michael@0 805 * but through this function's return value.
michael@0 806 * @return An integer value with bit(s) set corresponding to
michael@0 807 * the type of confusability found, as defined by
michael@0 808 * enum USpoofChecks. Zero is returned if the strings
michael@0 809 * are not confusable.
michael@0 810 * @stable ICU 4.2
michael@0 811 */
michael@0 812 U_STABLE int32_t U_EXPORT2
michael@0 813 uspoof_areConfusableUTF8(const USpoofChecker *sc,
michael@0 814 const char *id1, int32_t length1,
michael@0 815 const char *id2, int32_t length2,
michael@0 816 UErrorCode *status);
michael@0 817
michael@0 818
michael@0 819
michael@0 820
michael@0 821 #if U_SHOW_CPLUSPLUS_API
michael@0 822 /**
michael@0 823 * Check the whether two specified strings are visually confusable.
michael@0 824 * The types of confusability to be tested - single script, mixed script,
michael@0 825 * or whole script - are determined by the check options set for the
michael@0 826 * USpoofChecker.
michael@0 827 *
michael@0 828 * @param sc The USpoofChecker
michael@0 829 * @param s1 The first of the two identifiers to be compared for
michael@0 830 * confusability. The strings are in UTF-8 format.
michael@0 831 * @param s2 The second of the two identifiers to be compared for
michael@0 832 * confusability. The strings are in UTF-8 format.
michael@0 833 * @param status The error code, set if an error occurred while attempting to
michael@0 834 * perform the check.
michael@0 835 * Confusability of the identifiers is not reported here,
michael@0 836 * but through this function's return value.
michael@0 837 * @return An integer value with bit(s) set corresponding to
michael@0 838 * the type of confusability found, as defined by
michael@0 839 * enum USpoofChecks. Zero is returned if the identifiers
michael@0 840 * are not confusable.
michael@0 841 * @stable ICU 4.2
michael@0 842 */
michael@0 843 U_STABLE int32_t U_EXPORT2
michael@0 844 uspoof_areConfusableUnicodeString(const USpoofChecker *sc,
michael@0 845 const icu::UnicodeString &s1,
michael@0 846 const icu::UnicodeString &s2,
michael@0 847 UErrorCode *status);
michael@0 848 #endif
michael@0 849
michael@0 850
michael@0 851 /**
michael@0 852 * Get the "skeleton" for an identifier.
michael@0 853 * Skeletons are a transformation of the input identifier;
michael@0 854 * Two identifiers are confusable if their skeletons are identical.
michael@0 855 * See Unicode UAX #39 for additional information.
michael@0 856 *
michael@0 857 * Using skeletons directly makes it possible to quickly check
michael@0 858 * whether an identifier is confusable with any of some large
michael@0 859 * set of existing identifiers, by creating an efficiently
michael@0 860 * searchable collection of the skeletons.
michael@0 861 *
michael@0 862 * @param sc The USpoofChecker
michael@0 863 * @param type The type of skeleton, corresponding to which
michael@0 864 * of the Unicode confusable data tables to use.
michael@0 865 * The default is Mixed-Script, Lowercase.
michael@0 866 * Allowed options are USPOOF_SINGLE_SCRIPT_CONFUSABLE and
michael@0 867 * USPOOF_ANY_CASE_CONFUSABLE. The two flags may be ORed.
michael@0 868 * @param id The input identifier whose skeleton will be computed.
michael@0 869 * @param length The length of the input identifier, expressed in 16 bit
michael@0 870 * UTF-16 code units, or -1 if the string is zero terminated.
michael@0 871 * @param dest The output buffer, to receive the skeleton string.
michael@0 872 * @param destCapacity The length of the output buffer, in 16 bit units.
michael@0 873 * The destCapacity may be zero, in which case the function will
michael@0 874 * return the actual length of the skeleton.
michael@0 875 * @param status The error code, set if an error occurred while attempting to
michael@0 876 * perform the check.
michael@0 877 * @return The length of the skeleton string. The returned length
michael@0 878 * is always that of the complete skeleton, even when the
michael@0 879 * supplied buffer is too small (or of zero length)
michael@0 880 *
michael@0 881 * @stable ICU 4.2
michael@0 882 */
michael@0 883 U_STABLE int32_t U_EXPORT2
michael@0 884 uspoof_getSkeleton(const USpoofChecker *sc,
michael@0 885 uint32_t type,
michael@0 886 const UChar *id, int32_t length,
michael@0 887 UChar *dest, int32_t destCapacity,
michael@0 888 UErrorCode *status);
michael@0 889
michael@0 890 /**
michael@0 891 * Get the "skeleton" for an identifier.
michael@0 892 * Skeletons are a transformation of the input identifier;
michael@0 893 * Two identifiers are confusable if their skeletons are identical.
michael@0 894 * See Unicode UAX #39 for additional information.
michael@0 895 *
michael@0 896 * Using skeletons directly makes it possible to quickly check
michael@0 897 * whether an identifier is confusable with any of some large
michael@0 898 * set of existing identifiers, by creating an efficiently
michael@0 899 * searchable collection of the skeletons.
michael@0 900 *
michael@0 901 * @param sc The USpoofChecker
michael@0 902 * @param type The type of skeleton, corresponding to which
michael@0 903 * of the Unicode confusable data tables to use.
michael@0 904 * The default is Mixed-Script, Lowercase.
michael@0 905 * Allowed options are USPOOF_SINGLE_SCRIPT_CONFUSABLE and
michael@0 906 * USPOOF_ANY_CASE. The two flags may be ORed.
michael@0 907 * @param id The UTF-8 format identifier whose skeleton will be computed.
michael@0 908 * @param length The length of the input string, in bytes,
michael@0 909 * or -1 if the string is zero terminated.
michael@0 910 * @param dest The output buffer, to receive the skeleton string.
michael@0 911 * @param destCapacity The length of the output buffer, in bytes.
michael@0 912 * The destCapacity may be zero, in which case the function will
michael@0 913 * return the actual length of the skeleton.
michael@0 914 * @param status The error code, set if an error occurred while attempting to
michael@0 915 * perform the check. Possible Errors include U_INVALID_CHAR_FOUND
michael@0 916 * for invalid UTF-8 sequences, and
michael@0 917 * U_BUFFER_OVERFLOW_ERROR if the destination buffer is too small
michael@0 918 * to hold the complete skeleton.
michael@0 919 * @return The length of the skeleton string, in bytes. The returned length
michael@0 920 * is always that of the complete skeleton, even when the
michael@0 921 * supplied buffer is too small (or of zero length)
michael@0 922 *
michael@0 923 * @stable ICU 4.2
michael@0 924 */
michael@0 925 U_STABLE int32_t U_EXPORT2
michael@0 926 uspoof_getSkeletonUTF8(const USpoofChecker *sc,
michael@0 927 uint32_t type,
michael@0 928 const char *id, int32_t length,
michael@0 929 char *dest, int32_t destCapacity,
michael@0 930 UErrorCode *status);
michael@0 931
michael@0 932 #if U_SHOW_CPLUSPLUS_API
michael@0 933 /**
michael@0 934 * Get the "skeleton" for an identifier.
michael@0 935 * Skeletons are a transformation of the input identifier;
michael@0 936 * Two identifiers are confusable if their skeletons are identical.
michael@0 937 * See Unicode UAX #39 for additional information.
michael@0 938 *
michael@0 939 * Using skeletons directly makes it possible to quickly check
michael@0 940 * whether an identifier is confusable with any of some large
michael@0 941 * set of existing identifiers, by creating an efficiently
michael@0 942 * searchable collection of the skeletons.
michael@0 943 *
michael@0 944 * @param sc The USpoofChecker.
michael@0 945 * @param type The type of skeleton, corresponding to which
michael@0 946 * of the Unicode confusable data tables to use.
michael@0 947 * The default is Mixed-Script, Lowercase.
michael@0 948 * Allowed options are USPOOF_SINGLE_SCRIPT_CONFUSABLE and
michael@0 949 * USPOOF_ANY_CASE_CONFUSABLE. The two flags may be ORed.
michael@0 950 * @param id The input identifier whose skeleton will be computed.
michael@0 951 * @param dest The output identifier, to receive the skeleton string.
michael@0 952 * @param status The error code, set if an error occurred while attempting to
michael@0 953 * perform the check.
michael@0 954 * @return A reference to the destination (skeleton) string.
michael@0 955 *
michael@0 956 * @stable ICU 4.2
michael@0 957 */
michael@0 958 U_I18N_API icu::UnicodeString & U_EXPORT2
michael@0 959 uspoof_getSkeletonUnicodeString(const USpoofChecker *sc,
michael@0 960 uint32_t type,
michael@0 961 const icu::UnicodeString &id,
michael@0 962 icu::UnicodeString &dest,
michael@0 963 UErrorCode *status);
michael@0 964 #endif /* U_SHOW_CPLUSPLUS_API */
michael@0 965
michael@0 966
michael@0 967 #ifndef U_HIDE_DRAFT_API
michael@0 968 /**
michael@0 969 * Get the set of Candidate Characters for Inclusion in Identifiers, as defined
michael@0 970 * in Unicode UAX #31, http://www.unicode.org/reports/tr31/#Table_Candidate_Characters_for_Inclusion_in_Identifiers
michael@0 971 *
michael@0 972 * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
michael@0 973 * be deleted by the caller.
michael@0 974 *
michael@0 975 * @param status The error code, set if a problem occurs while creating the set.
michael@0 976 *
michael@0 977 * @draft ICU 51
michael@0 978 */
michael@0 979 U_DRAFT const USet * U_EXPORT2
michael@0 980 uspoof_getInclusionSet(UErrorCode *status);
michael@0 981
michael@0 982 /**
michael@0 983 * Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined
michael@0 984 * in Unicode UAX #31, http://www.unicode.org/reports/tr31/#Table_Recommended_Scripts
michael@0 985 *
michael@0 986 * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
michael@0 987 * be deleted by the caller.
michael@0 988 *
michael@0 989 * @param status The error code, set if a problem occurs while creating the set.
michael@0 990 *
michael@0 991 * @draft ICU 51
michael@0 992 */
michael@0 993 U_DRAFT const USet * U_EXPORT2
michael@0 994 uspoof_getRecommendedSet(UErrorCode *status);
michael@0 995
michael@0 996 #if U_SHOW_CPLUSPLUS_API
michael@0 997
michael@0 998 /**
michael@0 999 * Get the set of Candidate Characters for Inclusion in Identifiers, as defined
michael@0 1000 * in Unicode UAX #31, http://www.unicode.org/reports/tr31/#Table_Candidate_Characters_for_Inclusion_in_Identifiers
michael@0 1001 *
michael@0 1002 * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
michael@0 1003 * be deleted by the caller.
michael@0 1004 *
michael@0 1005 * @param status The error code, set if a problem occurs while creating the set.
michael@0 1006 *
michael@0 1007 * @draft ICU 51
michael@0 1008 */
michael@0 1009 U_DRAFT const icu::UnicodeSet * U_EXPORT2
michael@0 1010 uspoof_getInclusionUnicodeSet(UErrorCode *status);
michael@0 1011
michael@0 1012 /**
michael@0 1013 * Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined
michael@0 1014 * in Unicode UAX #31, http://www.unicode.org/reports/tr31/#Table_Recommended_Scripts
michael@0 1015 *
michael@0 1016 * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
michael@0 1017 * be deleted by the caller.
michael@0 1018 *
michael@0 1019 * @param status The error code, set if a problem occurs while creating the set.
michael@0 1020 *
michael@0 1021 * @draft ICU 51
michael@0 1022 */
michael@0 1023 U_DRAFT const icu::UnicodeSet * U_EXPORT2
michael@0 1024 uspoof_getRecommendedUnicodeSet(UErrorCode *status);
michael@0 1025
michael@0 1026 #endif /* U_SHOW_CPLUSPLUS_API */
michael@0 1027 #endif /* U_HIDE_DRAFT_API */
michael@0 1028
michael@0 1029 /**
michael@0 1030 * Serialize the data for a spoof detector into a chunk of memory.
michael@0 1031 * The flattened spoof detection tables can later be used to efficiently
michael@0 1032 * instantiate a new Spoof Detector.
michael@0 1033 *
michael@0 1034 * The serialized spoof checker includes only the data compiled from the
michael@0 1035 * Unicode data tables by uspoof_openFromSource(); it does not include
michael@0 1036 * include any other state or configuration that may have been set.
michael@0 1037 *
michael@0 1038 * @param sc the Spoof Detector whose data is to be serialized.
michael@0 1039 * @param data a pointer to 32-bit-aligned memory to be filled with the data,
michael@0 1040 * can be NULL if capacity==0
michael@0 1041 * @param capacity the number of bytes available at data,
michael@0 1042 * or 0 for preflighting
michael@0 1043 * @param status an in/out ICU UErrorCode; possible errors include:
michael@0 1044 * - U_BUFFER_OVERFLOW_ERROR if the data storage block is too small for serialization
michael@0 1045 * - U_ILLEGAL_ARGUMENT_ERROR the data or capacity parameters are bad
michael@0 1046 * @return the number of bytes written or needed for the spoof data
michael@0 1047 *
michael@0 1048 * @see utrie2_openFromSerialized()
michael@0 1049 * @stable ICU 4.2
michael@0 1050 */
michael@0 1051 U_STABLE int32_t U_EXPORT2
michael@0 1052 uspoof_serialize(USpoofChecker *sc,
michael@0 1053 void *data, int32_t capacity,
michael@0 1054 UErrorCode *status);
michael@0 1055
michael@0 1056
michael@0 1057 #endif
michael@0 1058
michael@0 1059 #endif /* USPOOF_H */

mercurial