• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *******************************************************************************
3  *
4  *   Copyright (C) 2003-2006, 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 /**
21  * \file
22  * \brief C API: Implements the StringPrep algorithm.
23  */
24 
25 #include "unicode/utypes.h"
26 /**
27  *
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
33  * <ul>
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>
40  * </ul>
41  *
42  * The procedure for preparing Unicode strings:
43  * <ol>
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
54  *           error.  </li>
55  * </ol>
56  * @author Ram Viswanadha
57  */
58 #if !UCONFIG_NO_IDNA
59 
60 #include "unicode/parseerr.h"
61 
62 /**
63  * The StringPrep profile
64  * @stable ICU 2.8
65  */
66 typedef struct UStringPrepProfile UStringPrepProfile;
67 
68 
69 /**
70  * Option to prohibit processing of unassigned code points in the input
71  *
72  * @see  usprep_prepare
73  * @stable ICU 2.8
74  */
75 #define USPREP_DEFAULT 0x0000
76 
77 /**
78  * Option to allow processing of unassigned code points in the input
79  *
80  * @see  usprep_prepare
81  * @stable ICU 2.8
82  */
83 #define USPREP_ALLOW_UNASSIGNED 0x0001
84 
85 
86 /**
87  * Creates a StringPrep profile from the data file.
88  *
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()
98  * @see usprep_close()
99  * @stable ICU 2.8
100  */
101 U_STABLE UStringPrepProfile* U_EXPORT2
102 usprep_open(const char* path,
103             const char* fileName,
104             UErrorCode* status);
105 
106 
107 /**
108  * Closes the profile
109  * @param profile The profile to close
110  * @stable ICU 2.8
111  */
112 U_STABLE void U_EXPORT2
113 usprep_close(UStringPrepProfile* profile);
114 
115 
116 /**
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.
120  *
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:
127  *
128  *  - USPREP_NONE               Prohibit processing of unassigned code points in the input
129  *
130  *  - USPREP_ALLOW_UNASSIGNED   Treat the unassigned code points are in the input
131  *                              as normal Unicode code points.
132  *
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
142  * @stable ICU 2.8
143  */
144 
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,
149                   int32_t options,
150                   UParseError* parseError,
151                   UErrorCode* status );
152 
153 
154 #endif /* #if !UCONFIG_NO_IDNA */
155 
156 #endif
157