2 *******************************************************************************
4 * Copyright (C) 2003-2006, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 2003jul2
14 * created by: Ram Viswanadha
22 * \brief C API: Implements the StringPrep algorithm.
25 #include "unicode/utypes.h"
28 * StringPrep API implements the StingPrep framework as described by RFC 3454.
29 * StringPrep prepares Unicode strings for use in network protocols.
30 * Profiles of StingPrep are set of rules and data according to with the
31 * Unicode Strings are prepared. Each profiles contains tables which describe
32 * how a code point should be treated. The tables are broadly classied into
34 * <li> Unassinged Table: Contains code points that are unassigned
35 * in the Unicode Version supported by StringPrep. Currently
36 * RFC 3454 supports Unicode 3.2. </li>
37 * <li> Prohibited Table: Contains code points that are prohibted from
38 * the output of the StringPrep processing function. </li>
39 * <li> Mapping Table: Contains code ponts that are deleted from the output or case mapped. </li>
42 * The procedure for preparing Unicode strings:
44 * <li> Map: For each character in the input, check if it has a mapping
45 * and, if so, replace it with its mapping. </li>
46 * <li> Normalize: Possibly normalize the result of step 1 using Unicode
47 * normalization. </li>
48 * <li> Prohibit: Check for any characters that are not allowed in the
49 * output. If any are found, return an error.</li>
50 * <li> Check bidi: Possibly check for right-to-left characters, and if
51 * any are found, make sure that the whole string satisfies the
52 * requirements for bidirectional strings. If the string does not
53 * satisfy the requirements for bidirectional strings, return an
56 * @author Ram Viswanadha
60 #include "unicode/parseerr.h"
63 * The StringPrep profile
66 typedef struct UStringPrepProfile UStringPrepProfile
;
70 * Option to prohibit processing of unassigned code points in the input
75 #define USPREP_DEFAULT 0x0000
78 * Option to allow processing of unassigned code points in the input
83 #define USPREP_ALLOW_UNASSIGNED 0x0001
87 * Creates a StringPrep profile from the data file.
89 * @param path string containing the full path pointing to the directory
90 * where the profile reside followed by the package name
91 * e.g. "/usr/resource/my_app/profiles/mydata" on a Unix system.
92 * if NULL, ICU default data files will be used.
93 * @param fileName name of the profile file to be opened
94 * @param status ICU error code in/out parameter. Must not be NULL.
95 * Must fulfill U_SUCCESS before the function call.
96 * @return Pointer to UStringPrepProfile that is opened. Should be closed by
97 * calling usprep_close()
101 U_STABLE UStringPrepProfile
* U_EXPORT2
102 usprep_open(const char* path
,
103 const char* fileName
,
109 * @param profile The profile to close
112 U_STABLE
void U_EXPORT2
113 usprep_close(UStringPrepProfile
* profile
);
117 * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
118 * checks for prohited and BiDi characters in the order defined by RFC 3454
119 * depending on the options specified in the profile.
121 * @param prep The profile to use
122 * @param src Pointer to UChar buffer containing the string to prepare
123 * @param srcLength Number of characters in the source string
124 * @param dest Pointer to the destination buffer to receive the output
125 * @param destCapacity The capacity of destination array
126 * @param options A bit set of options:
128 * - USPREP_NONE Prohibit processing of unassigned code points in the input
130 * - USPREP_ALLOW_UNASSIGNED Treat the unassigned code points are in the input
131 * as normal Unicode code points.
133 * @param parseError Pointer to UParseError struct to receive information on position
134 * of error if an error is encountered. Can be NULL.
135 * @param status ICU in/out error code parameter.
136 * U_INVALID_CHAR_FOUND if src contains
137 * unmatched single surrogates.
138 * U_INDEX_OUTOFBOUNDS_ERROR if src contains
139 * too many code points.
140 * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
141 * @return The number of UChars in the destination buffer
145 U_STABLE
int32_t U_EXPORT2
146 usprep_prepare( const UStringPrepProfile
* prep
,
147 const UChar
* src
, int32_t srcLength
,
148 UChar
* dest
, int32_t destCapacity
,
150 UParseError
* parseError
,
151 UErrorCode
* status
);
154 #endif /* #if !UCONFIG_NO_IDNA */