rev |
line source |
jbe@0
|
1 /*
|
jbe@10
|
2 * Copyright (c) 2009 Public Software Group e. V., Berlin, Germany
|
jbe@0
|
3 *
|
jbe@7
|
4 * Permission is hereby granted, free of charge, to any person obtaining a
|
jbe@7
|
5 * copy of this software and associated documentation files (the "Software"),
|
jbe@7
|
6 * to deal in the Software without restriction, including without limitation
|
jbe@7
|
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
jbe@7
|
8 * and/or sell copies of the Software, and to permit persons to whom the
|
jbe@7
|
9 * Software is furnished to do so, subject to the following conditions:
|
jbe@0
|
10 *
|
jbe@7
|
11 * The above copyright notice and this permission notice shall be included in
|
jbe@7
|
12 * all copies or substantial portions of the Software.
|
jbe@0
|
13 *
|
jbe@7
|
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
jbe@7
|
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
jbe@7
|
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
jbe@7
|
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
jbe@7
|
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
jbe@7
|
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
jbe@7
|
20 * DEALINGS IN THE SOFTWARE.
|
jbe@0
|
21 */
|
jbe@7
|
22
|
jbe@0
|
23
|
jbe@0
|
24 /*
|
jbe@0
|
25 * File name: utf8proc.h
|
jbe@0
|
26 *
|
jbe@0
|
27 * Description:
|
jbe@0
|
28 * Header files for libutf8proc, which is a mapping tool for UTF-8 strings
|
jbe@0
|
29 * with following features:
|
jbe@0
|
30 * - decomposing and composing of strings
|
jbe@0
|
31 * - replacing compatibility characters with their equivalents
|
jbe@0
|
32 * - stripping of "default ignorable characters"
|
jbe@0
|
33 * like SOFT-HYPHEN or ZERO-WIDTH-SPACE
|
jbe@3
|
34 * - folding of certain characters for string comparison
|
jbe@3
|
35 * (e.g. HYPHEN U+2010 and MINUS U+2212 to ASCII "-")
|
jbe@3
|
36 * (see "LUMP" option)
|
jbe@0
|
37 * - optional rejection of strings containing non-assigned code points
|
jbe@0
|
38 * - stripping of control characters
|
jbe@3
|
39 * - stripping of character marks (accents, etc.)
|
jbe@0
|
40 * - transformation of LF, CRLF, CR and NEL to line-feed (LF)
|
jbe@0
|
41 * or to the unicode chararacters for paragraph separation (PS)
|
jbe@0
|
42 * or line separation (LS).
|
jbe@0
|
43 * - unicode case folding (for case insensitive string comparisons)
|
jbe@7
|
44 * - rejection of illegal UTF-8 data
|
jbe@7
|
45 * (i.e. UTF-8 encoded UTF-16 surrogates)
|
jbe@0
|
46 * - support for korean hangul characters
|
Jiahao@15
|
47 * Unicode Version 7.0.0 is supported.
|
jbe@0
|
48 */
|
jbe@0
|
49
|
jbe@0
|
50
|
jbe@0
|
51 #ifndef UTF8PROC_H
|
jbe@0
|
52 #define UTF8PROC_H
|
jbe@0
|
53
|
jbe@0
|
54
|
jbe@0
|
55 #include <stdlib.h>
|
Jan@12
|
56 #include <sys/types.h>
|
Jan@12
|
57 #ifdef _MSC_VER
|
Jan@12
|
58 typedef signed char int8_t;
|
Jan@12
|
59 typedef unsigned char uint8_t;
|
Jan@12
|
60 typedef short int16_t;
|
Jan@12
|
61 typedef unsigned short uint16_t;
|
Jan@12
|
62 typedef int int32_t;
|
Jiahao@15
|
63 # ifdef _WIN64
|
Jiahao@15
|
64 # define ssize_t __int64
|
Jiahao@15
|
65 # else
|
Jiahao@15
|
66 # define ssize_t int
|
Jiahao@15
|
67 # endif
|
Jiahao@15
|
68 # ifndef __cplusplus
|
Jan@12
|
69 typedef unsigned char bool;
|
Jan@12
|
70 enum {false, true};
|
Jiahao@15
|
71 # endif
|
Jan@12
|
72 #else
|
Jiahao@15
|
73 # include <stdbool.h>
|
Jiahao@15
|
74 # include <inttypes.h>
|
Jan@12
|
75 #endif
|
jbe@0
|
76 #include <limits.h>
|
jbe@0
|
77
|
Jiahao@15
|
78 #ifdef _WIN32
|
Jiahao@15
|
79 # ifdef UTF8PROC_EXPORTS
|
Jiahao@15
|
80 # define DLLEXPORT __declspec(dllexport)
|
Jiahao@15
|
81 # else
|
Jiahao@15
|
82 # define DLLEXPORT __declspec(dllimport)
|
Jiahao@15
|
83 # endif
|
Jiahao@15
|
84 #elif __GNUC__ >= 4
|
Jiahao@15
|
85 # define DLLEXPORT __attribute__ ((visibility("default")))
|
Jiahao@15
|
86 #else
|
Jiahao@15
|
87 # define DLLEXPORT
|
Jiahao@15
|
88 #endif
|
Jiahao@15
|
89
|
Jan@12
|
90 #ifdef __cplusplus
|
Jan@12
|
91 extern "C" {
|
Jan@12
|
92 #endif
|
Jan@12
|
93
|
jbe@0
|
94 #ifndef SSIZE_MAX
|
jbe@10
|
95 #define SSIZE_MAX ((size_t)SIZE_MAX/2)
|
jbe@0
|
96 #endif
|
jbe@0
|
97
|
jbe@2
|
98 #define UTF8PROC_NULLTERM (1<<0)
|
jbe@2
|
99 #define UTF8PROC_STABLE (1<<1)
|
jbe@2
|
100 #define UTF8PROC_COMPAT (1<<2)
|
jbe@2
|
101 #define UTF8PROC_COMPOSE (1<<3)
|
jbe@2
|
102 #define UTF8PROC_DECOMPOSE (1<<4)
|
jbe@2
|
103 #define UTF8PROC_IGNORE (1<<5)
|
jbe@2
|
104 #define UTF8PROC_REJECTNA (1<<6)
|
jbe@2
|
105 #define UTF8PROC_NLF2LS (1<<7)
|
jbe@2
|
106 #define UTF8PROC_NLF2PS (1<<8)
|
jbe@2
|
107 #define UTF8PROC_NLF2LF (UTF8PROC_NLF2LS | UTF8PROC_NLF2PS)
|
jbe@2
|
108 #define UTF8PROC_STRIPCC (1<<9)
|
jbe@2
|
109 #define UTF8PROC_CASEFOLD (1<<10)
|
jbe@2
|
110 #define UTF8PROC_CHARBOUND (1<<11)
|
jbe@3
|
111 #define UTF8PROC_LUMP (1<<12)
|
jbe@3
|
112 #define UTF8PROC_STRIPMARK (1<<13)
|
jbe@0
|
113 /*
|
jbe@0
|
114 * Flags being regarded by several functions in the library:
|
jbe@2
|
115 * NULLTERM: The given UTF-8 input is NULL terminated.
|
jbe@2
|
116 * STABLE: Unicode Versioning Stability has to be respected.
|
Jiahao@15
|
117 * COMPAT: Compatibility decomposition
|
jbe@2
|
118 * (i.e. formatting information is lost)
|
jbe@2
|
119 * COMPOSE: Return a result with composed characters.
|
jbe@2
|
120 * DECOMPOSE: Return a result with decomposed characters.
|
jbe@2
|
121 * IGNORE: Strip "default ignorable characters"
|
jbe@7
|
122 * REJECTNA: Return an error, if the input contains unassigned
|
jbe@7
|
123 * code points.
|
jbe@2
|
124 * NLF2LS: Indicating that NLF-sequences (LF, CRLF, CR, NEL) are
|
jbe@2
|
125 * representing a line break, and should be converted to the
|
jbe@2
|
126 * unicode character for line separation (LS).
|
jbe@2
|
127 * NLF2PS: Indicating that NLF-sequences are representing a paragraph
|
jbe@2
|
128 * break, and should be converted to the unicode character for
|
jbe@2
|
129 * paragraph separation (PS).
|
jbe@2
|
130 * NLF2LF: Indicating that the meaning of NLF-sequences is unknown.
|
jbe@2
|
131 * STRIPCC: Strips and/or convers control characters.
|
jbe@7
|
132 * NLF-sequences are transformed into space, except if one of
|
jbe@7
|
133 * the NLF2LS/PS/LF options is given.
|
jbe@2
|
134 * HorizontalTab (HT) and FormFeed (FF) are treated as a
|
jbe@2
|
135 * NLF-sequence in this case.
|
jbe@2
|
136 * All other control characters are simply removed.
|
jbe@2
|
137 * CASEFOLD: Performs unicode case folding, to be able to do a
|
jbe@2
|
138 * case-insensitive string comparison.
|
jbe@7
|
139 * CHARBOUND: Inserts 0xFF bytes at the beginning of each sequence which
|
jbe@7
|
140 * is representing a single grapheme cluster (see UAX#29).
|
jbe@3
|
141 * LUMP: Lumps certain characters together
|
jbe@3
|
142 * (e.g. HYPHEN U+2010 and MINUS U+2212 to ASCII "-").
|
jbe@3
|
143 * (See lump.txt for details.)
|
jbe@7
|
144 * If NLF2LF is set, this includes a transformation of
|
jbe@7
|
145 * paragraph and line separators to ASCII line-feed (LF).
|
jbe@3
|
146 * STRIPMARK: Strips all character markings
|
jbe@3
|
147 * (non-spacing, spacing and enclosing) (i.e. accents)
|
jbe@3
|
148 * NOTE: this option works only with COMPOSE or DECOMPOSE
|
jbe@0
|
149 */
|
jbe@0
|
150
|
jbe@0
|
151 #define UTF8PROC_ERROR_NOMEM -1
|
jbe@0
|
152 #define UTF8PROC_ERROR_OVERFLOW -2
|
jbe@0
|
153 #define UTF8PROC_ERROR_INVALIDUTF8 -3
|
jbe@0
|
154 #define UTF8PROC_ERROR_NOTASSIGNED -4
|
jbe@3
|
155 #define UTF8PROC_ERROR_INVALIDOPTS -5
|
jbe@0
|
156 /*
|
jbe@0
|
157 * Error codes being returned by almost all functions:
|
jbe@0
|
158 * ERROR_NOMEM: Memory could not be allocated.
|
jbe@0
|
159 * ERROR_OVERFLOW: The given string is too long to be processed.
|
jbe@0
|
160 * ERROR_INVALIDUTF8: The given string is not a legal UTF-8 string.
|
jbe@0
|
161 * ERROR_NOTASSIGNED: The REJECTNA flag was set,
|
jbe@0
|
162 * and an unassigned code point was found.
|
jbe@3
|
163 * ERROR_INVALIDOPTS: Invalid options have been used.
|
jbe@0
|
164 */
|
jbe@0
|
165
|
jbe@3
|
166 typedef int16_t utf8proc_propval_t;
|
jbe@0
|
167 typedef struct utf8proc_property_struct {
|
jbe@3
|
168 utf8proc_propval_t category;
|
jbe@3
|
169 utf8proc_propval_t combining_class;
|
jbe@3
|
170 utf8proc_propval_t bidi_class;
|
jbe@3
|
171 utf8proc_propval_t decomp_type;
|
jbe@0
|
172 const int32_t *decomp_mapping;
|
jbe@7
|
173 unsigned bidi_mirrored:1;
|
jbe@7
|
174 int32_t uppercase_mapping;
|
jbe@7
|
175 int32_t lowercase_mapping;
|
jbe@7
|
176 int32_t titlecase_mapping;
|
jbe@7
|
177 int32_t comb1st_index;
|
jbe@7
|
178 int32_t comb2nd_index;
|
jbe@7
|
179 unsigned comp_exclusion:1;
|
jbe@7
|
180 unsigned ignorable:1;
|
jbe@7
|
181 unsigned control_boundary:1;
|
jbe@7
|
182 unsigned extend:1;
|
jbe@0
|
183 const int32_t *casefold_mapping;
|
jbe@0
|
184 } utf8proc_property_t;
|
jbe@0
|
185
|
jbe@2
|
186 #define UTF8PROC_CATEGORY_LU 1
|
jbe@2
|
187 #define UTF8PROC_CATEGORY_LL 2
|
jbe@2
|
188 #define UTF8PROC_CATEGORY_LT 3
|
jbe@2
|
189 #define UTF8PROC_CATEGORY_LM 4
|
jbe@2
|
190 #define UTF8PROC_CATEGORY_LO 5
|
jbe@2
|
191 #define UTF8PROC_CATEGORY_MN 6
|
jbe@2
|
192 #define UTF8PROC_CATEGORY_MC 7
|
jbe@2
|
193 #define UTF8PROC_CATEGORY_ME 8
|
jbe@2
|
194 #define UTF8PROC_CATEGORY_ND 9
|
jbe@2
|
195 #define UTF8PROC_CATEGORY_NL 10
|
jbe@2
|
196 #define UTF8PROC_CATEGORY_NO 11
|
jbe@2
|
197 #define UTF8PROC_CATEGORY_PC 12
|
jbe@2
|
198 #define UTF8PROC_CATEGORY_PD 13
|
jbe@2
|
199 #define UTF8PROC_CATEGORY_PS 14
|
jbe@2
|
200 #define UTF8PROC_CATEGORY_PE 15
|
jbe@2
|
201 #define UTF8PROC_CATEGORY_PI 16
|
jbe@2
|
202 #define UTF8PROC_CATEGORY_PF 17
|
jbe@2
|
203 #define UTF8PROC_CATEGORY_PO 18
|
jbe@2
|
204 #define UTF8PROC_CATEGORY_SM 19
|
jbe@2
|
205 #define UTF8PROC_CATEGORY_SC 20
|
jbe@2
|
206 #define UTF8PROC_CATEGORY_SK 21
|
jbe@2
|
207 #define UTF8PROC_CATEGORY_SO 22
|
jbe@2
|
208 #define UTF8PROC_CATEGORY_ZS 23
|
jbe@2
|
209 #define UTF8PROC_CATEGORY_ZL 24
|
jbe@2
|
210 #define UTF8PROC_CATEGORY_ZP 25
|
jbe@2
|
211 #define UTF8PROC_CATEGORY_CC 26
|
jbe@2
|
212 #define UTF8PROC_CATEGORY_CF 27
|
jbe@2
|
213 #define UTF8PROC_CATEGORY_CS 28
|
jbe@2
|
214 #define UTF8PROC_CATEGORY_CO 29
|
jbe@2
|
215 #define UTF8PROC_CATEGORY_CN 30
|
jbe@2
|
216 #define UTF8PROC_BIDI_CLASS_L 1
|
jbe@2
|
217 #define UTF8PROC_BIDI_CLASS_LRE 2
|
jbe@2
|
218 #define UTF8PROC_BIDI_CLASS_LRO 3
|
jbe@2
|
219 #define UTF8PROC_BIDI_CLASS_R 4
|
jbe@2
|
220 #define UTF8PROC_BIDI_CLASS_AL 5
|
jbe@2
|
221 #define UTF8PROC_BIDI_CLASS_RLE 6
|
jbe@2
|
222 #define UTF8PROC_BIDI_CLASS_RLO 7
|
jbe@2
|
223 #define UTF8PROC_BIDI_CLASS_PDF 8
|
jbe@2
|
224 #define UTF8PROC_BIDI_CLASS_EN 9
|
jbe@2
|
225 #define UTF8PROC_BIDI_CLASS_ES 10
|
jbe@2
|
226 #define UTF8PROC_BIDI_CLASS_ET 11
|
jbe@2
|
227 #define UTF8PROC_BIDI_CLASS_AN 12
|
jbe@2
|
228 #define UTF8PROC_BIDI_CLASS_CS 13
|
jbe@2
|
229 #define UTF8PROC_BIDI_CLASS_NSM 14
|
jbe@2
|
230 #define UTF8PROC_BIDI_CLASS_BN 15
|
jbe@2
|
231 #define UTF8PROC_BIDI_CLASS_B 16
|
jbe@2
|
232 #define UTF8PROC_BIDI_CLASS_S 17
|
jbe@2
|
233 #define UTF8PROC_BIDI_CLASS_WS 18
|
jbe@2
|
234 #define UTF8PROC_BIDI_CLASS_ON 19
|
Jiahao@15
|
235 #define UTF8PROC_BIDI_CLASS_LRI 20 /* new in Unicode 6.3 */
|
Jiahao@15
|
236 #define UTF8PROC_BIDI_CLASS_RLI 21 /* new in Unicode 6.3 */
|
Jiahao@15
|
237 #define UTF8PROC_BIDI_CLASS_FSI 22 /* new in Unicode 6.3 */
|
Jiahao@15
|
238 #define UTF8PROC_BIDI_CLASS_PDI 23 /* new in Unicode 6.3 */
|
jbe@2
|
239 #define UTF8PROC_DECOMP_TYPE_FONT 1
|
jbe@2
|
240 #define UTF8PROC_DECOMP_TYPE_NOBREAK 2
|
jbe@2
|
241 #define UTF8PROC_DECOMP_TYPE_INITIAL 3
|
jbe@2
|
242 #define UTF8PROC_DECOMP_TYPE_MEDIAL 4
|
jbe@2
|
243 #define UTF8PROC_DECOMP_TYPE_FINAL 5
|
jbe@2
|
244 #define UTF8PROC_DECOMP_TYPE_ISOLATED 6
|
jbe@2
|
245 #define UTF8PROC_DECOMP_TYPE_CIRCLE 7
|
jbe@2
|
246 #define UTF8PROC_DECOMP_TYPE_SUPER 8
|
jbe@2
|
247 #define UTF8PROC_DECOMP_TYPE_SUB 9
|
jbe@2
|
248 #define UTF8PROC_DECOMP_TYPE_VERTICAL 10
|
jbe@2
|
249 #define UTF8PROC_DECOMP_TYPE_WIDE 11
|
jbe@2
|
250 #define UTF8PROC_DECOMP_TYPE_NARROW 12
|
jbe@2
|
251 #define UTF8PROC_DECOMP_TYPE_SMALL 13
|
jbe@2
|
252 #define UTF8PROC_DECOMP_TYPE_SQUARE 14
|
jbe@2
|
253 #define UTF8PROC_DECOMP_TYPE_FRACTION 15
|
jbe@2
|
254 #define UTF8PROC_DECOMP_TYPE_COMPAT 16
|
jbe@2
|
255
|
Jiahao@15
|
256 DLLEXPORT extern const int8_t utf8proc_utf8class[256];
|
jbe@0
|
257
|
Jiahao@15
|
258 DLLEXPORT const char *utf8proc_version(void);
|
jbe@9
|
259
|
Jiahao@15
|
260 DLLEXPORT const char *utf8proc_errmsg(ssize_t errcode);
|
jbe@0
|
261 /*
|
jbe@0
|
262 * Returns a static error string for the given error code.
|
jbe@0
|
263 */
|
jbe@0
|
264
|
Jiahao@15
|
265 DLLEXPORT ssize_t utf8proc_iterate(const uint8_t *str, ssize_t strlen, int32_t *dst);
|
jbe@0
|
266 /*
|
jbe@0
|
267 * Reads a single char from the UTF-8 sequence being pointed to by 'str'.
|
jbe@0
|
268 * The maximum number of bytes read is 'strlen', unless 'strlen' is
|
jbe@0
|
269 * negative.
|
jbe@0
|
270 * If a valid unicode char could be read, it is stored in the variable
|
jbe@0
|
271 * being pointed to by 'dst', otherwise that variable will be set to -1.
|
jbe@0
|
272 * In case of success the number of bytes read is returned, otherwise a
|
jbe@0
|
273 * negative error code is returned.
|
jbe@0
|
274 */
|
jbe@0
|
275
|
Jiahao@15
|
276 DLLEXPORT bool utf8proc_codepoint_valid(int32_t uc);
|
jbe@7
|
277 /*
|
jbe@7
|
278 * Returns 1, if the given unicode code-point is valid, otherwise 0.
|
jbe@7
|
279 */
|
jbe@7
|
280
|
Jiahao@15
|
281 DLLEXPORT ssize_t utf8proc_encode_char(int32_t uc, uint8_t *dst);
|
jbe@0
|
282 /*
|
jbe@0
|
283 * Encodes the unicode char with the code point 'uc' as an UTF-8 string in
|
jbe@0
|
284 * the byte array being pointed to by 'dst'. This array has to be at least
|
jbe@0
|
285 * 4 bytes long.
|
jbe@7
|
286 * In case of success the number of bytes written is returned,
|
jbe@7
|
287 * otherwise 0.
|
jbe@0
|
288 * This function does not check if 'uc' is a valid unicode code point.
|
jbe@0
|
289 */
|
jbe@0
|
290
|
Jiahao@15
|
291 DLLEXPORT const utf8proc_property_t *utf8proc_get_property(int32_t uc);
|
jbe@0
|
292 /*
|
jbe@0
|
293 * Returns a pointer to a (constant) struct containing information about
|
jbe@0
|
294 * the unicode char with the given code point 'uc'.
|
jbe@0
|
295 * If the character is not existent a pointer to a special struct is
|
jbe@0
|
296 * returned, where 'category' is a NULL pointer.
|
jbe@0
|
297 * WARNING: The parameter 'uc' has to be in the range of 0x0000 to
|
jbe@0
|
298 * 0x10FFFF, otherwise the program might crash!
|
jbe@0
|
299 */
|
jbe@0
|
300
|
Jiahao@15
|
301 DLLEXPORT ssize_t utf8proc_decompose_char(
|
jbe@7
|
302 int32_t uc, int32_t *dst, ssize_t bufsize,
|
jbe@7
|
303 int options, int *last_boundclass
|
jbe@7
|
304 );
|
jbe@0
|
305 /*
|
jbe@0
|
306 * Writes a decomposition of the unicode char 'uc' into the array being
|
jbe@0
|
307 * pointed to by 'dst'.
|
jbe@0
|
308 * Following flags in the 'options' field are regarded:
|
jbe@2
|
309 * REJECTNA: an unassigned unicode code point leads to an error
|
jbe@2
|
310 * IGNORE: "default ignorable" chars are stripped
|
jbe@2
|
311 * CASEFOLD: unicode casefolding is applied
|
jbe@2
|
312 * COMPAT: replace certain characters with their
|
jbe@2
|
313 * compatibility decomposition
|
jbe@2
|
314 * CHARBOUND: Inserts 0xFF bytes before each grapheme cluster
|
jbe@3
|
315 * LUMP: lumps certain different characters together
|
jbe@3
|
316 * STRIPMARK: removes all character marks
|
jbe@7
|
317 * The pointer 'last_boundclass' has to point to an integer variable which
|
jbe@7
|
318 * is storing the last character boundary class, if the CHARBOUND option
|
jbe@7
|
319 * is used.
|
jbe@0
|
320 * In case of success the number of chars written is returned,
|
jbe@0
|
321 * in case of an error, a negative error code is returned.
|
jbe@0
|
322 * If the number of written chars would be bigger than 'bufsize',
|
jbe@0
|
323 * the buffer (up to 'bufsize') has inpredictable data, and the needed
|
jbe@0
|
324 * buffer size is returned.
|
jbe@0
|
325 * WARNING: The parameter 'uc' has to be in the range of 0x0000 to
|
jbe@0
|
326 * 0x10FFFF, otherwise the program might crash!
|
jbe@0
|
327 */
|
jbe@0
|
328
|
Jiahao@15
|
329 DLLEXPORT ssize_t utf8proc_decompose(
|
jbe@7
|
330 const uint8_t *str, ssize_t strlen,
|
jbe@7
|
331 int32_t *buffer, ssize_t bufsize, int options
|
jbe@7
|
332 );
|
jbe@0
|
333 /*
|
jbe@0
|
334 * Does the same as 'utf8proc_decompose_char', but acts on a whole UTF-8
|
jbe@0
|
335 * string, and orders the decomposed sequences correctly.
|
jbe@0
|
336 * If the NULLTERM flag in 'options' is set, processing will be stopped,
|
jbe@0
|
337 * when a NULL byte is encounted, otherwise 'strlen' bytes are processed.
|
jbe@0
|
338 * The result in form of unicode code points is written into the buffer
|
jbe@0
|
339 * being pointed to by 'buffer', having the length of 'bufsize' entries.
|
jbe@0
|
340 * In case of success the number of chars written is returned,
|
jbe@0
|
341 * in case of an error, a negative error code is returned.
|
jbe@0
|
342 * If the number of written chars would be bigger than 'bufsize',
|
jbe@0
|
343 * the buffer (up to 'bufsize') has inpredictable data, and the needed
|
jbe@0
|
344 * buffer size is returned.
|
jbe@0
|
345 */
|
jbe@0
|
346
|
Jiahao@15
|
347 DLLEXPORT ssize_t utf8proc_reencode(int32_t *buffer, ssize_t length, int options);
|
jbe@0
|
348 /*
|
jbe@0
|
349 * Reencodes the sequence of unicode characters given by the pointer
|
jbe@0
|
350 * 'buffer' and 'length' as UTF-8.
|
jbe@0
|
351 * The result is stored in the same memory area where the data is read.
|
jbe@0
|
352 * Following flags in the 'options' field are regarded:
|
jbe@0
|
353 * NLF2LS: converts LF, CRLF, CR and NEL into LS
|
jbe@0
|
354 * NLF2PS: converts LF, CRLF, CR and NEL into PS
|
jbe@0
|
355 * NLF2LF: converts LF, CRLF, CR and NEL into LF
|
jbe@0
|
356 * STRIPCC: strips or converts all non-affected control characters
|
jbe@7
|
357 * COMPOSE: tries to combine decomposed characters into composite
|
jbe@7
|
358 * characters
|
jbe@0
|
359 * STABLE: prohibits combining characters which would violate
|
jbe@0
|
360 * the unicode versioning stability
|
jbe@7
|
361 * In case of success the length of the resulting UTF-8 string is
|
jbe@7
|
362 * returned, otherwise a negative error code is returned.
|
jbe@0
|
363 * WARNING: The amount of free space being pointed to by 'buffer', has to
|
jbe@0
|
364 * exceed the amount of the input data by one byte, and the
|
jbe@0
|
365 * entries of the array pointed to by 'str' have to be in the
|
jbe@7
|
366 * range of 0x0000 to 0x10FFFF, otherwise the program might
|
jbe@7
|
367 * crash!
|
jbe@0
|
368 */
|
jbe@0
|
369
|
Jiahao@15
|
370 DLLEXPORT ssize_t utf8proc_map(
|
jbe@7
|
371 const uint8_t *str, ssize_t strlen, uint8_t **dstptr, int options
|
jbe@7
|
372 );
|
jbe@0
|
373 /*
|
jbe@0
|
374 * Maps the given UTF-8 string being pointed to by 'str' to a new UTF-8
|
jbe@7
|
375 * string, which is allocated dynamically, and afterwards pointed to by
|
jbe@7
|
376 * the pointer being pointed to by 'dstptr'.
|
jbe@0
|
377 * If the NULLTERM flag in the 'options' field is set, the length is
|
jbe@0
|
378 * determined by a NULL terminator, otherwise the parameter 'strlen' is
|
jbe@0
|
379 * evaluated to determine the string length, but in any case the result
|
jbe@7
|
380 * will be NULL terminated (though it might contain NULL characters
|
jbe@7
|
381 * before). Other flags in the 'options' field are passed to the functions
|
jbe@7
|
382 * defined above, and regarded as described.
|
jbe@0
|
383 * In case of success the length of the new string is returned,
|
jbe@0
|
384 * otherwise a negative error code is returned.
|
jbe@0
|
385 * NOTICE: The memory of the new UTF-8 string will have been allocated with
|
jbe@0
|
386 * 'malloc', and has theirfore to be freed with 'free'.
|
jbe@0
|
387 */
|
jbe@0
|
388
|
Jiahao@15
|
389 DLLEXPORT uint8_t *utf8proc_NFD(const uint8_t *str);
|
Jiahao@15
|
390 DLLEXPORT uint8_t *utf8proc_NFC(const uint8_t *str);
|
Jiahao@15
|
391 DLLEXPORT uint8_t *utf8proc_NFKD(const uint8_t *str);
|
Jiahao@15
|
392 DLLEXPORT uint8_t *utf8proc_NFKC(const uint8_t *str);
|
jbe@0
|
393 /*
|
jbe@0
|
394 * Returns a pointer to newly allocated memory of a NFD, NFC, NFKD or NFKC
|
jbe@0
|
395 * normalized version of the null-terminated string 'str'.
|
jbe@0
|
396 */
|
jbe@0
|
397
|
Jan@12
|
398 #ifdef __cplusplus
|
Jan@12
|
399 }
|
Jan@12
|
400 #endif
|
jbe@0
|
401
|
jbe@0
|
402 #endif
|
jbe@0
|
403
|