]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/usprep.h
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / common / unicode / usprep.h
1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 2003-2004, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 * file name: usprep.h
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2003jul2
14 * created by: Ram Viswanadha
15 */
16
17 #ifndef __USPREP_H__
18 #define __USPREP_H__
19
20 #include "unicode/utypes.h"
21 /**
22 *\file
23 * StringPrep API implements the StingPrep framework as described by RFC 3454.
24 * StringPrep prepares Unicode strings for use in network protocols.
25 * Profiles of StingPrep are set of rules and data according to with the
26 * Unicode Strings are prepared. Each profiles contains tables which describe
27 * how a code point should be treated. The tables are broadly classied into
28 * <ul>
29 * <li> Unassinged Table: Contains code points that are unassigned
30 * in the Unicode Version supported by StringPrep. Currently
31 * RFC 3454 supports Unicode 3.2. </li>
32 * <li> Prohibited Table: Contains code points that are prohibted from
33 * the output of the StringPrep processing function. </li>
34 * <li> Mapping Table: Contains code ponts that are deleted from the output or case mapped. </li>
35 * </ul>
36 *
37 * The procedure for preparing Unicode strings:
38 * <ol>
39 * <li> Map: For each character in the input, check if it has a mapping
40 * and, if so, replace it with its mapping. </li>
41 * <li> Normalize: Possibly normalize the result of step 1 using Unicode
42 * normalization. </li>
43 * <li> Prohibit: Check for any characters that are not allowed in the
44 * output. If any are found, return an error.</li>
45 * <li> Check bidi: Possibly check for right-to-left characters, and if
46 * any are found, make sure that the whole string satisfies the
47 * requirements for bidirectional strings. If the string does not
48 * satisfy the requirements for bidirectional strings, return an
49 * error. </li>
50 * </ol>
51 * @author Ram Viswanadha
52 */
53 #if !UCONFIG_NO_IDNA
54
55 #include "unicode/parseerr.h"
56
57 #ifndef U_HIDE_DRAFT_API
58
59 /**
60 * The StringPrep profile
61 * @draft ICU 2.8
62 */
63 typedef struct UStringPrepProfile UStringPrepProfile;
64
65
66 /**
67 * Option to prohibit processing of unassigned code points in the input
68 *
69 * @see usprep_prepare
70 * @draft ICU 2.8
71 */
72 #define USPREP_DEFAULT 0x0000
73
74 /**
75 * Option to allow processing of unassigned code points in the input
76 *
77 * @see usprep_prepare
78 * @draft ICU 2.8
79 */
80 #define USPREP_ALLOW_UNASSIGNED 0x0001
81
82
83 #endif /*U_HIDE_DRAFT_API*/
84
85 /**
86 * Creates a StringPrep profile from the data file.
87 *
88 * @param path string containing the full path pointing to the directory
89 * where the profile reside followed by the package name
90 * e.g. "/usr/resource/my_app/profiles/mydata" on a Unix system.
91 * if NULL, ICU default data files will be used.
92 * @param fileName name of the profile file to be opened
93 * @param status ICU error code in/out parameter. Must not be NULL.
94 * Must fulfill U_SUCCESS before the function call.
95 * @return Pointer to UStringPrepProfile that is opened. Should be closed by
96 * calling usprep_close()
97 * @see usprep_close()
98 * @draft ICU 2.8
99 */
100 U_DRAFT UStringPrepProfile* U_EXPORT2
101 usprep_open(const char* path,
102 const char* fileName,
103 UErrorCode* status);
104
105
106 /**
107 * Closes the profile
108 * @param profile The profile to close
109 * @draft ICU 2.8
110 */
111 U_DRAFT void U_EXPORT2
112 usprep_close(UStringPrepProfile* profile);
113
114
115 /**
116 * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
117 * checks for prohited and BiDi characters in the order defined by RFC 3454
118 * depending on the options specified in the profile.
119 *
120 * @param prep The profile to use
121 * @param src Pointer to UChar buffer containing the string to prepare
122 * @param srcLength Number of characters in the source string
123 * @param dest Pointer to the destination buffer to receive the output
124 * @param destCapacity The capacity of destination array
125 * @param options A bit set of options:
126 *
127 * - USPREP_NONE Prohibit processing of unassigned code points in the input
128 *
129 * - USPREP_ALLOW_UNASSIGNED Treat the unassigned code points are in the input
130 * as normal Unicode code points.
131 *
132 * @param parseError Pointer to UParseError struct to receive information on position
133 * of error if an error is encountered. Can be NULL.
134 * @param status ICU in/out error code parameter.
135 * U_INVALID_CHAR_FOUND if src contains
136 * unmatched single surrogates.
137 * U_INDEX_OUTOFBOUNDS_ERROR if src contains
138 * too many code points.
139 * U_BUFFER_OVERFLOW_ERROR if destCapacity is not enough
140 * @return The number of UChars in the destination buffer
141 * @draft ICU 2.8
142 */
143
144 U_DRAFT int32_t U_EXPORT2
145 usprep_prepare( const UStringPrepProfile* prep,
146 const UChar* src, int32_t srcLength,
147 UChar* dest, int32_t destCapacity,
148 int32_t options,
149 UParseError* parseError,
150 UErrorCode* status );
151
152
153 #endif /* #if !UCONFIG_NO_IDNA */
154
155 #endif