|
1 /* |
|
2 * Copyright (c) 2000 - 2001 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** ----------------------------------------------------------------------- ** |
|
21 @package: NW_String |
|
22 |
|
23 @synopsis: default |
|
24 |
|
25 @description: default |
|
26 |
|
27 ** ----------------------------------------------------------------------- **/ |
|
28 |
|
29 #ifndef NW_STRING_CHARACTER_H |
|
30 #define NW_STRING_CHARACTER_H |
|
31 |
|
32 #include <xml/cxml/cxml_proj.h> |
|
33 |
|
34 #ifdef __cplusplus |
|
35 extern "C" { |
|
36 #endif /* __cplusplus */ |
|
37 |
|
38 #define HTTP_iso_10646_ucs_2 0x03E8 |
|
39 #define HTTP_iso_8859_1 0x04 |
|
40 #define HTTP_us_ascii 0x03 |
|
41 #define HTTP_utf_8 0x6A |
|
42 #define HTTP_utf_16 1015 |
|
43 |
|
44 |
|
45 /** ----------------------------------------------------------------------- ** |
|
46 @struct: NW_String_UCS2Buff |
|
47 |
|
48 @synopsis: A ucs2 character as stored in a ucs2 string. |
|
49 |
|
50 @scope: public |
|
51 @variables: |
|
52 NW_Byte bytes[2] |
|
53 default |
|
54 |
|
55 @description: A ucs2 character as stored in a ucs2 string. This is |
|
56 different from a NW_Ucs2 which is a 16 bit unsigned |
|
57 quantity stored in the platform's native integer |
|
58 representation. NW_UCS2Buff_t stores bytes in |
|
59 native-endian format. |
|
60 |
|
61 ** ----------------------------------------------------------------------- **/ |
|
62 typedef struct NW_String_UCS2Buff_s { |
|
63 NW_Byte bytes[2]; |
|
64 } NW_String_UCS2Buff_t; |
|
65 |
|
66 |
|
67 /** ----------------------------------------------------------------------- ** |
|
68 @function: NW_String_charsetValid |
|
69 |
|
70 @synopsis: Checks if charset is valid. |
|
71 |
|
72 @scope: public |
|
73 |
|
74 @parameters: |
|
75 [in] NW_Uint32 encoding |
|
76 default |
|
77 |
|
78 @description: Checks if charset is valid. |
|
79 |
|
80 @returns: NW_Status_t |
|
81 Status of operation. |
|
82 |
|
83 [NW_STAT_SUCCESS] |
|
84 Valid charset. |
|
85 |
|
86 [NW_STAT_WBXML_ERROR_CHARSET_UNSUPPORTED] |
|
87 Invalid charset. |
|
88 |
|
89 ** ----------------------------------------------------------------------- **/ |
|
90 NW_Status_t |
|
91 NW_String_charsetValid (NW_Uint32 encoding); |
|
92 |
|
93 |
|
94 /** ----------------------------------------------------------------------- ** |
|
95 @function: NW_String_valid |
|
96 |
|
97 @synopsis: Validate string storage. |
|
98 |
|
99 @scope: public |
|
100 |
|
101 @parameters: |
|
102 [in] NW_Byte* storage |
|
103 The storage. |
|
104 |
|
105 [in] NW_Uint32 length |
|
106 The length. |
|
107 |
|
108 [in] NW_Uint32 encoding |
|
109 The encoding. |
|
110 |
|
111 @description: Validate string storage. |
|
112 |
|
113 @returns: NW_Int32 |
|
114 1 if storage is specified encoding, otherwise 0. |
|
115 |
|
116 ** ----------------------------------------------------------------------- **/ |
|
117 NW_Int32 |
|
118 NW_String_valid(NW_Byte* storage, NW_Uint32 length, NW_Uint32 encoding); |
|
119 |
|
120 |
|
121 /** ----------------------------------------------------------------------- ** |
|
122 @function: NW_String_writeUTF8Char |
|
123 |
|
124 @synopsis: Write chars to storage in UTF8 format. |
|
125 |
|
126 @scope: public |
|
127 |
|
128 @parameters: |
|
129 [in] NW_Ucs2 c |
|
130 Character to write. |
|
131 |
|
132 [in-out] NW_Byte* buff |
|
133 Buffer to write into.default |
|
134 |
|
135 @description: Write a NW_Ucs2 into a buffer as UTF8. Returns number of |
|
136 bytes written. |
|
137 |
|
138 @returns: NW_Uint32 |
|
139 Number of bytes written. |
|
140 |
|
141 ** ----------------------------------------------------------------------- **/ |
|
142 NW_Uint32 |
|
143 NW_String_writeUTF8Char (NW_Ucs2 c, NW_Byte* buff); |
|
144 |
|
145 |
|
146 /** ----------------------------------------------------------------------- ** |
|
147 @function: NW_String_readChar |
|
148 |
|
149 @synopsis: Read chars from storage. |
|
150 |
|
151 @scope: public |
|
152 |
|
153 @parameters: |
|
154 [in] NW_Byte* buff |
|
155 default |
|
156 |
|
157 [out] NW_Ucs2* c |
|
158 default |
|
159 |
|
160 [in] NW_Uint32 encoding |
|
161 default |
|
162 |
|
163 @description: Read one character of some encoding, returning the |
|
164 NW_Ucs2 equivalent and the count of raw bytes read. |
|
165 |
|
166 @returns: NW_Int32 |
|
167 Number of characters read or -1 if invalid encoding. |
|
168 |
|
169 ** ----------------------------------------------------------------------- **/ |
|
170 IMPORT_C NW_Int32 |
|
171 NW_String_readChar (NW_Byte* buff, NW_Ucs2* c, NW_Uint32 encoding); |
|
172 |
|
173 |
|
174 /** ----------------------------------------------------------------------- ** |
|
175 @function: NW_String_charBuffGetLength |
|
176 |
|
177 @synopsis: String length of input character buffer. |
|
178 |
|
179 @scope: public |
|
180 |
|
181 @parameters: |
|
182 [in] void* buffer |
|
183 default |
|
184 |
|
185 [in] NW_Uint32 encoding |
|
186 default |
|
187 |
|
188 [out] NW_Uint32* byte_count |
|
189 default |
|
190 |
|
191 @description: Get the length of a character string in some |
|
192 encoding. Returns the number of characters (less the |
|
193 terminating char). The out param byte_count returns |
|
194 the number of bytes of storage scanned (including the |
|
195 terminating char). Note that there is NO validity |
|
196 check here. This should be done first if needed. |
|
197 |
|
198 @returns: NW_Int32 |
|
199 Returns number of characters read. |
|
200 |
|
201 ** ----------------------------------------------------------------------- **/ |
|
202 IMPORT_C NW_Int32 |
|
203 NW_String_charBuffGetLength (void* buffer, NW_Uint32 encoding, NW_Uint32* byte_count); |
|
204 |
|
205 |
|
206 /* ----------------------------------------------------------------------- ** |
|
207 Conversions |
|
208 ** ----------------------------------------------------------------------- **/ |
|
209 |
|
210 |
|
211 /** ----------------------------------------------------------------------- ** |
|
212 @function: NW_String_charToUCS2Buff |
|
213 |
|
214 @synopsis: Convert to UCS2 buffer. |
|
215 |
|
216 @scope: public |
|
217 |
|
218 @parameters: |
|
219 [in] NW_Byte* s |
|
220 Characters to convert. |
|
221 |
|
222 [in] NW_Uint32 encoding |
|
223 Initial encoding. |
|
224 |
|
225 @description: Conversions among character strings of various types |
|
226 and ucs2. These functions assume that the length in |
|
227 characters of the input buffer has been |
|
228 pre-calculated, so that this operation doesn't have to |
|
229 be performed for every conversion. This works well for |
|
230 String_t which store the character count. |
|
231 |
|
232 @returns: NW_String_UCS2Buff_t* |
|
233 New UCS2 buffer or NULL if failed. |
|
234 |
|
235 ** ----------------------------------------------------------------------- **/ |
|
236 NW_String_UCS2Buff_t* |
|
237 NW_String_charToUCS2Buff (NW_Byte* s, NW_Uint32 encoding); |
|
238 |
|
239 |
|
240 /** ----------------------------------------------------------------------- ** |
|
241 @function: NW_String_UTF8ToUCS2Buff |
|
242 |
|
243 @synopsis: Convert UTF8 to UCS2 buffer. |
|
244 |
|
245 @scope: public |
|
246 |
|
247 @parameters: |
|
248 [in] NW_Byte* s |
|
249 Characters to convert. |
|
250 |
|
251 @description: Convert UTF8 to UCS2 buffer. |
|
252 |
|
253 @returns: NW_String_UCS2Buff_t* |
|
254 Converted buffer or NULL if failed. |
|
255 |
|
256 ** ----------------------------------------------------------------------- **/ |
|
257 NW_String_UCS2Buff_t* |
|
258 NW_String_UTF8ToUCS2Buff (NW_Byte* s); |
|
259 |
|
260 |
|
261 /** ----------------------------------------------------------------------- ** |
|
262 @function: NW_String_ISO88591ToUCS2Buff |
|
263 |
|
264 @synopsis: Convert ISO88591 to UCS2 buffer. |
|
265 |
|
266 @scope: public |
|
267 |
|
268 @parameters: |
|
269 [in] NW_Byte* s |
|
270 Characters to convert. |
|
271 |
|
272 @description: Convert ISO88591 to UCS2 buffer. |
|
273 |
|
274 @returns: NW_String_UCS2Buff_t* |
|
275 Converted buffer or NULL if failed. |
|
276 |
|
277 ** ----------------------------------------------------------------------- **/ |
|
278 NW_String_UCS2Buff_t* |
|
279 NW_String_ISO88591ToUCS2Buff (NW_Byte* s); |
|
280 |
|
281 |
|
282 /** ----------------------------------------------------------------------- ** |
|
283 @function: NW_String_UCS2ToUTF8 |
|
284 |
|
285 @synopsis: Convert UCS2 to UTF8. |
|
286 |
|
287 @scope: public |
|
288 |
|
289 @parameters: |
|
290 [in] NW_String_UCS2Buff_t* s |
|
291 Characters to convert. |
|
292 |
|
293 [in] NW_Uint32 length |
|
294 Number of characters. |
|
295 |
|
296 @description: Convert UCS2 to UTF8. |
|
297 |
|
298 @returns: NW_Byte* |
|
299 Converted buffer or NULL if failed. |
|
300 |
|
301 ** ----------------------------------------------------------------------- **/ |
|
302 NW_Byte* |
|
303 NW_String_UCS2ToUTF8 (NW_String_UCS2Buff_t* s, NW_Uint32 length); |
|
304 |
|
305 |
|
306 /** ----------------------------------------------------------------------- ** |
|
307 @function: NW_String_UCS2ToISO88591 |
|
308 |
|
309 @synopsis: Convert UCS2 to ISO88591. |
|
310 |
|
311 @scope: public |
|
312 |
|
313 @parameters: |
|
314 [in] NW_String_UCS2Buff_t* s |
|
315 Characters to convert. |
|
316 |
|
317 [in] NW_Uint32 length |
|
318 Number of characters. |
|
319 |
|
320 @description: Convert UCS2 to ISO88591. |
|
321 |
|
322 @returns: NW_Byte* |
|
323 Converted buffer or NULL if failed. |
|
324 |
|
325 ** ----------------------------------------------------------------------- **/ |
|
326 NW_Byte* |
|
327 NW_String_UCS2ToISO88591 (NW_String_UCS2Buff_t* s, NW_Uint32 length); |
|
328 |
|
329 |
|
330 /** ----------------------------------------------------------------------- ** |
|
331 @function: NW_String_UCS2BuffCmp |
|
332 |
|
333 @synopsis: Ordered comparison of ucs2 strings. |
|
334 |
|
335 @scope: public |
|
336 |
|
337 @parameters: |
|
338 [in] NW_String_UCS2Buff_t* s1 |
|
339 The character buffer. |
|
340 |
|
341 [in] NW_String_UCS2Buff_t* s2 |
|
342 The other character buffer. |
|
343 |
|
344 [in] NW_Bool matchCase |
|
345 If NW_TRUE then case sensitive comparison. |
|
346 |
|
347 @description: Ordered comparison of ucs2 strings. |
|
348 |
|
349 @returns: NW_Int32 |
|
350 Return 0 if equal, -1 if s1 comes before s2 otherwise 1. |
|
351 |
|
352 ** ----------------------------------------------------------------------- **/ |
|
353 NW_Int32 |
|
354 NW_String_UCS2BuffCmp (NW_String_UCS2Buff_t* s1, |
|
355 NW_String_UCS2Buff_t* s2, |
|
356 NW_Bool matchCase); |
|
357 |
|
358 |
|
359 /** ----------------------------------------------------------------------- ** |
|
360 @function: NW_String_CmpToNativeAlignedUCS2 |
|
361 |
|
362 @synopsis: Compare to native aligned UCS2. |
|
363 |
|
364 @scope: public |
|
365 |
|
366 @parameters: |
|
367 [in] NW_Uint32 encoding |
|
368 The encoding. |
|
369 |
|
370 [in] NW_Uint32 charCount |
|
371 The charcount. |
|
372 |
|
373 [in] NW_Uint8* s1 |
|
374 The character buffer. |
|
375 |
|
376 [in] NW_Uint16* s2 |
|
377 The other character buffer. |
|
378 |
|
379 [out] NW_Int32* r |
|
380 Result of comparison. |
|
381 |
|
382 @description: Compare to native aligned UCS2. Assumes s2 is null |
|
383 terminated, native byte order and aligned for |
|
384 16-bit access. |
|
385 |
|
386 @returns: NW_Status_t |
|
387 Status of operation. |
|
388 |
|
389 [NW_STAT_SUCCESS] |
|
390 Valid string. |
|
391 |
|
392 [NW_STAT_FAILURE] |
|
393 Invalid string. |
|
394 |
|
395 ** ----------------------------------------------------------------------- **/ |
|
396 NW_Status_t |
|
397 NW_String_CmpToNativeAlignedUCS2 (NW_Uint32 encoding, NW_Uint32 charCount, |
|
398 NW_Uint8* s1, NW_Uint16* s2, |
|
399 NW_Int32* r); |
|
400 |
|
401 #ifdef __cplusplus |
|
402 } /* extern "C" { */ |
|
403 #endif /* __cplusplus */ |
|
404 |
|
405 #endif /* NW_STRING_CHARACTER_H */ |