intl/icu/source/i18n/unicode/uspoof.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/unicode/uspoof.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1059 @@
     1.4 +/*
     1.5 +***************************************************************************
     1.6 +* Copyright (C) 2008-2013, International Business Machines Corporation
     1.7 +* and others. All Rights Reserved.
     1.8 +***************************************************************************
     1.9 +*   file name:  uspoof.h
    1.10 +*   encoding:   US-ASCII
    1.11 +*   tab size:   8 (not used)
    1.12 +*   indentation:4
    1.13 +*
    1.14 +*   created on: 2008Feb13
    1.15 +*   created by: Andy Heninger
    1.16 +*
    1.17 +*   Unicode Spoof Detection
    1.18 +*/
    1.19 +
    1.20 +#ifndef USPOOF_H
    1.21 +#define USPOOF_H
    1.22 +
    1.23 +#include "unicode/utypes.h"
    1.24 +#include "unicode/uset.h"
    1.25 +#include "unicode/parseerr.h"
    1.26 +#include "unicode/localpointer.h"
    1.27 +
    1.28 +#if !UCONFIG_NO_NORMALIZATION
    1.29 +
    1.30 +
    1.31 +#if U_SHOW_CPLUSPLUS_API
    1.32 +#include "unicode/unistr.h"
    1.33 +#include "unicode/uniset.h"
    1.34 +#endif
    1.35 +
    1.36 +
    1.37 +/**
    1.38 + * \file
    1.39 + * \brief Unicode Security and Spoofing Detection, C API.
    1.40 + *
    1.41 + * These functions are intended to check strings, typically
    1.42 + * identifiers of some type, such as URLs, for the presence of
    1.43 + * characters that are likely to be visually confusing - 
    1.44 + * for cases where the displayed form of an identifier may
    1.45 + * not be what it appears to be.
    1.46 + *
    1.47 + * Unicode Technical Report #36, http://unicode.org/reports/tr36, and
    1.48 + * Unicode Technical Standard #39, http://unicode.org/reports/tr39
    1.49 + * "Unicode security considerations", give more background on 
    1.50 + * security an spoofing issues with Unicode identifiers.
    1.51 + * The tests and checks provided by this module implement the recommendations
    1.52 + * from those Unicode documents.
    1.53 + *
    1.54 + * The tests available on identifiers fall into two general categories:
    1.55 + *   -#  Single identifier tests.  Check whether an identifier is
    1.56 + *       potentially confusable with any other string, or is suspicious
    1.57 + *       for other reasons.
    1.58 + *   -#  Two identifier tests.  Check whether two specific identifiers are confusable.
    1.59 + *       This does not consider whether either of strings is potentially
    1.60 + *       confusable with any string other than the exact one specified.
    1.61 + *
    1.62 + * The steps to perform confusability testing are
    1.63 + *   -#  Open a USpoofChecker.
    1.64 + *   -#  Configure the USPoofChecker for the desired set of tests.  The tests that will
    1.65 + *       be performed are specified by a set of USpoofChecks flags.
    1.66 + *   -#  Perform the checks using the pre-configured USpoofChecker.  The results indicate
    1.67 + *       which (if any) of the selected tests have identified possible problems with the identifier.
    1.68 + *       Results are reported as a set of USpoofChecks flags;  this mirrors the form in which
    1.69 + *       the set of tests to perform was originally specified to the USpoofChecker.
    1.70 + *
    1.71 + * A USpoofChecker may be used repeatedly to perform checks on any number of identifiers.
    1.72 + *
    1.73 + * Thread Safety: The test functions for checking a single identifier, or for testing 
    1.74 + * whether two identifiers are possible confusable, are thread safe.  
    1.75 + * They may called concurrently, from multiple threads, using the same USpoofChecker instance.
    1.76 + *
    1.77 + * More generally, the standard ICU thread safety rules apply:  functions that take a
    1.78 + * const USpoofChecker parameter are thread safe.  Those that take a non-const 
    1.79 + * USpoofChecier are not thread safe.
    1.80 + *
    1.81 + *
    1.82 + * Descriptions of the available checks.
    1.83 + *
    1.84 + * When testing whether pairs of identifiers are confusable, with the uspoof_areConfusable()
    1.85 + * family of functions, the relevant tests are
    1.86 + *
    1.87 + *   -# USPOOF_SINGLE_SCRIPT_CONFUSABLE:  All of the characters from the two identifiers are
    1.88 + *      from a single script, and the two identifiers are visually confusable.
    1.89 + *   -# USPOOF_MIXED_SCRIPT_CONFUSABLE:  At least one of the identifiers contains characters
    1.90 + *      from more than one script, and the two identifiers are visually confusable.
    1.91 + *   -# USPOOF_WHOLE_SCRIPT_CONFUSABLE: Each of the two identifiers is of a single script, but
    1.92 + *      the two identifiers are from different scripts, and they are visually confusable.
    1.93 + *
    1.94 + * The safest approach is to enable all three of these checks as a group.
    1.95 + *
    1.96 + * USPOOF_ANY_CASE is a modifier for the above tests.  If the identifiers being checked can
    1.97 + * be of mixed case and are used in a case-sensitive manner, this option should be specified.
    1.98 + *
    1.99 + * If the identifiers being checked are used in a case-insensitive manner, and if they are
   1.100 + * displayed to users in lower-case form only, the USPOOF_ANY_CASE option should not be
   1.101 + * specified.  Confusabality issues involving upper case letters will not be reported.
   1.102 + *
   1.103 + * When performing tests on a single identifier, with the uspoof_check() family of functions,
   1.104 + * the relevant tests are:
   1.105 + *
   1.106 + *    -# USPOOF_MIXED_SCRIPT_CONFUSABLE: the identifier contains characters from multiple
   1.107 + *       scripts, and there exists an identifier of a single script that is visually confusable.
   1.108 + *    -# USPOOF_WHOLE_SCRIPT_CONFUSABLE: the identifier consists of characters from a single
   1.109 + *       script, and there exists a visually confusable identifier.
   1.110 + *       The visually confusable identifier also consists of characters from a single script.
   1.111 + *       but not the same script as the identifier being checked.
   1.112 + *    -# USPOOF_ANY_CASE: modifies the mixed script and whole script confusables tests.  If
   1.113 + *       specified, the checks will consider confusable characters of any case.  If this flag is not
   1.114 + *       set, the test is performed assuming case folded identifiers.
   1.115 + *    -# USPOOF_SINGLE_SCRIPT: check that the identifier contains only characters from a
   1.116 + *       single script.  (Characters from the 'common' and 'inherited' scripts are ignored.)
   1.117 + *       This is not a test for confusable identifiers
   1.118 + *    -# USPOOF_INVISIBLE: check an identifier for the presence of invisible characters,
   1.119 + *       such as zero-width spaces, or character sequences that are
   1.120 + *       likely not to display, such as multiple occurrences of the same
   1.121 + *       non-spacing mark.  This check does not test the input string as a whole
   1.122 + *       for conformance to any particular syntax for identifiers.
   1.123 + *    -# USPOOF_CHAR_LIMIT: check that an identifier contains only characters from a specified set
   1.124 + *       of acceptable characters.  See uspoof_setAllowedChars() and
   1.125 + *       uspoof_setAllowedLocales().
   1.126 + *
   1.127 + *  Note on Scripts:
   1.128 + *     Characters from the Unicode Scripts "Common" and "Inherited" are ignored when considering
   1.129 + *     the script of an identifier. Common characters include digits and symbols that
   1.130 + *     are normally used with text from more than one script.
   1.131 + *
   1.132 + *  Identifier Skeletons:  A skeleton is a transformation of an identifier, such that
   1.133 + *  all identifiers that are confusable with each other have the same skeleton.
   1.134 + *  Using skeletons, it is possible to build a dictionary data structure for
   1.135 + *  a set of identifiers, and then quickly test whether a new identifier is
   1.136 + *  confusable with an identifier already in the set.  The uspoof_getSkeleton()
   1.137 + *  family of functions will produce the skeleton from an identifier.
   1.138 + *
   1.139 + *  Note that skeletons are not guaranteed to be stable between versions 
   1.140 + *  of Unicode or ICU, so an applications should not rely on creating a permanent,
   1.141 + *  or difficult to update, database of skeletons.  Instabilities result from
   1.142 + *  identifying new pairs or sequences of characters that are visually
   1.143 + *  confusable, and thus must be mapped to the same skeleton character(s).
   1.144 + *
   1.145 + */
   1.146 +
   1.147 +struct USpoofChecker;
   1.148 +typedef struct USpoofChecker USpoofChecker; /**< typedef for C of USpoofChecker */
   1.149 +
   1.150 +/**
   1.151 + * Enum for the kinds of checks that USpoofChecker can perform.
   1.152 + * These enum values are used both to select the set of checks that
   1.153 + * will be performed, and to report results from the check function.
   1.154 + *
   1.155 + * @stable ICU 4.2
   1.156 + */
   1.157 +typedef enum USpoofChecks {
   1.158 +    /**   Single script confusable test.
   1.159 +      *   When testing whether two identifiers are confusable, report that they are if
   1.160 +      *   both are from the same script and they are visually confusable.
   1.161 +      *   Note: this test is not applicable to a check of a single identifier.
   1.162 +      */
   1.163 +    USPOOF_SINGLE_SCRIPT_CONFUSABLE =   1,
   1.164 +
   1.165 +    /** Mixed script confusable test.
   1.166 +     *  When checking a single identifier, report a problem if
   1.167 +     *    the identifier contains multiple scripts, and
   1.168 +     *    is confusable with some other identifier in a single script
   1.169 +     *  When testing whether two identifiers are confusable, report that they are if
   1.170 +     *    the two IDs are visually confusable, 
   1.171 +     *    and at least one contains characters from more than one script.
   1.172 +     */
   1.173 +    USPOOF_MIXED_SCRIPT_CONFUSABLE  =   2,
   1.174 +
   1.175 +    /** Whole script confusable test.
   1.176 +     *  When checking a single identifier, report a problem if
   1.177 +     *    The identifier is of a single script, and
   1.178 +     *    there exists a confusable identifier in another script.
   1.179 +     *  When testing whether two identifiers are confusable, report that they are if
   1.180 +     *    each is of a single script, 
   1.181 +     *    the scripts of the two identifiers are different, and
   1.182 +     *    the identifiers are visually confusable.
   1.183 +     */
   1.184 +    USPOOF_WHOLE_SCRIPT_CONFUSABLE  =   4,
   1.185 +    
   1.186 +    /** Any Case Modifier for confusable identifier tests.
   1.187 +        If specified, consider all characters, of any case, when looking for confusables.
   1.188 +        If USPOOF_ANY_CASE is not specified, identifiers being checked are assumed to have been
   1.189 +        case folded.  Upper case confusable characters will not be checked.
   1.190 +        Selects between Lower Case Confusable and
   1.191 +        Any Case Confusable.   */
   1.192 +    USPOOF_ANY_CASE                 =   8,
   1.193 +
   1.194 +    /**
   1.195 +      * Check that an identifier is no looser than the specified RestrictionLevel.
   1.196 +      * The default if uspoof_setRestrctionLevel() is not called is HIGHLY_RESTRICTIVE.
   1.197 +      *
   1.198 +      * If USPOOF_AUX_INFO is enabled the actual restriction level of the
   1.199 +      * identifier being tested will also be returned by uspoof_check().
   1.200 +      *
   1.201 +      * @see URestrictionLevel
   1.202 +      * @see uspoof_setRestrictionLevel
   1.203 +      * @see USPOOF_AUX_INFO
   1.204 +      *
   1.205 +      * @stable ICU 51
   1.206 +      */
   1.207 +    USPOOF_RESTRICTION_LEVEL        = 16,
   1.208 +
   1.209 +#ifndef U_HIDE_DEPRECATED_API 
   1.210 +    /** Check that an identifier contains only characters from a
   1.211 +      * single script (plus chars from the common and inherited scripts.)
   1.212 +      * Applies to checks of a single identifier check only.
   1.213 +      * @deprecated ICU 51  Use RESTRICTION_LEVEL instead.
   1.214 +      */
   1.215 +    USPOOF_SINGLE_SCRIPT            =  USPOOF_RESTRICTION_LEVEL,
   1.216 +#endif  /* U_HIDE_DEPRECATED_API */
   1.217 +   
   1.218 +    /** Check an identifier for the presence of invisible characters,
   1.219 +      * such as zero-width spaces, or character sequences that are
   1.220 +      * likely not to display, such as multiple occurrences of the same
   1.221 +      * non-spacing mark.  This check does not test the input string as a whole
   1.222 +      * for conformance to any particular syntax for identifiers.
   1.223 +      */
   1.224 +    USPOOF_INVISIBLE                =  32,
   1.225 +
   1.226 +    /** Check that an identifier contains only characters from a specified set
   1.227 +      * of acceptable characters.  See uspoof_setAllowedChars() and
   1.228 +      * uspoof_setAllowedLocales().
   1.229 +      */
   1.230 +    USPOOF_CHAR_LIMIT               =  64,
   1.231 +
   1.232 +#ifndef U_HIDE_DRAFT_API
   1.233 +   /**
   1.234 +     * Check that an identifier does not include decimal digits from
   1.235 +     * more than one numbering system.
   1.236 +     * 
   1.237 +     * @draft ICU 51
   1.238 +     */
   1.239 +    USPOOF_MIXED_NUMBERS            = 128,
   1.240 +#endif /* U_HIDE_DRAFT_API */
   1.241 +
   1.242 +   /**
   1.243 +     * Enable all spoof checks.
   1.244 +     * 
   1.245 +     * @stable ICU 4.6
   1.246 +     */
   1.247 +    USPOOF_ALL_CHECKS               = 0xFFFF,
   1.248 +
   1.249 +#ifndef U_HIDE_DRAFT_API
   1.250 +    /**
   1.251 +      * Enable the return of auxillary (non-error) information in the
   1.252 +      * upper bits of the check results value. 
   1.253 +      *
   1.254 +      * If this "check" is not enabled, the results of uspoof_check() will be zero when an
   1.255 +      * identifier passes all of the enabled checks.
   1.256 +      *
   1.257 +      * If this "check" is enabled, (uspoof_check() & USPOOF_ALL_CHECKS) will be zero
   1.258 +      * when an identifier passes all checks.
   1.259 +      *
   1.260 +      * @draft ICU 51
   1.261 +      */
   1.262 +    USPOOF_AUX_INFO                  = 0x40000000
   1.263 +#endif /* U_HIDE_DRAFT_API */
   1.264 +
   1.265 +    } USpoofChecks;
   1.266 +    
   1.267 +    
   1.268 +#ifndef U_HIDE_DRAFT_API
   1.269 +    /**
   1.270 +     * Constants from UAX #39 for use in setRestrictionLevel(), and
   1.271 +     * for returned identifier restriction levels in check results.
   1.272 +     * @draft ICU 51
   1.273 +     */
   1.274 +    typedef enum URestrictionLevel {
   1.275 +        /**
   1.276 +         * Only ASCII characters: U+0000..U+007F
   1.277 +         * 
   1.278 +         * @draft ICU 51
   1.279 +         */
   1.280 +        USPOOF_ASCII = 0x10000000,
   1.281 +        /**
   1.282 +         * All characters in each identifier must be from a single script, or from the combinations: Latin + Han +
   1.283 +         * Hiragana + Katakana; Latin + Han + Bopomofo; or Latin + Han + Hangul. Note that this level will satisfy the
   1.284 +         * vast majority of Latin-script users; also that TR36 has ASCII instead of Latin.
   1.285 +         * 
   1.286 +         * @draft ICU 51
   1.287 +         */
   1.288 +        USPOOF_HIGHLY_RESTRICTIVE = 0x20000000,
   1.289 +        /**
   1.290 +         * Allow Latin with other scripts except Cyrillic, Greek, Cherokee Otherwise, the same as Highly Restrictive
   1.291 +         * 
   1.292 +         * @draft ICU 51
   1.293 +         */
   1.294 +        USPOOF_MODERATELY_RESTRICTIVE = 0x30000000,
   1.295 +        /**
   1.296 +         * Allow arbitrary mixtures of scripts. Otherwise, the same as Moderately Restrictive.
   1.297 +         * 
   1.298 +         * @draft ICU 51
   1.299 +         */
   1.300 +        USPOOF_MINIMALLY_RESTRICTIVE = 0x40000000,
   1.301 +        /**
   1.302 +         * Any valid identifiers, including characters outside of the Identifier Profile.
   1.303 +         * 
   1.304 +         * @draft ICU 51
   1.305 +         */
   1.306 +        USPOOF_UNRESTRICTIVE = 0x50000000
   1.307 +    } URestrictionLevel;
   1.308 +#endif /* U_HIDE_DRAFT_API */
   1.309 +
   1.310 +/**
   1.311 + *  Create a Unicode Spoof Checker, configured to perform all 
   1.312 + *  checks except for USPOOF_LOCALE_LIMIT and USPOOF_CHAR_LIMIT.
   1.313 + *  Note that additional checks may be added in the future,
   1.314 + *  resulting in the changes to the default checking behavior.
   1.315 + *
   1.316 + *  @param status  The error code, set if this function encounters a problem.
   1.317 + *  @return        the newly created Spoof Checker
   1.318 + *  @stable ICU 4.2
   1.319 + */
   1.320 +U_STABLE USpoofChecker * U_EXPORT2
   1.321 +uspoof_open(UErrorCode *status);
   1.322 +
   1.323 +
   1.324 +/**
   1.325 + * Open a Spoof checker from its serialized from, stored in 32-bit-aligned memory.
   1.326 + * Inverse of uspoof_serialize().
   1.327 + * The memory containing the serialized data must remain valid and unchanged
   1.328 + * as long as the spoof checker, or any cloned copies of the spoof checker,
   1.329 + * are in use.  Ownership of the memory remains with the caller.
   1.330 + * The spoof checker (and any clones) must be closed prior to deleting the
   1.331 + * serialized data.
   1.332 + *
   1.333 + * @param data a pointer to 32-bit-aligned memory containing the serialized form of spoof data
   1.334 + * @param length the number of bytes available at data;
   1.335 + *               can be more than necessary
   1.336 + * @param pActualLength receives the actual number of bytes at data taken up by the data;
   1.337 + *                      can be NULL
   1.338 + * @param pErrorCode ICU error code
   1.339 + * @return the spoof checker.
   1.340 + *
   1.341 + * @see uspoof_open
   1.342 + * @see uspoof_serialize
   1.343 + * @stable ICU 4.2
   1.344 + */
   1.345 +U_STABLE USpoofChecker * U_EXPORT2
   1.346 +uspoof_openFromSerialized(const void *data, int32_t length, int32_t *pActualLength,
   1.347 +                          UErrorCode *pErrorCode);
   1.348 +
   1.349 +/**
   1.350 +  * Open a Spoof Checker from the source form of the spoof data.
   1.351 +  * The Three inputs correspond to the Unicode data files confusables.txt
   1.352 +  * confusablesWholeScript.txt and xidmdifications.txt as described in
   1.353 +  * Unicode UAX #39.  The syntax of the source data is as described in UAX #39 for
   1.354 +  * these files, and the content of these files is acceptable input.
   1.355 +  *
   1.356 +  * The character encoding of the (char *) input text is UTF-8.
   1.357 +  *
   1.358 +  * @param confusables a pointer to the confusable characters definitions,
   1.359 +  *                    as found in file confusables.txt from unicode.org.
   1.360 +  * @param confusablesLen The length of the confusables text, or -1 if the
   1.361 +  *                    input string is zero terminated.
   1.362 +  * @param confusablesWholeScript
   1.363 +  *                    a pointer to the whole script confusables definitions,
   1.364 +  *                    as found in the file confusablesWholeScript.txt from unicode.org.
   1.365 +  * @param confusablesWholeScriptLen The length of the whole script confusables text, or
   1.366 +  *                    -1 if the input string is zero terminated.
   1.367 +  * @param errType     In the event of an error in the input, indicates
   1.368 +  *                    which of the input files contains the error.
   1.369 +  *                    The value is one of USPOOF_SINGLE_SCRIPT_CONFUSABLE or
   1.370 +  *                    USPOOF_WHOLE_SCRIPT_CONFUSABLE, or
   1.371 +  *                    zero if no errors are found.
   1.372 +  * @param pe          In the event of an error in the input, receives the position
   1.373 +  *                    in the input text (line, offset) of the error.
   1.374 +  * @param status      an in/out ICU UErrorCode.  Among the possible errors is
   1.375 +  *                    U_PARSE_ERROR, which is used to report syntax errors
   1.376 +  *                    in the input.
   1.377 +  * @return            A spoof checker that uses the rules from the input files.
   1.378 +  * @stable ICU 4.2
   1.379 +  */
   1.380 +U_STABLE USpoofChecker * U_EXPORT2
   1.381 +uspoof_openFromSource(const char *confusables,  int32_t confusablesLen,
   1.382 +                      const char *confusablesWholeScript, int32_t confusablesWholeScriptLen,
   1.383 +                      int32_t *errType, UParseError *pe, UErrorCode *status);
   1.384 +
   1.385 +
   1.386 +/**
   1.387 +  * Close a Spoof Checker, freeing any memory that was being held by
   1.388 +  *   its implementation.
   1.389 +  * @stable ICU 4.2
   1.390 +  */
   1.391 +U_STABLE void U_EXPORT2
   1.392 +uspoof_close(USpoofChecker *sc);
   1.393 +
   1.394 +#if U_SHOW_CPLUSPLUS_API
   1.395 +
   1.396 +U_NAMESPACE_BEGIN
   1.397 +
   1.398 +/**
   1.399 + * \class LocalUSpoofCheckerPointer
   1.400 + * "Smart pointer" class, closes a USpoofChecker via uspoof_close().
   1.401 + * For most methods see the LocalPointerBase base class.
   1.402 + *
   1.403 + * @see LocalPointerBase
   1.404 + * @see LocalPointer
   1.405 + * @stable ICU 4.4
   1.406 + */
   1.407 +U_DEFINE_LOCAL_OPEN_POINTER(LocalUSpoofCheckerPointer, USpoofChecker, uspoof_close);
   1.408 +
   1.409 +U_NAMESPACE_END
   1.410 +
   1.411 +#endif
   1.412 +
   1.413 +/**
   1.414 + * Clone a Spoof Checker.  The clone will be set to perform the same checks
   1.415 + *   as the original source.
   1.416 + *
   1.417 + * @param sc       The source USpoofChecker
   1.418 + * @param status   The error code, set if this function encounters a problem.
   1.419 + * @return
   1.420 + * @stable ICU 4.2
   1.421 + */
   1.422 +U_STABLE USpoofChecker * U_EXPORT2
   1.423 +uspoof_clone(const USpoofChecker *sc, UErrorCode *status);
   1.424 +
   1.425 +
   1.426 +/**
   1.427 + * Specify the set of checks that will be performed by the check
   1.428 + * functions of this Spoof Checker.
   1.429 + *
   1.430 + * @param sc       The USpoofChecker
   1.431 + * @param checks         The set of checks that this spoof checker will perform.
   1.432 + *                 The value is a bit set, obtained by OR-ing together
   1.433 + *                 values from enum USpoofChecks.
   1.434 + * @param status   The error code, set if this function encounters a problem.
   1.435 + * @stable ICU 4.2
   1.436 + *
   1.437 + */
   1.438 +U_STABLE void U_EXPORT2
   1.439 +uspoof_setChecks(USpoofChecker *sc, int32_t checks, UErrorCode *status);
   1.440 +
   1.441 +/**
   1.442 + * Get the set of checks that this Spoof Checker has been configured to perform.
   1.443 + * 
   1.444 + * @param sc       The USpoofChecker
   1.445 + * @param status   The error code, set if this function encounters a problem.
   1.446 + * @return         The set of checks that this spoof checker will perform.
   1.447 + *                 The value is a bit set, obtained by OR-ing together
   1.448 + *                 values from enum USpoofChecks.
   1.449 + * @stable ICU 4.2
   1.450 + *
   1.451 + */
   1.452 +U_STABLE int32_t U_EXPORT2
   1.453 +uspoof_getChecks(const USpoofChecker *sc, UErrorCode *status);
   1.454 +
   1.455 +#ifndef U_HIDE_DRAFT_API
   1.456 +/**
   1.457 +  * Set the loosest restriction level allowed. The default if this function 
   1.458 +  * is not called is HIGHLY_RESTRICTIVE.
   1.459 +  * Calling this function also enables the RESTRICTION_LEVEL check.
   1.460 +  * @param restrictionLevel The loosest restriction level allowed.
   1.461 +  * @see URestrictionLevel
   1.462 +  * @draft ICU 51
   1.463 +  */
   1.464 +U_DRAFT void U_EXPORT2
   1.465 +uspoof_setRestrictionLevel(USpoofChecker *sc, URestrictionLevel restrictionLevel);
   1.466 +
   1.467 +
   1.468 +/**
   1.469 +  * Get the Restriction Level that will be tested if the checks include RESTRICTION_LEVEL.
   1.470 +  *
   1.471 +  * @return The restriction level
   1.472 +  * @see URestrictionLevel
   1.473 +  * @draft ICU 51
   1.474 +  */
   1.475 +U_DRAFT URestrictionLevel U_EXPORT2
   1.476 +uspoof_getRestrictionLevel(const USpoofChecker *sc);
   1.477 +#endif /* U_HIDE_DRAFT_API */
   1.478 +
   1.479 +/**
   1.480 + * Limit characters that are acceptable in identifiers being checked to those 
   1.481 + * normally used with the languages associated with the specified locales.
   1.482 + * Any previously specified list of locales is replaced by the new settings.
   1.483 + *
   1.484 + * A set of languages is determined from the locale(s), and
   1.485 + * from those a set of acceptable Unicode scripts is determined.
   1.486 + * Characters from this set of scripts, along with characters from
   1.487 + * the "common" and "inherited" Unicode Script categories
   1.488 + * will be permitted.
   1.489 + *
   1.490 + * Supplying an empty string removes all restrictions;
   1.491 + * characters from any script will be allowed.
   1.492 + *
   1.493 + * The USPOOF_CHAR_LIMIT test is automatically enabled for this
   1.494 + * USpoofChecker when calling this function with a non-empty list
   1.495 + * of locales.
   1.496 + *
   1.497 + * The Unicode Set of characters that will be allowed is accessible
   1.498 + * via the uspoof_getAllowedChars() function.  uspoof_setAllowedLocales()
   1.499 + * will <i>replace</i> any previously applied set of allowed characters.
   1.500 + *
   1.501 + * Adjustments, such as additions or deletions of certain classes of characters,
   1.502 + * can be made to the result of uspoof_setAllowedLocales() by
   1.503 + * fetching the resulting set with uspoof_getAllowedChars(),
   1.504 + * manipulating it with the Unicode Set API, then resetting the
   1.505 + * spoof detectors limits with uspoof_setAllowedChars()
   1.506 + *
   1.507 + * @param sc           The USpoofChecker 
   1.508 + * @param localesList  A list list of locales, from which the language
   1.509 + *                     and associated script are extracted.  The locales
   1.510 + *                     are comma-separated if there is more than one.
   1.511 + *                     White space may not appear within an individual locale,
   1.512 + *                     but is ignored otherwise.
   1.513 + *                     The locales are syntactically like those from the
   1.514 + *                     HTTP Accept-Language header.
   1.515 + *                     If the localesList is empty, no restrictions will be placed on
   1.516 + *                     the allowed characters.
   1.517 + *
   1.518 + * @param status       The error code, set if this function encounters a problem.
   1.519 + * @stable ICU 4.2
   1.520 + */
   1.521 +U_STABLE void U_EXPORT2
   1.522 +uspoof_setAllowedLocales(USpoofChecker *sc, const char *localesList, UErrorCode *status);
   1.523 +
   1.524 +/**
   1.525 + * Get a list of locales for the scripts that are acceptable in strings
   1.526 + *  to be checked.  If no limitations on scripts have been specified,
   1.527 + *  an empty string will be returned.
   1.528 + *
   1.529 + *  uspoof_setAllowedChars() will reset the list of allowed to be empty.
   1.530 + *
   1.531 + *  The format of the returned list is the same as that supplied to 
   1.532 + *  uspoof_setAllowedLocales(), but returned list may not be identical 
   1.533 + *  to the originally specified string; the string may be reformatted, 
   1.534 + *  and information other than languages from
   1.535 + *  the originally specified locales may be omitted.
   1.536 + *
   1.537 + * @param sc           The USpoofChecker 
   1.538 + * @param status       The error code, set if this function encounters a problem.
   1.539 + * @return             A string containing a list of  locales corresponding
   1.540 + *                     to the acceptable scripts, formatted like an
   1.541 + *                     HTTP Accept Language value.
   1.542 + *  
   1.543 + * @stable ICU 4.2
   1.544 + */
   1.545 +U_STABLE const char * U_EXPORT2
   1.546 +uspoof_getAllowedLocales(USpoofChecker *sc, UErrorCode *status);
   1.547 +
   1.548 +
   1.549 +/**
   1.550 + * Limit the acceptable characters to those specified by a Unicode Set.
   1.551 + *   Any previously specified character limit is
   1.552 + *   is replaced by the new settings.  This includes limits on
   1.553 + *   characters that were set with the uspoof_setAllowedLocales() function.
   1.554 + *
   1.555 + * The USPOOF_CHAR_LIMIT test is automatically enabled for this
   1.556 + * USpoofChecker by this function.
   1.557 + *
   1.558 + * @param sc       The USpoofChecker 
   1.559 + * @param chars    A Unicode Set containing the list of
   1.560 + *                 characters that are permitted.  Ownership of the set
   1.561 + *                 remains with the caller.  The incoming set is cloned by
   1.562 + *                 this function, so there are no restrictions on modifying
   1.563 + *                 or deleting the USet after calling this function.
   1.564 + * @param status   The error code, set if this function encounters a problem.
   1.565 + * @stable ICU 4.2
   1.566 + */
   1.567 +U_STABLE void U_EXPORT2
   1.568 +uspoof_setAllowedChars(USpoofChecker *sc, const USet *chars, UErrorCode *status);
   1.569 +
   1.570 +
   1.571 +/**
   1.572 + * Get a USet for the characters permitted in an identifier.
   1.573 + * This corresponds to the limits imposed by the Set Allowed Characters
   1.574 + * functions. Limitations imposed by other checks will not be
   1.575 + * reflected in the set returned by this function.
   1.576 + *
   1.577 + * The returned set will be frozen, meaning that it cannot be modified
   1.578 + * by the caller.
   1.579 + *
   1.580 + * Ownership of the returned set remains with the Spoof Detector.  The
   1.581 + * returned set will become invalid if the spoof detector is closed,
   1.582 + * or if a new set of allowed characters is specified.
   1.583 + *
   1.584 + *
   1.585 + * @param sc       The USpoofChecker 
   1.586 + * @param status   The error code, set if this function encounters a problem.
   1.587 + * @return         A USet containing the characters that are permitted by
   1.588 + *                 the USPOOF_CHAR_LIMIT test.
   1.589 + * @stable ICU 4.2
   1.590 + */
   1.591 +U_STABLE const USet * U_EXPORT2
   1.592 +uspoof_getAllowedChars(const USpoofChecker *sc, UErrorCode *status);
   1.593 +
   1.594 +
   1.595 +#if U_SHOW_CPLUSPLUS_API
   1.596 +/**
   1.597 + * Limit the acceptable characters to those specified by a Unicode Set.
   1.598 + *   Any previously specified character limit is
   1.599 + *   is replaced by the new settings.    This includes limits on
   1.600 + *   characters that were set with the uspoof_setAllowedLocales() function.
   1.601 + *
   1.602 + * The USPOOF_CHAR_LIMIT test is automatically enabled for this
   1.603 + * USoofChecker by this function.
   1.604 + *
   1.605 + * @param sc       The USpoofChecker 
   1.606 + * @param chars    A Unicode Set containing the list of
   1.607 + *                 characters that are permitted.  Ownership of the set
   1.608 + *                 remains with the caller.  The incoming set is cloned by
   1.609 + *                 this function, so there are no restrictions on modifying
   1.610 + *                 or deleting the UnicodeSet after calling this function.
   1.611 + * @param status   The error code, set if this function encounters a problem.
   1.612 + * @stable ICU 4.2
   1.613 + */
   1.614 +U_STABLE void U_EXPORT2
   1.615 +uspoof_setAllowedUnicodeSet(USpoofChecker *sc, const icu::UnicodeSet *chars, UErrorCode *status);
   1.616 +
   1.617 +
   1.618 +/**
   1.619 + * Get a UnicodeSet for the characters permitted in an identifier.
   1.620 + * This corresponds to the limits imposed by the Set Allowed Characters / 
   1.621 + * UnicodeSet functions. Limitations imposed by other checks will not be
   1.622 + * reflected in the set returned by this function.
   1.623 + *
   1.624 + * The returned set will be frozen, meaning that it cannot be modified
   1.625 + * by the caller.
   1.626 + *
   1.627 + * Ownership of the returned set remains with the Spoof Detector.  The
   1.628 + * returned set will become invalid if the spoof detector is closed,
   1.629 + * or if a new set of allowed characters is specified.
   1.630 + *
   1.631 + *
   1.632 + * @param sc       The USpoofChecker 
   1.633 + * @param status   The error code, set if this function encounters a problem.
   1.634 + * @return         A UnicodeSet containing the characters that are permitted by
   1.635 + *                 the USPOOF_CHAR_LIMIT test.
   1.636 + * @stable ICU 4.2
   1.637 + */
   1.638 +U_STABLE const icu::UnicodeSet * U_EXPORT2
   1.639 +uspoof_getAllowedUnicodeSet(const USpoofChecker *sc, UErrorCode *status);
   1.640 +#endif
   1.641 +
   1.642 +
   1.643 +/**
   1.644 + * Check the specified string for possible security issues.
   1.645 + * The text to be checked will typically be an identifier of some sort.
   1.646 + * The set of checks to be performed is specified with uspoof_setChecks().
   1.647 + * 
   1.648 + * @param sc      The USpoofChecker 
   1.649 + * @param id      The identifier to be checked for possible security issues,
   1.650 + *                in UTF-16 format.
   1.651 + * @param length  the length of the string to be checked, expressed in
   1.652 + *                16 bit UTF-16 code units, or -1 if the string is 
   1.653 + *                zero terminated.
   1.654 + * @param position      An out parameter.
   1.655 + *                Originally, the index of the first string position that failed a check.
   1.656 + *                Now, always returns zero.
   1.657 + *                This parameter may be null.
   1.658 + * @param status  The error code, set if an error occurred while attempting to
   1.659 + *                perform the check.
   1.660 + *                Spoofing or security issues detected with the input string are
   1.661 + *                not reported here, but through the function's return value.
   1.662 + * @return        An integer value with bits set for any potential security
   1.663 + *                or spoofing issues detected.  The bits are defined by
   1.664 + *                enum USpoofChecks.  (returned_value & USPOOF_ALL_CHECKS)
   1.665 + *                will be zero if the input string passes all of the
   1.666 + *                enabled checks.
   1.667 + * @stable ICU 4.2
   1.668 + */
   1.669 +U_STABLE int32_t U_EXPORT2
   1.670 +uspoof_check(const USpoofChecker *sc,
   1.671 +                         const UChar *id, int32_t length, 
   1.672 +                         int32_t *position,
   1.673 +                         UErrorCode *status);
   1.674 +
   1.675 +
   1.676 +/**
   1.677 + * Check the specified string for possible security issues.
   1.678 + * The text to be checked will typically be an identifier of some sort.
   1.679 + * The set of checks to be performed is specified with uspoof_setChecks().
   1.680 + * 
   1.681 + * @param sc      The USpoofChecker 
   1.682 + * @param id      A identifier to be checked for possible security issues, in UTF8 format.
   1.683 + * @param length  the length of the string to be checked, or -1 if the string is 
   1.684 + *                zero terminated.
   1.685 + * @param position      An out parameter.
   1.686 + *                Originally, the index of the first string position that failed a check.
   1.687 + *                Now, always returns zero.
   1.688 + *                This parameter may be null.
   1.689 + *                @deprecated ICU 51
   1.690 + * @param status  The error code, set if an error occurred while attempting to
   1.691 + *                perform the check.
   1.692 + *                Spoofing or security issues detected with the input string are
   1.693 + *                not reported here, but through the function's return value.
   1.694 + *                If the input contains invalid UTF-8 sequences,
   1.695 + *                a status of U_INVALID_CHAR_FOUND will be returned.
   1.696 + * @return        An integer value with bits set for any potential security
   1.697 + *                or spoofing issues detected.  The bits are defined by
   1.698 + *                enum USpoofChecks.  (returned_value & USPOOF_ALL_CHECKS)
   1.699 + *                will be zero if the input string passes all of the
   1.700 + *                enabled checks.
   1.701 + * @stable ICU 4.2
   1.702 + */
   1.703 +U_STABLE int32_t U_EXPORT2
   1.704 +uspoof_checkUTF8(const USpoofChecker *sc,
   1.705 +                 const char *id, int32_t length,
   1.706 +                 int32_t *position,
   1.707 +                 UErrorCode *status);
   1.708 +
   1.709 +
   1.710 +#if U_SHOW_CPLUSPLUS_API
   1.711 +/**
   1.712 + * Check the specified string for possible security issues.
   1.713 + * The text to be checked will typically be an identifier of some sort.
   1.714 + * The set of checks to be performed is specified with uspoof_setChecks().
   1.715 + * 
   1.716 + * @param sc      The USpoofChecker 
   1.717 + * @param id      A identifier to be checked for possible security issues.
   1.718 + * @param position      An out parameter.
   1.719 + *                Originally, the index of the first string position that failed a check.
   1.720 + *                Now, always returns zero.
   1.721 + *                This parameter may be null.
   1.722 + *                @deprecated ICU 51
   1.723 + * @param status  The error code, set if an error occurred while attempting to
   1.724 + *                perform the check.
   1.725 + *                Spoofing or security issues detected with the input string are
   1.726 + *                not reported here, but through the function's return value.
   1.727 + * @return        An integer value with bits set for any potential security
   1.728 + *                or spoofing issues detected.  The bits are defined by
   1.729 + *                enum USpoofChecks.  (returned_value & USPOOF_ALL_CHECKS)
   1.730 + *                will be zero if the input string passes all of the
   1.731 + *                enabled checks.
   1.732 + * @stable ICU 4.2
   1.733 + */
   1.734 +U_STABLE int32_t U_EXPORT2
   1.735 +uspoof_checkUnicodeString(const USpoofChecker *sc,
   1.736 +                          const icu::UnicodeString &id, 
   1.737 +                          int32_t *position,
   1.738 +                          UErrorCode *status);
   1.739 +
   1.740 +#endif
   1.741 +
   1.742 +
   1.743 +/**
   1.744 + * Check the whether two specified strings are visually confusable.
   1.745 + * The types of confusability to be tested - single script, mixed script,
   1.746 + * or whole script - are determined by the check options set for the
   1.747 + * USpoofChecker.
   1.748 + *
   1.749 + * The tests to be performed are controlled by the flags
   1.750 + *   USPOOF_SINGLE_SCRIPT_CONFUSABLE 
   1.751 + *   USPOOF_MIXED_SCRIPT_CONFUSABLE  
   1.752 + *   USPOOF_WHOLE_SCRIPT_CONFUSABLE
   1.753 + * At least one of these tests must be selected.
   1.754 + * 
   1.755 + * USPOOF_ANY_CASE is a modifier for the tests.  Select it if the identifiers
   1.756 + *   may be of mixed case.
   1.757 + * If identifiers are case folded for comparison and
   1.758 + * display to the user, do not select the USPOOF_ANY_CASE option.
   1.759 + *
   1.760 + *
   1.761 + * @param sc      The USpoofChecker
   1.762 + * @param id1     The first of the two identifiers to be compared for 
   1.763 + *                confusability.  The strings are in UTF-16 format.
   1.764 + * @param length1 the length of the first identifer, expressed in
   1.765 + *                16 bit UTF-16 code units, or -1 if the string is 
   1.766 + *                nul terminated.
   1.767 + * @param id2     The second of the two identifiers to be compared for 
   1.768 + *                confusability.  The identifiers are in UTF-16 format.
   1.769 + * @param length2 The length of the second identifiers, expressed in
   1.770 + *                16 bit UTF-16 code units, or -1 if the string is 
   1.771 + *                nul terminated.
   1.772 + * @param status  The error code, set if an error occurred while attempting to
   1.773 + *                perform the check.
   1.774 + *                Confusability of the identifiers is not reported here,
   1.775 + *                but through this function's return value.
   1.776 + * @return        An integer value with bit(s) set corresponding to
   1.777 + *                the type of confusability found, as defined by
   1.778 + *                enum USpoofChecks.  Zero is returned if the identifiers
   1.779 + *                are not confusable.
   1.780 + * @stable ICU 4.2
   1.781 + */
   1.782 +U_STABLE int32_t U_EXPORT2
   1.783 +uspoof_areConfusable(const USpoofChecker *sc,
   1.784 +                     const UChar *id1, int32_t length1,
   1.785 +                     const UChar *id2, int32_t length2,
   1.786 +                     UErrorCode *status);
   1.787 +
   1.788 +
   1.789 +
   1.790 +/**
   1.791 + * Check the whether two specified strings are visually confusable.
   1.792 + * The types of confusability to be tested - single script, mixed script,
   1.793 + * or whole script - are determined by the check options set for the
   1.794 + * USpoofChecker.
   1.795 + *
   1.796 + * @param sc      The USpoofChecker
   1.797 + * @param id1     The first of the two identifiers to be compared for 
   1.798 + *                confusability.  The strings are in UTF-8 format.
   1.799 + * @param length1 the length of the first identifiers, in bytes, or -1 
   1.800 + *                if the string is nul terminated.
   1.801 + * @param id2     The second of the two identifiers to be compared for 
   1.802 + *                confusability.  The strings are in UTF-8 format.
   1.803 + * @param length2 The length of the second string in bytes, or -1 
   1.804 + *                if the string is nul terminated.
   1.805 + * @param status  The error code, set if an error occurred while attempting to
   1.806 + *                perform the check.
   1.807 + *                Confusability of the strings is not reported here,
   1.808 + *                but through this function's return value.
   1.809 + * @return        An integer value with bit(s) set corresponding to
   1.810 + *                the type of confusability found, as defined by
   1.811 + *                enum USpoofChecks.  Zero is returned if the strings
   1.812 + *                are not confusable.
   1.813 + * @stable ICU 4.2
   1.814 + */
   1.815 +U_STABLE int32_t U_EXPORT2
   1.816 +uspoof_areConfusableUTF8(const USpoofChecker *sc,
   1.817 +                         const char *id1, int32_t length1,
   1.818 +                         const char *id2, int32_t length2,
   1.819 +                         UErrorCode *status);
   1.820 +
   1.821 +
   1.822 +
   1.823 +
   1.824 +#if U_SHOW_CPLUSPLUS_API
   1.825 +/**
   1.826 + * Check the whether two specified strings are visually confusable.
   1.827 + * The types of confusability to be tested - single script, mixed script,
   1.828 + * or whole script - are determined by the check options set for the
   1.829 + * USpoofChecker.
   1.830 + *
   1.831 + * @param sc      The USpoofChecker
   1.832 + * @param s1     The first of the two identifiers to be compared for 
   1.833 + *                confusability.  The strings are in UTF-8 format.
   1.834 + * @param s2     The second of the two identifiers to be compared for 
   1.835 + *                confusability.  The strings are in UTF-8 format.
   1.836 + * @param status  The error code, set if an error occurred while attempting to
   1.837 + *                perform the check.
   1.838 + *                Confusability of the identifiers is not reported here,
   1.839 + *                but through this function's return value.
   1.840 + * @return        An integer value with bit(s) set corresponding to
   1.841 + *                the type of confusability found, as defined by
   1.842 + *                enum USpoofChecks.  Zero is returned if the identifiers
   1.843 + *                are not confusable.
   1.844 + * @stable ICU 4.2
   1.845 + */
   1.846 +U_STABLE int32_t U_EXPORT2
   1.847 +uspoof_areConfusableUnicodeString(const USpoofChecker *sc,
   1.848 +                                  const icu::UnicodeString &s1,
   1.849 +                                  const icu::UnicodeString &s2,
   1.850 +                                  UErrorCode *status);
   1.851 +#endif
   1.852 +
   1.853 +
   1.854 +/**
   1.855 +  *  Get the "skeleton" for an identifier.
   1.856 +  *  Skeletons are a transformation of the input identifier;
   1.857 +  *  Two identifiers are confusable if their skeletons are identical.
   1.858 +  *  See Unicode UAX #39 for additional information.
   1.859 +  *
   1.860 +  *  Using skeletons directly makes it possible to quickly check
   1.861 +  *  whether an identifier is confusable with any of some large
   1.862 +  *  set of existing identifiers, by creating an efficiently
   1.863 +  *  searchable collection of the skeletons.
   1.864 +  *
   1.865 +  * @param sc      The USpoofChecker
   1.866 +  * @param type    The type of skeleton, corresponding to which
   1.867 +  *                of the Unicode confusable data tables to use.
   1.868 +  *                The default is Mixed-Script, Lowercase.
   1.869 +  *                Allowed options are USPOOF_SINGLE_SCRIPT_CONFUSABLE and
   1.870 +  *                USPOOF_ANY_CASE_CONFUSABLE.  The two flags may be ORed.
   1.871 +  * @param id      The input identifier whose skeleton will be computed.
   1.872 +  * @param length  The length of the input identifier, expressed in 16 bit
   1.873 +  *                UTF-16 code units, or -1 if the string is zero terminated.
   1.874 +  * @param dest    The output buffer, to receive the skeleton string.
   1.875 +  * @param destCapacity  The length of the output buffer, in 16 bit units.
   1.876 +  *                The destCapacity may be zero, in which case the function will
   1.877 +  *                return the actual length of the skeleton.
   1.878 +  * @param status  The error code, set if an error occurred while attempting to
   1.879 +  *                perform the check.
   1.880 +  * @return        The length of the skeleton string.  The returned length
   1.881 +  *                is always that of the complete skeleton, even when the
   1.882 +  *                supplied buffer is too small (or of zero length)
   1.883 +  *                
   1.884 +  * @stable ICU 4.2
   1.885 +  */
   1.886 +U_STABLE int32_t U_EXPORT2
   1.887 +uspoof_getSkeleton(const USpoofChecker *sc,
   1.888 +                   uint32_t type,
   1.889 +                   const UChar *id,  int32_t length,
   1.890 +                   UChar *dest, int32_t destCapacity,
   1.891 +                   UErrorCode *status);
   1.892 +    
   1.893 +/**
   1.894 +  *  Get the "skeleton" for an identifier.
   1.895 +  *  Skeletons are a transformation of the input identifier;
   1.896 +  *  Two identifiers are confusable if their skeletons are identical.
   1.897 +  *  See Unicode UAX #39 for additional information.
   1.898 +  *
   1.899 +  *  Using skeletons directly makes it possible to quickly check
   1.900 +  *  whether an identifier is confusable with any of some large
   1.901 +  *  set of existing identifiers, by creating an efficiently
   1.902 +  *  searchable collection of the skeletons.
   1.903 +  *
   1.904 +  * @param sc      The USpoofChecker 
   1.905 +  * @param type    The type of skeleton, corresponding to which
   1.906 +  *                of the Unicode confusable data tables to use.
   1.907 +  *                The default is Mixed-Script, Lowercase.
   1.908 +  *                Allowed options are USPOOF_SINGLE_SCRIPT_CONFUSABLE and
   1.909 +  *                USPOOF_ANY_CASE.  The two flags may be ORed.
   1.910 +  * @param id      The UTF-8 format identifier whose skeleton will be computed.
   1.911 +  * @param length  The length of the input string, in bytes,
   1.912 +  *                or -1 if the string is zero terminated.
   1.913 +  * @param dest    The output buffer, to receive the skeleton string.
   1.914 +  * @param destCapacity  The length of the output buffer, in bytes.
   1.915 +  *                The destCapacity may be zero, in which case the function will
   1.916 +  *                return the actual length of the skeleton.
   1.917 +  * @param status  The error code, set if an error occurred while attempting to
   1.918 +  *                perform the check.  Possible Errors include U_INVALID_CHAR_FOUND
   1.919 +  *                   for invalid UTF-8 sequences, and
   1.920 +  *                   U_BUFFER_OVERFLOW_ERROR if the destination buffer is too small
   1.921 +  *                   to hold the complete skeleton.
   1.922 +  * @return        The length of the skeleton string, in bytes.  The returned length
   1.923 +  *                is always that of the complete skeleton, even when the
   1.924 +  *                supplied buffer is too small (or of zero length)
   1.925 +  *                
   1.926 +  * @stable ICU 4.2
   1.927 +  */   
   1.928 +U_STABLE int32_t U_EXPORT2
   1.929 +uspoof_getSkeletonUTF8(const USpoofChecker *sc,
   1.930 +                       uint32_t type,
   1.931 +                       const char *id,  int32_t length,
   1.932 +                       char *dest, int32_t destCapacity,
   1.933 +                       UErrorCode *status);
   1.934 +    
   1.935 +#if U_SHOW_CPLUSPLUS_API
   1.936 +/**
   1.937 +  *  Get the "skeleton" for an identifier.
   1.938 +  *  Skeletons are a transformation of the input identifier;
   1.939 +  *  Two identifiers are confusable if their skeletons are identical.
   1.940 +  *  See Unicode UAX #39 for additional information.
   1.941 +  *
   1.942 +  *  Using skeletons directly makes it possible to quickly check
   1.943 +  *  whether an identifier is confusable with any of some large
   1.944 +  *  set of existing identifiers, by creating an efficiently
   1.945 +  *  searchable collection of the skeletons.
   1.946 +  *
   1.947 +  * @param sc      The USpoofChecker.
   1.948 +  * @param type    The type of skeleton, corresponding to which
   1.949 +  *                of the Unicode confusable data tables to use.
   1.950 +  *                The default is Mixed-Script, Lowercase.
   1.951 +  *                Allowed options are USPOOF_SINGLE_SCRIPT_CONFUSABLE and
   1.952 +  *                USPOOF_ANY_CASE_CONFUSABLE.  The two flags may be ORed.
   1.953 +  * @param id      The input identifier whose skeleton will be computed.
   1.954 +  * @param dest    The output identifier, to receive the skeleton string.
   1.955 +  * @param status  The error code, set if an error occurred while attempting to
   1.956 +  *                perform the check.
   1.957 +  * @return        A reference to the destination (skeleton) string.
   1.958 +  *                
   1.959 +  * @stable ICU 4.2
   1.960 +  */   
   1.961 +U_I18N_API icu::UnicodeString & U_EXPORT2
   1.962 +uspoof_getSkeletonUnicodeString(const USpoofChecker *sc,
   1.963 +                                uint32_t type,
   1.964 +                                const icu::UnicodeString &id,
   1.965 +                                icu::UnicodeString &dest,
   1.966 +                                UErrorCode *status);
   1.967 +#endif   /* U_SHOW_CPLUSPLUS_API */
   1.968 +
   1.969 +
   1.970 +#ifndef U_HIDE_DRAFT_API
   1.971 +/**
   1.972 +  * Get the set of Candidate Characters for Inclusion in Identifiers, as defined
   1.973 +  * in Unicode UAX #31, http://www.unicode.org/reports/tr31/#Table_Candidate_Characters_for_Inclusion_in_Identifiers
   1.974 +  *
   1.975 +  * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
   1.976 +  * be deleted by the caller.
   1.977 +  *
   1.978 +  * @param status The error code, set if a problem occurs while creating the set.
   1.979 +  *
   1.980 +  * @draft ICU 51
   1.981 +  */
   1.982 +U_DRAFT const USet * U_EXPORT2
   1.983 +uspoof_getInclusionSet(UErrorCode *status);
   1.984 +
   1.985 +/**
   1.986 +  * Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined
   1.987 +  * in Unicode UAX #31, http://www.unicode.org/reports/tr31/#Table_Recommended_Scripts
   1.988 +  *
   1.989 +  * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
   1.990 +  * be deleted by the caller.
   1.991 +  *
   1.992 +  * @param status The error code, set if a problem occurs while creating the set.
   1.993 +  *
   1.994 +  * @draft ICU 51
   1.995 +  */
   1.996 +U_DRAFT const USet * U_EXPORT2
   1.997 +uspoof_getRecommendedSet(UErrorCode *status);
   1.998 +
   1.999 +#if U_SHOW_CPLUSPLUS_API
  1.1000 +
  1.1001 +/**
  1.1002 +  * Get the set of Candidate Characters for Inclusion in Identifiers, as defined
  1.1003 +  * in Unicode UAX #31, http://www.unicode.org/reports/tr31/#Table_Candidate_Characters_for_Inclusion_in_Identifiers
  1.1004 +  *
  1.1005 +  * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
  1.1006 +  * be deleted by the caller.
  1.1007 +  *
  1.1008 +  * @param status The error code, set if a problem occurs while creating the set.
  1.1009 +  *
  1.1010 +  * @draft ICU 51
  1.1011 +  */
  1.1012 +U_DRAFT const icu::UnicodeSet * U_EXPORT2
  1.1013 +uspoof_getInclusionUnicodeSet(UErrorCode *status);
  1.1014 +
  1.1015 +/**
  1.1016 +  * Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined
  1.1017 +  * in Unicode UAX #31, http://www.unicode.org/reports/tr31/#Table_Recommended_Scripts
  1.1018 +  *
  1.1019 +  * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
  1.1020 +  * be deleted by the caller.
  1.1021 +  *
  1.1022 +  * @param status The error code, set if a problem occurs while creating the set.
  1.1023 +  *
  1.1024 +  * @draft ICU 51
  1.1025 +  */
  1.1026 +U_DRAFT const icu::UnicodeSet * U_EXPORT2
  1.1027 +uspoof_getRecommendedUnicodeSet(UErrorCode *status);
  1.1028 +
  1.1029 +#endif /* U_SHOW_CPLUSPLUS_API */
  1.1030 +#endif /* U_HIDE_DRAFT_API */
  1.1031 +
  1.1032 +/**
  1.1033 + * Serialize the data for a spoof detector into a chunk of memory.
  1.1034 + * The flattened spoof detection tables can later be used to efficiently
  1.1035 + * instantiate a new Spoof Detector.
  1.1036 + *
  1.1037 + * The serialized spoof checker includes only the data compiled from the
  1.1038 + * Unicode data tables by uspoof_openFromSource(); it does not include 
  1.1039 + * include any other state or configuration that may have been set.
  1.1040 + *
  1.1041 + * @param sc   the Spoof Detector whose data is to be serialized.
  1.1042 + * @param data a pointer to 32-bit-aligned memory to be filled with the data,
  1.1043 + *             can be NULL if capacity==0
  1.1044 + * @param capacity the number of bytes available at data,
  1.1045 + *                 or 0 for preflighting
  1.1046 + * @param status an in/out ICU UErrorCode; possible errors include:
  1.1047 + * - U_BUFFER_OVERFLOW_ERROR if the data storage block is too small for serialization
  1.1048 + * - U_ILLEGAL_ARGUMENT_ERROR  the data or capacity parameters are bad
  1.1049 + * @return the number of bytes written or needed for the spoof data
  1.1050 + *
  1.1051 + * @see utrie2_openFromSerialized()
  1.1052 + * @stable ICU 4.2
  1.1053 + */
  1.1054 +U_STABLE int32_t U_EXPORT2
  1.1055 +uspoof_serialize(USpoofChecker *sc,
  1.1056 +                 void *data, int32_t capacity,
  1.1057 +                 UErrorCode *status);
  1.1058 +
  1.1059 +
  1.1060 +#endif
  1.1061 +
  1.1062 +#endif   /* USPOOF_H */

mercurial