intl/icu/source/common/unicode/usprep.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 *
michael@0 4 * Copyright (C) 2003-2010, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 *******************************************************************************
michael@0 8 * file name: usprep.h
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * created on: 2003jul2
michael@0 14 * created by: Ram Viswanadha
michael@0 15 */
michael@0 16
michael@0 17 #ifndef __USPREP_H__
michael@0 18 #define __USPREP_H__
michael@0 19
michael@0 20 /**
michael@0 21 * \file
michael@0 22 * \brief C API: Implements the StringPrep algorithm.
michael@0 23 */
michael@0 24
michael@0 25 #include "unicode/utypes.h"
michael@0 26 #include "unicode/localpointer.h"
michael@0 27
michael@0 28 /**
michael@0 29 *
michael@0 30 * StringPrep API implements the StingPrep framework as described by RFC 3454.
michael@0 31 * StringPrep prepares Unicode strings for use in network protocols.
michael@0 32 * Profiles of StingPrep are set of rules and data according to with the
michael@0 33 * Unicode Strings are prepared. Each profiles contains tables which describe
michael@0 34 * how a code point should be treated. The tables are broadly classied into
michael@0 35 * <ul>
michael@0 36 * <li> Unassinged Table: Contains code points that are unassigned
michael@0 37 * in the Unicode Version supported by StringPrep. Currently
michael@0 38 * RFC 3454 supports Unicode 3.2. </li>
michael@0 39 * <li> Prohibited Table: Contains code points that are prohibted from
michael@0 40 * the output of the StringPrep processing function. </li>
michael@0 41 * <li> Mapping Table: Contains code ponts that are deleted from the output or case mapped. </li>
michael@0 42 * </ul>
michael@0 43 *
michael@0 44 * The procedure for preparing Unicode strings:
michael@0 45 * <ol>
michael@0 46 * <li> Map: For each character in the input, check if it has a mapping
michael@0 47 * and, if so, replace it with its mapping. </li>
michael@0 48 * <li> Normalize: Possibly normalize the result of step 1 using Unicode
michael@0 49 * normalization. </li>
michael@0 50 * <li> Prohibit: Check for any characters that are not allowed in the
michael@0 51 * output. If any are found, return an error.</li>
michael@0 52 * <li> Check bidi: Possibly check for right-to-left characters, and if
michael@0 53 * any are found, make sure that the whole string satisfies the
michael@0 54 * requirements for bidirectional strings. If the string does not
michael@0 55 * satisfy the requirements for bidirectional strings, return an
michael@0 56 * error. </li>
michael@0 57 * </ol>
michael@0 58 * @author Ram Viswanadha
michael@0 59 */
michael@0 60 #if !UCONFIG_NO_IDNA
michael@0 61
michael@0 62 #include "unicode/parseerr.h"
michael@0 63
michael@0 64 /**
michael@0 65 * The StringPrep profile
michael@0 66 * @stable ICU 2.8
michael@0 67 */
michael@0 68 typedef struct UStringPrepProfile UStringPrepProfile;
michael@0 69
michael@0 70
michael@0 71 /**
michael@0 72 * Option to prohibit processing of unassigned code points in the input
michael@0 73 *
michael@0 74 * @see usprep_prepare
michael@0 75 * @stable ICU 2.8
michael@0 76 */
michael@0 77 #define USPREP_DEFAULT 0x0000
michael@0 78
michael@0 79 /**
michael@0 80 * Option to allow processing of unassigned code points in the input
michael@0 81 *
michael@0 82 * @see usprep_prepare
michael@0 83 * @stable ICU 2.8
michael@0 84 */
michael@0 85 #define USPREP_ALLOW_UNASSIGNED 0x0001
michael@0 86
michael@0 87 /**
michael@0 88 * enums for the standard stringprep profile types
michael@0 89 * supported by usprep_openByType.
michael@0 90 * @see usprep_openByType
michael@0 91 * @stable ICU 4.2
michael@0 92 */
michael@0 93 typedef enum UStringPrepProfileType {
michael@0 94 /**
michael@0 95 * RFC3491 Nameprep
michael@0 96 * @stable ICU 4.2
michael@0 97 */
michael@0 98 USPREP_RFC3491_NAMEPREP,
michael@0 99 /**
michael@0 100 * RFC3530 nfs4_cs_prep
michael@0 101 * @stable ICU 4.2
michael@0 102 */
michael@0 103 USPREP_RFC3530_NFS4_CS_PREP,
michael@0 104 /**
michael@0 105 * RFC3530 nfs4_cs_prep with case insensitive option
michael@0 106 * @stable ICU 4.2
michael@0 107 */
michael@0 108 USPREP_RFC3530_NFS4_CS_PREP_CI,
michael@0 109 /**
michael@0 110 * RFC3530 nfs4_cis_prep
michael@0 111 * @stable ICU 4.2
michael@0 112 */
michael@0 113 USPREP_RFC3530_NFS4_CIS_PREP,
michael@0 114 /**
michael@0 115 * RFC3530 nfs4_mixed_prep for prefix
michael@0 116 * @stable ICU 4.2
michael@0 117 */
michael@0 118 USPREP_RFC3530_NFS4_MIXED_PREP_PREFIX,
michael@0 119 /**
michael@0 120 * RFC3530 nfs4_mixed_prep for suffix
michael@0 121 * @stable ICU 4.2
michael@0 122 */
michael@0 123 USPREP_RFC3530_NFS4_MIXED_PREP_SUFFIX,
michael@0 124 /**
michael@0 125 * RFC3722 iSCSI
michael@0 126 * @stable ICU 4.2
michael@0 127 */
michael@0 128 USPREP_RFC3722_ISCSI,
michael@0 129 /**
michael@0 130 * RFC3920 XMPP Nodeprep
michael@0 131 * @stable ICU 4.2
michael@0 132 */
michael@0 133 USPREP_RFC3920_NODEPREP,
michael@0 134 /**
michael@0 135 * RFC3920 XMPP Resourceprep
michael@0 136 * @stable ICU 4.2
michael@0 137 */
michael@0 138 USPREP_RFC3920_RESOURCEPREP,
michael@0 139 /**
michael@0 140 * RFC4011 Policy MIB Stringprep
michael@0 141 * @stable ICU 4.2
michael@0 142 */
michael@0 143 USPREP_RFC4011_MIB,
michael@0 144 /**
michael@0 145 * RFC4013 SASLprep
michael@0 146 * @stable ICU 4.2
michael@0 147 */
michael@0 148 USPREP_RFC4013_SASLPREP,
michael@0 149 /**
michael@0 150 * RFC4505 trace
michael@0 151 * @stable ICU 4.2
michael@0 152 */
michael@0 153 USPREP_RFC4505_TRACE,
michael@0 154 /**
michael@0 155 * RFC4518 LDAP
michael@0 156 * @stable ICU 4.2
michael@0 157 */
michael@0 158 USPREP_RFC4518_LDAP,
michael@0 159 /**
michael@0 160 * RFC4518 LDAP for case ignore, numeric and stored prefix
michael@0 161 * matching rules
michael@0 162 * @stable ICU 4.2
michael@0 163 */
michael@0 164 USPREP_RFC4518_LDAP_CI
michael@0 165 } UStringPrepProfileType;
michael@0 166
michael@0 167 /**
michael@0 168 * Creates a StringPrep profile from the data file.
michael@0 169 *
michael@0 170 * @param path string containing the full path pointing to the directory
michael@0 171 * where the profile reside followed by the package name
michael@0 172 * e.g. "/usr/resource/my_app/profiles/mydata" on a Unix system.
michael@0 173 * if NULL, ICU default data files will be used.
michael@0 174 * @param fileName name of the profile file to be opened
michael@0 175 * @param status ICU error code in/out parameter. Must not be NULL.
michael@0 176 * Must fulfill U_SUCCESS before the function call.
michael@0 177 * @return Pointer to UStringPrepProfile that is opened. Should be closed by
michael@0 178 * calling usprep_close()
michael@0 179 * @see usprep_close()
michael@0 180 * @stable ICU 2.8
michael@0 181 */
michael@0 182 U_STABLE UStringPrepProfile* U_EXPORT2
michael@0 183 usprep_open(const char* path,
michael@0 184 const char* fileName,
michael@0 185 UErrorCode* status);
michael@0 186
michael@0 187 /**
michael@0 188 * Creates a StringPrep profile for the specified profile type.
michael@0 189 *
michael@0 190 * @param type The profile type
michael@0 191 * @param status ICU error code in/out parameter. Must not be NULL.
michael@0 192 * Must fulfill U_SUCCESS before the function call.
michael@0 193 * @return Pointer to UStringPrepProfile that is opened. Should be closed by
michael@0 194 * calling usprep_close()
michael@0 195 * @see usprep_close()
michael@0 196 * @stable ICU 4.2
michael@0 197 */
michael@0 198 U_STABLE UStringPrepProfile* U_EXPORT2
michael@0 199 usprep_openByType(UStringPrepProfileType type,
michael@0 200 UErrorCode* status);
michael@0 201
michael@0 202 /**
michael@0 203 * Closes the profile
michael@0 204 * @param profile The profile to close
michael@0 205 * @stable ICU 2.8
michael@0 206 */
michael@0 207 U_STABLE void U_EXPORT2
michael@0 208 usprep_close(UStringPrepProfile* profile);
michael@0 209
michael@0 210 #if U_SHOW_CPLUSPLUS_API
michael@0 211
michael@0 212 U_NAMESPACE_BEGIN
michael@0 213
michael@0 214 /**
michael@0 215 * \class LocalUStringPrepProfilePointer
michael@0 216 * "Smart pointer" class, closes a UStringPrepProfile via usprep_close().
michael@0 217 * For most methods see the LocalPointerBase base class.
michael@0 218 *
michael@0 219 * @see LocalPointerBase
michael@0 220 * @see LocalPointer
michael@0 221 * @stable ICU 4.4
michael@0 222 */
michael@0 223 U_DEFINE_LOCAL_OPEN_POINTER(LocalUStringPrepProfilePointer, UStringPrepProfile, usprep_close);
michael@0 224
michael@0 225 U_NAMESPACE_END
michael@0 226
michael@0 227 #endif
michael@0 228
michael@0 229 /**
michael@0 230 * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
michael@0 231 * checks for prohited and BiDi characters in the order defined by RFC 3454
michael@0 232 * depending on the options specified in the profile.
michael@0 233 *
michael@0 234 * @param prep The profile to use
michael@0 235 * @param src Pointer to UChar buffer containing the string to prepare
michael@0 236 * @param srcLength Number of characters in the source string
michael@0 237 * @param dest Pointer to the destination buffer to receive the output
michael@0 238 * @param destCapacity The capacity of destination array
michael@0 239 * @param options A bit set of options:
michael@0 240 *
michael@0 241 * - USPREP_NONE Prohibit processing of unassigned code points in the input
michael@0 242 *
michael@0 243 * - USPREP_ALLOW_UNASSIGNED Treat the unassigned code points are in the input
michael@0 244 * as normal Unicode code points.
michael@0 245 *
michael@0 246 * @param parseError Pointer to UParseError struct to receive information on position
michael@0 247 * of error if an error is encountered. Can be NULL.
michael@0 248 * @param status ICU in/out error code parameter.
michael@0 249 * U_INVALID_CHAR_FOUND if src contains
michael@0 250 * unmatched single surrogates.
michael@0 251 * U_INDEX_OUTOFBOUNDS_ERROR if src contains
michael@0 252 * too many code points.
michael@0 253 * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
michael@0 254 * @return The number of UChars in the destination buffer
michael@0 255 * @stable ICU 2.8
michael@0 256 */
michael@0 257
michael@0 258 U_STABLE int32_t U_EXPORT2
michael@0 259 usprep_prepare( const UStringPrepProfile* prep,
michael@0 260 const UChar* src, int32_t srcLength,
michael@0 261 UChar* dest, int32_t destCapacity,
michael@0 262 int32_t options,
michael@0 263 UParseError* parseError,
michael@0 264 UErrorCode* status );
michael@0 265
michael@0 266
michael@0 267 #endif /* #if !UCONFIG_NO_IDNA */
michael@0 268
michael@0 269 #endif

mercurial