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