]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ****************************************************************************** | |
3 | * | |
374ca955 | 4 | * Copyright (C) 1998-2004, International Business Machines |
b75a7d8f A |
5 | * Corporation and others. All Rights Reserved. |
6 | * | |
7 | ****************************************************************************** | |
8 | * | |
9 | * File ustdio.h | |
10 | * | |
11 | * Modification History: | |
12 | * | |
13 | * Date Name Description | |
14 | * 10/16/98 stephen Creation. | |
15 | * 11/06/98 stephen Modified per code review. | |
16 | * 03/12/99 stephen Modified for new C API. | |
17 | * 07/19/99 stephen Minor doc update. | |
18 | * 02/01/01 george Added sprintf & sscanf with all of its variants | |
19 | ****************************************************************************** | |
20 | */ | |
21 | ||
22 | #ifndef USTDIO_H | |
23 | #define USTDIO_H | |
24 | ||
25 | #include <stdio.h> | |
26 | #include <stdarg.h> | |
27 | ||
28 | #include "unicode/utypes.h" | |
29 | #include "unicode/ucnv.h" | |
30 | #include "unicode/utrans.h" | |
31 | ||
32 | /* | |
33 | TODO | |
34 | The following is a small list as to what is currently wrong/suggestions for | |
35 | ustdio. | |
36 | ||
374ca955 A |
37 | * Make sure that * in the scanf format specification works for all formats. |
38 | * Each UFILE takes up at least 2KB. | |
39 | Look into adding setvbuf() for configurable buffers. | |
b75a7d8f A |
40 | * This library does buffering. The OS should do this for us already. Check on |
41 | this, and remove it from this library, if this is the case. Double buffering | |
42 | wastes a lot of time and space. | |
374ca955 | 43 | * Test stdin and stdout with the u_f* functions |
b75a7d8f A |
44 | * Testing should be done for reading and writing multi-byte encodings, |
45 | and make sure that a character that is contained across buffer boundries | |
46 | works even for incomplete characters. | |
47 | * Make sure that the last character is flushed when the file/string is closed. | |
48 | * snprintf should follow the C99 standard for the return value, which is | |
49 | return the number of characters (excluding the trailing '\0') | |
50 | which would have been written to the destination string regardless | |
51 | of available space. This is like pre-flighting. | |
52 | * Everything that uses %s should do what operator>> does for UnicodeString. | |
53 | It should convert one byte at a time, and once a character is | |
54 | converted then check to see if it's whitespace or in the scanset. | |
55 | If it's whitespace or in the scanset, put all the bytes back (do nothing | |
56 | for sprintf/sscanf). | |
57 | * If bad string data is encountered, make sure that the function fails | |
58 | without memory leaks and the unconvertable characters are valid | |
59 | substitution or are escaped characters. | |
60 | * u_fungetc() can't unget a character when it's at the beginning of the | |
374ca955 A |
61 | internal conversion buffer. For example, read the buffer size # of |
62 | characters, and then ungetc to get the previous character that was | |
63 | at the end of the last buffer. | |
b75a7d8f A |
64 | * u_fflush() and u_fclose should return an int32_t like C99 functions. |
65 | 0 is returned if the operation was successful and EOF otherwise. | |
66 | * u_fsettransliterator does not support U_READ side of transliteration. | |
67 | * The format specifier should limit the size of a format or honor it in | |
374ca955 | 68 | order to prevent buffer overruns. (e.g. %256.256d). |
b75a7d8f A |
69 | * u_fread and u_fwrite don't exist. They're needed for reading and writing |
70 | data structures without any conversion. | |
71 | * u_file_read and u_file_write are used for writing strings. u_fgets and | |
72 | u_fputs or u_fread and u_fwrite should be used to do this. | |
374ca955 | 73 | * The width parameter for all scanf formats, including scanset, needs |
b75a7d8f | 74 | better testing. This prevents buffer overflows. |
374ca955 A |
75 | * Figure out what is suppose to happen when a codepage is changed midstream. |
76 | Maybe a flush or a rewind are good enough. | |
77 | * Make sure that a UFile opened with "rw" can be used after using | |
78 | u_fflush with a u_frewind. | |
79 | * scanf(%i) should detect what type of number to use. | |
80 | * Add more testing of the alternate format, %# | |
81 | * Look at newline handling of fputs/puts | |
82 | * Think more about codeunit/codepoint error handling/support in %S,%s,%C,%c,%[] | |
83 | * Complete the file documentation with proper doxygen formatting. | |
84 | See http://oss.software.ibm.com/pipermail/icu/2003-July/005647.html | |
b75a7d8f A |
85 | */ |
86 | ||
374ca955 A |
87 | /** |
88 | * \file | |
89 | * \brief C API: Unicode stdio-like API | |
90 | * | |
91 | * <h2>Unicode stdio-like C API</h2> | |
92 | General printf format:<br> | |
93 | %[format modifier][width][.precision][type modifier][format] | |
94 | ||
95 | General scanf format:<br> | |
96 | %[*][format modifier][width][type modifier][format] | |
97 | ||
98 | <table cellspacing="3"> | |
99 | <tr><td>format</td><td>default<br>type</td><td>description</td></tr> | |
100 | <tr><td>%E</td><td>double</td><td>Scientific with an uppercase exponent</td></tr> | |
101 | <tr><td>%e</td><td>double</td><td>Scientific with a lowercase exponent</td></tr> | |
102 | <tr><td>%G</td><td>double</td><td>Use %E or %f for best format</td></tr> | |
103 | <tr><td>%g</td><td>double</td><td>Use %e or %f for best format</td></tr> | |
104 | <tr><td>%f</td><td>double</td><td>Simple floating point without the exponent</td></tr> | |
105 | <tr><td>%X</td><td>int32_t</td><td>ustdio special uppercase hex radix formatting</td></tr> | |
106 | <tr><td>%x</td><td>int32_t</td><td>ustdio special lowercase hex radix formatting</td></tr> | |
107 | <tr><td>%d</td><td>int32_t</td><td>Decimal format</td></tr> | |
108 | <tr><td>%i</td><td>int32_t</td><td>Same as %d</td></tr> | |
109 | <tr><td>%n</td><td>int32_t</td><td>count (write the number of UTF-16 codeunits read/written)</td></tr> | |
110 | <tr><td>%o</td><td>int32_t</td><td>ustdio special octal radix formatting</td></tr> | |
111 | <tr><td>%u</td><td>uint32_t</td><td>Decimal format</td></tr> | |
112 | <tr><td>%p</td><td>void *</td><td>Prints the pointer value</td></tr> | |
113 | <tr><td>%s</td><td>char *</td><td>Use default converter or specified converter from fopen</td></tr> | |
114 | <tr><td>%c</td><td>char</td><td>Use default converter or specified converter from fopen<br> | |
115 | When width is specified, this acts like a non-NULL-terminated char * string.<br> | |
116 | By default, only one char is written.</td></tr> | |
117 | <tr><td>%S</td><td>UChar *</td><td>Null terminated UTF-16 string</td></tr> | |
118 | <tr><td>%C</td><td>UChar</td><td>16-bit Unicode code unit<br> | |
119 | When width is specified, this acts like a non-NULL-terminated UChar * string<br> | |
120 | By default, only one codepoint is written.</td></tr> | |
121 | <tr><td>%[]</td><td>UChar *</td><td>(scanf only) Null terminated UTF-16 string which contains the filtered set of characters specified by the UnicodeSet</td></tr> | |
122 | <tr><td>%%</td><td>N/A</td><td>Show a percent sign</td></tr> | |
123 | </table> | |
124 | ||
125 | Format modifiers | |
126 | <table> | |
127 | <tr><td>modifier</td><td>formats</td><td>type</td><td>comments</td></tr> | |
128 | <tr><td>%h</td><td>%d, %i, %o, %x</td><td>int16_t</td><td>short format</td></tr> | |
129 | <tr><td>%h</td><td>%u</td><td>uint16_t</td><td>short format</td></tr> | |
130 | <tr><td>%h</td><td>c</td><td>char</td><td><b>(Unimplemented)</b> Use invariant converter</td></tr> | |
131 | <tr><td>%h</td><td>s</td><td>char *</td><td><b>(Unimplemented)</b> Use invariant converter</td></tr> | |
132 | <tr><td>%h</td><td>C</td><td>char</td><td><b>(Unimplemented)</b> 8-bit Unicode code unit</td></tr> | |
133 | <tr><td>%h</td><td>S</td><td>char *</td><td><b>(Unimplemented)</b> Null terminated UTF-8 string</td></tr> | |
134 | <tr><td>%l</td><td>%d, %i, %o, %x</td><td>int32_t</td><td>long format (no effect)</td></tr> | |
135 | <tr><td>%l</td><td>%u</td><td>uint32_t</td><td>long format (no effect)</td></tr> | |
136 | <tr><td>%l</td><td>c</td><td>N/A</td><td><b>(Unimplemented)</b> Reserved for future implementation</td></tr> | |
137 | <tr><td>%l</td><td>s</td><td>N/A</td><td><b>(Unimplemented)</b> Reserved for future implementation</td></tr> | |
138 | <tr><td>%l</td><td>C</td><td>UChar32</td><td><b>(Unimplemented)</b> 32-bit Unicode code unit</td></tr> | |
139 | <tr><td>%l</td><td>S</td><td>UChar32 *</td><td><b>(Unimplemented)</b> Null terminated UTF-32 string</td></tr> | |
140 | <tr><td>%ll</td><td>%d, %i, %o, %x</td><td>int64_t</td><td>long long format</td></tr> | |
141 | <tr><td>%ll</td><td>%u</td><td>uint64_t</td><td><b>(Unimplemented)</b> long long format</td></tr> | |
142 | <tr><td>%-</td><td><i>all</i></td><td>N/A</td><td>Left justify</td></tr> | |
143 | <tr><td>%+</td><td>%d, %i, %o, %x, %e, %f, %g, %E, %G</td><td>N/A</td><td>Always show the plus or minus sign. Needs data for plus sign.</td></tr> | |
144 | <tr><td>% </td><td>%d, %i, %o, %x, %e, %f, %g, %E, %G</td><td>N/A</td><td>Instead of a "+" output a blank character for positive numbers.</td></tr> | |
145 | <tr><td>%#</td><td>%d, %i, %o, %x, %e, %f, %g, %E, %G</td><td>N/A</td><td>Precede octal value with 0, hex with 0x and show the | |
146 | decimal point for floats.</td></tr> | |
147 | <tr><td>%<i>n</i></td><td><i>all</i></td><td>N/A</td><td>Width of input/output. num is an actual number from 0 to | |
148 | some large number.</td></tr> | |
149 | <tr><td>%.<i>n</i></td><td>%e, %f, %g, %E, %F, %G</td><td>N/A</td><td>Significant digits precision. num is an actual number from | |
150 | 0 to some large number.<br>If * is used in printf, then the precision is passed in as an argument before the number to be formatted.</td></tr> | |
151 | </table> | |
152 | ||
153 | printf modifier | |
154 | %* int32_t Next argument after this one specifies the width | |
155 | ||
156 | scanf modifier | |
157 | %* N/A This field is scanned, but not stored | |
158 | ||
159 | */ | |
160 | ||
b75a7d8f A |
161 | |
162 | /** | |
163 | * When an end of file is encountered, this value can be returned. | |
164 | * @see u_fgetc | |
374ca955 | 165 | * @draft 3.0 |
b75a7d8f A |
166 | */ |
167 | #define U_EOF 0xFFFF | |
168 | ||
374ca955 | 169 | /** Forward declaration of a Unicode-aware file @draft 3.0 */ |
b75a7d8f A |
170 | typedef struct UFILE UFILE; |
171 | ||
172 | /** | |
173 | * Enum for which direction of stream a transliterator applies to. | |
174 | * @see u_fsettransliterator | |
374ca955 | 175 | * @draft 3.0 |
b75a7d8f A |
176 | */ |
177 | typedef enum { | |
178 | U_READ = 1, | |
179 | U_WRITE = 2, | |
180 | U_READWRITE =3 /* == (U_READ | U_WRITE) */ | |
181 | } UFileDirection; | |
182 | ||
183 | /** | |
184 | * Open a UFILE. | |
185 | * A UFILE is a wrapper around a FILE* that is locale and codepage aware. | |
186 | * That is, data written to a UFILE will be formatted using the conventions | |
187 | * specified by that UFILE's Locale; this data will be in the character set | |
188 | * specified by that UFILE's codepage. | |
189 | * @param filename The name of the file to open. | |
190 | * @param perm The read/write permission for the UFILE; one of "r", "w", "rw" | |
191 | * @param locale The locale whose conventions will be used to format | |
192 | * and parse output. If this parameter is NULL, the default locale will | |
193 | * be used. | |
194 | * @param codepage The codepage in which data will be written to and | |
374ca955 A |
195 | * read from the file. If this paramter is NULL the system default codepage |
196 | * will be used. | |
b75a7d8f | 197 | * @return A new UFILE, or NULL if an error occurred. |
374ca955 | 198 | * @draft 3.0 |
b75a7d8f A |
199 | */ |
200 | U_CAPI UFILE* U_EXPORT2 | |
201 | u_fopen(const char *filename, | |
202 | const char *perm, | |
203 | const char *locale, | |
204 | const char *codepage); | |
205 | ||
206 | /** | |
207 | * Open a UFILE on top of an existing FILE* stream. | |
208 | * @param f The FILE* to which this UFILE will attach. | |
209 | * @param locale The locale whose conventions will be used to format | |
210 | * and parse output. If this parameter is NULL, the default locale will | |
211 | * be used. | |
212 | * @param codepage The codepage in which data will be written to and | |
213 | * read from the file. If this paramter is NULL, data will be written and | |
214 | * read using the default codepage for <TT>locale</TT>, unless <TT>locale</TT> | |
215 | * is NULL, in which case the system default codepage will be used. | |
216 | * @return A new UFILE, or NULL if an error occurred. | |
374ca955 | 217 | * @draft 3.0 |
b75a7d8f A |
218 | */ |
219 | U_CAPI UFILE* U_EXPORT2 | |
220 | u_finit(FILE *f, | |
221 | const char *locale, | |
222 | const char *codepage); | |
223 | ||
374ca955 A |
224 | /** |
225 | * Create a UFILE that can be used for localized formatting or parsing. | |
226 | * The u_sprintf and u_sscanf functions do not read or write numbers for a | |
227 | * specific locale. The ustdio.h file functions can be used on this UFILE. | |
228 | * The string is usable once u_fclose or u_fflush has been called on the | |
229 | * returned UFILE. | |
230 | * @param stringBuf The string used for reading or writing. | |
231 | * @param capacity The number of code units available for use in stringBuf | |
232 | * @param locale The locale whose conventions will be used to format | |
233 | * and parse output. If this parameter is NULL, the default locale will | |
234 | * be used. | |
235 | * @return A new UFILE, or NULL if an error occurred. | |
236 | * @draft 3.0 | |
237 | */ | |
238 | U_CAPI UFILE* U_EXPORT2 | |
239 | u_fstropen(UChar *stringBuf, | |
240 | int32_t capacity, | |
241 | const char *locale); | |
242 | ||
b75a7d8f A |
243 | /** |
244 | * Close a UFILE. | |
245 | * @param file The UFILE to close. | |
374ca955 | 246 | * @draft 3.0 |
b75a7d8f A |
247 | */ |
248 | U_CAPI void U_EXPORT2 | |
249 | u_fclose(UFILE *file); | |
250 | ||
374ca955 A |
251 | /** |
252 | * Tests if the UFILE is at the end of the file stream. | |
253 | * @param f The UFILE from which to read. | |
254 | * @return Returns TRUE after the first read operation that attempts to | |
255 | * read past the end of the file. It returns FALSE if the current position is | |
256 | * not end of file. | |
257 | * @draft 3.0 | |
258 | */ | |
259 | U_CAPI UBool U_EXPORT2 | |
260 | u_feof(UFILE *f); | |
261 | ||
b75a7d8f A |
262 | /** |
263 | * Flush output of a UFILE. Implies a flush of | |
264 | * converter/transliterator state. (That is, a logical break is | |
265 | * made in the output stream - for example if a different type of | |
266 | * output is desired.) The underlying OS level file is also flushed. | |
267 | * @param file The UFILE to flush. | |
374ca955 | 268 | * @draft 3.0 |
b75a7d8f A |
269 | */ |
270 | U_CAPI void U_EXPORT2 | |
271 | u_fflush(UFILE *file); | |
272 | ||
374ca955 A |
273 | /** |
274 | * Rewind the file pointer to the beginning of the file. | |
275 | * @param file The UFILE to rewind. | |
276 | * @draft 3.0 | |
277 | */ | |
278 | U_CAPI void | |
279 | u_frewind(UFILE *file); | |
280 | ||
b75a7d8f A |
281 | /** |
282 | * Get the FILE* associated with a UFILE. | |
283 | * @param f The UFILE | |
284 | * @return A FILE*, owned by the UFILE. The FILE <EM>must not</EM> be closed. | |
374ca955 | 285 | * @draft 3.0 |
b75a7d8f A |
286 | */ |
287 | U_CAPI FILE* U_EXPORT2 | |
288 | u_fgetfile(UFILE *f); | |
289 | ||
290 | #if !UCONFIG_NO_FORMATTING | |
291 | ||
292 | /** | |
293 | * Get the locale whose conventions are used to format and parse output. | |
294 | * This is the same locale passed in the preceding call to<TT>u_fsetlocale</TT> | |
295 | * or <TT>u_fopen</TT>. | |
296 | * @param file The UFILE to set. | |
297 | * @return The locale whose conventions are used to format and parse output. | |
374ca955 | 298 | * @draft 3.0 |
b75a7d8f A |
299 | */ |
300 | U_CAPI const char* U_EXPORT2 | |
301 | u_fgetlocale(UFILE *file); | |
302 | ||
303 | /** | |
304 | * Set the locale whose conventions will be used to format and parse output. | |
305 | * @param locale The locale whose conventions will be used to format | |
306 | * and parse output. | |
307 | * @param file The UFILE to query. | |
308 | * @return NULL if successful, otherwise a negative number. | |
374ca955 | 309 | * @draft 3.0 |
b75a7d8f A |
310 | */ |
311 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
312 | u_fsetlocale(UFILE *file, |
313 | const char *locale); | |
b75a7d8f A |
314 | |
315 | #endif | |
316 | ||
317 | /** | |
318 | * Get the codepage in which data is written to and read from the UFILE. | |
319 | * This is the same codepage passed in the preceding call to | |
320 | * <TT>u_fsetcodepage</TT> or <TT>u_fopen</TT>. | |
321 | * @param file The UFILE to query. | |
322 | * @return The codepage in which data is written to and read from the UFILE, | |
323 | * or NULL if an error occurred. | |
374ca955 | 324 | * @draft 3.0 |
b75a7d8f A |
325 | */ |
326 | U_CAPI const char* U_EXPORT2 | |
327 | u_fgetcodepage(UFILE *file); | |
328 | ||
329 | /** | |
330 | * Set the codepage in which data will be written to and read from the UFILE. | |
331 | * All Unicode data written to the UFILE will be converted to this codepage | |
374ca955 A |
332 | * before it is written to the underlying FILE*. It it generally a bad idea to |
333 | * mix codepages within a file. This should only be called right | |
334 | * after opening the <TT>UFile</TT>, or after calling <TT>u_frewind</TT>. | |
b75a7d8f A |
335 | * @param codepage The codepage in which data will be written to |
336 | * and read from the file. For example <TT>"latin-1"</TT> or <TT>"ibm-943</TT>. | |
337 | * A value of NULL means the default codepage for the UFILE's current | |
338 | * locale will be used. | |
339 | * @param file The UFILE to set. | |
374ca955 A |
340 | * @return 0 if successful, otherwise a negative number. |
341 | * @see u_frewind | |
342 | * @draft 3.0 | |
b75a7d8f A |
343 | */ |
344 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
345 | u_fsetcodepage(const char *codepage, |
346 | UFILE *file); | |
b75a7d8f A |
347 | |
348 | ||
349 | /** | |
350 | * Returns an alias to the converter being used for this file. | |
374ca955 | 351 | * @param f The UFILE to get the value from |
b75a7d8f | 352 | * @return alias to the converter |
374ca955 | 353 | * @draft 3.0 |
b75a7d8f A |
354 | */ |
355 | U_CAPI UConverter* U_EXPORT2 u_fgetConverter(UFILE *f); | |
356 | ||
374ca955 A |
357 | #if !UCONFIG_NO_FORMATTING |
358 | ||
b75a7d8f A |
359 | /* Output functions */ |
360 | ||
361 | /** | |
362 | * Write formatted data to a UFILE. | |
363 | * @param f The UFILE to which to write. | |
364 | * @param patternSpecification A pattern specifying how <TT>u_fprintf</TT> will | |
365 | * interpret the variable arguments received and format the data. | |
366 | * @return The number of Unicode characters written to <TT>f</TT>. | |
374ca955 | 367 | * @draft 3.0 |
b75a7d8f A |
368 | */ |
369 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
370 | u_fprintf(UFILE *f, |
371 | const char *patternSpecification, | |
372 | ... ); | |
b75a7d8f A |
373 | |
374 | /** | |
375 | * Write formatted data to a UFILE. | |
376 | * This is identical to <TT>u_fprintf</TT>, except that it will | |
374ca955 | 377 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>. |
b75a7d8f A |
378 | * @param f The UFILE to which to write. |
379 | * @param patternSpecification A pattern specifying how <TT>u_fprintf</TT> will | |
380 | * interpret the variable arguments received and format the data. | |
381 | * @param ap The argument list to use. | |
382 | * @return The number of Unicode characters written to <TT>f</TT>. | |
383 | * @see u_fprintf | |
374ca955 | 384 | * @draft 3.0 |
b75a7d8f A |
385 | */ |
386 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
387 | u_vfprintf(UFILE *f, |
388 | const char *patternSpecification, | |
389 | va_list ap); | |
b75a7d8f A |
390 | |
391 | /** | |
392 | * Write formatted data to a UFILE. | |
393 | * @param f The UFILE to which to write. | |
394 | * @param patternSpecification A pattern specifying how <TT>u_fprintf</TT> will | |
395 | * interpret the variable arguments received and format the data. | |
396 | * @return The number of Unicode characters written to <TT>f</TT>. | |
374ca955 | 397 | * @draft 3.0 |
b75a7d8f A |
398 | */ |
399 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
400 | u_fprintf_u(UFILE *f, |
401 | const UChar *patternSpecification, | |
402 | ... ); | |
b75a7d8f A |
403 | |
404 | /** | |
405 | * Write formatted data to a UFILE. | |
406 | * This is identical to <TT>u_fprintf_u</TT>, except that it will | |
374ca955 | 407 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>. |
b75a7d8f A |
408 | * @param f The UFILE to which to write. |
409 | * @param patternSpecification A pattern specifying how <TT>u_fprintf</TT> will | |
410 | * interpret the variable arguments received and format the data. | |
411 | * @param ap The argument list to use. | |
412 | * @return The number of Unicode characters written to <TT>f</TT>. | |
413 | * @see u_fprintf_u | |
374ca955 | 414 | * @draft 3.0 |
b75a7d8f A |
415 | */ |
416 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
417 | u_vfprintf_u(UFILE *f, |
418 | const UChar *patternSpecification, | |
419 | va_list ap); | |
420 | #endif | |
b75a7d8f A |
421 | /** |
422 | * Write a Unicode to a UFILE. The null (U+0000) terminated UChar* | |
423 | * <TT>s</TT> will be written to <TT>f</TT>, excluding the NULL terminator. | |
424 | * A newline will be added to <TT>f</TT>. | |
425 | * @param s The UChar* to write. | |
426 | * @param f The UFILE to which to write. | |
427 | * @return A non-negative number if successful, EOF otherwise. | |
374ca955 A |
428 | * @see u_file_write |
429 | * @draft 3.0 | |
b75a7d8f A |
430 | */ |
431 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
432 | u_fputs(const UChar *s, |
433 | UFILE *f); | |
b75a7d8f A |
434 | |
435 | /** | |
436 | * Write a UChar to a UFILE. | |
437 | * @param uc The UChar to write. | |
438 | * @param f The UFILE to which to write. | |
439 | * @return The character written if successful, EOF otherwise. | |
374ca955 | 440 | * @draft 3.0 |
b75a7d8f | 441 | */ |
374ca955 A |
442 | U_CAPI UChar32 U_EXPORT2 |
443 | u_fputc(UChar32 uc, | |
444 | UFILE *f); | |
b75a7d8f A |
445 | |
446 | /** | |
447 | * Write Unicode to a UFILE. | |
448 | * The ustring passed in will be converted to the UFILE's underlying | |
449 | * codepage before it is written. | |
374ca955 | 450 | * @param ustring A pointer to the Unicode data to write. |
b75a7d8f A |
451 | * @param count The number of Unicode characters to write |
452 | * @param f The UFILE to which to write. | |
453 | * @return The number of Unicode characters written. | |
374ca955 A |
454 | * @see u_fputs |
455 | * @draft 3.0 | |
b75a7d8f A |
456 | */ |
457 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
458 | u_file_write(const UChar *ustring, |
459 | int32_t count, | |
460 | UFILE *f); | |
b75a7d8f A |
461 | |
462 | ||
463 | /* Input functions */ | |
374ca955 | 464 | #if !UCONFIG_NO_FORMATTING |
b75a7d8f A |
465 | |
466 | /** | |
467 | * Read formatted data from a UFILE. | |
468 | * @param f The UFILE from which to read. | |
469 | * @param patternSpecification A pattern specifying how <TT>u_fscanf</TT> will | |
470 | * interpret the variable arguments received and parse the data. | |
471 | * @return The number of items successfully converted and assigned, or EOF | |
472 | * if an error occurred. | |
374ca955 | 473 | * @draft 3.0 |
b75a7d8f A |
474 | */ |
475 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
476 | u_fscanf(UFILE *f, |
477 | const char *patternSpecification, | |
478 | ... ); | |
b75a7d8f A |
479 | |
480 | /** | |
481 | * Read formatted data from a UFILE. | |
482 | * This is identical to <TT>u_fscanf</TT>, except that it will | |
374ca955 | 483 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>. |
b75a7d8f A |
484 | * @param f The UFILE from which to read. |
485 | * @param patternSpecification A pattern specifying how <TT>u_fscanf</TT> will | |
486 | * interpret the variable arguments received and parse the data. | |
487 | * @param ap The argument list to use. | |
488 | * @return The number of items successfully converted and assigned, or EOF | |
489 | * if an error occurred. | |
490 | * @see u_fscanf | |
374ca955 | 491 | * @draft 3.0 |
b75a7d8f A |
492 | */ |
493 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
494 | u_vfscanf(UFILE *f, |
495 | const char *patternSpecification, | |
496 | va_list ap); | |
b75a7d8f A |
497 | |
498 | /** | |
499 | * Read formatted data from a UFILE. | |
500 | * @param f The UFILE from which to read. | |
501 | * @param patternSpecification A pattern specifying how <TT>u_fscanf</TT> will | |
502 | * interpret the variable arguments received and parse the data. | |
503 | * @return The number of items successfully converted and assigned, or EOF | |
504 | * if an error occurred. | |
374ca955 | 505 | * @draft 3.0 |
b75a7d8f A |
506 | */ |
507 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
508 | u_fscanf_u(UFILE *f, |
509 | const UChar *patternSpecification, | |
510 | ... ); | |
b75a7d8f A |
511 | |
512 | /** | |
513 | * Read formatted data from a UFILE. | |
514 | * This is identical to <TT>u_fscanf_u</TT>, except that it will | |
374ca955 | 515 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>. |
b75a7d8f A |
516 | * @param f The UFILE from which to read. |
517 | * @param patternSpecification A pattern specifying how <TT>u_fscanf</TT> will | |
518 | * interpret the variable arguments received and parse the data. | |
519 | * @param ap The argument list to use. | |
520 | * @return The number of items successfully converted and assigned, or EOF | |
521 | * if an error occurred. | |
522 | * @see u_fscanf_u | |
374ca955 | 523 | * @draft 3.0 |
b75a7d8f A |
524 | */ |
525 | U_CAPI int32_t U_EXPORT2 | |
374ca955 A |
526 | u_vfscanf_u(UFILE *f, |
527 | const UChar *patternSpecification, | |
528 | va_list ap); | |
529 | #endif | |
b75a7d8f A |
530 | |
531 | /** | |
532 | * Read one line of text into a UChar* string from a UFILE. The newline | |
533 | * at the end of the line is read into the string. The string is always | |
534 | * null terminated | |
535 | * @param f The UFILE from which to read. | |
536 | * @param n The maximum number of characters - 1 to read. | |
537 | * @param s The UChar* to receive the read data. Characters will be | |
538 | * stored successively in <TT>s</TT> until a newline or EOF is | |
539 | * reached. A null character (U+0000) will be appended to <TT>s</TT>. | |
540 | * @return A pointer to <TT>s</TT>, or NULL if no characters were available. | |
374ca955 | 541 | * @draft 3.0 |
b75a7d8f A |
542 | */ |
543 | U_CAPI UChar* U_EXPORT2 | |
374ca955 A |
544 | u_fgets(UChar *s, |
545 | int32_t n, | |
546 | UFILE *f); | |
b75a7d8f A |
547 | |
548 | /** | |
374ca955 A |
549 | * Read a UChar from a UFILE. It is recommended that <TT>u_fgetcx</TT> |
550 | * used instead for proper parsing functions, but sometimes reading | |
551 | * code units is needed instead of codepoints. | |
552 | * | |
b75a7d8f A |
553 | * @param f The UFILE from which to read. |
554 | * @return The UChar value read, or U+FFFF if no character was available. | |
374ca955 | 555 | * @draft 3.0 |
b75a7d8f A |
556 | */ |
557 | U_CAPI UChar U_EXPORT2 | |
374ca955 | 558 | u_fgetc(UFILE *f); |
b75a7d8f A |
559 | |
560 | /** | |
374ca955 A |
561 | * Read a UChar32 from a UFILE. |
562 | * | |
b75a7d8f | 563 | * @param f The UFILE from which to read. |
374ca955 A |
564 | * @return The UChar32 value read, or U_EOF if no character was |
565 | * available, or U+FFFFFFFF if an ill-formed character was | |
b75a7d8f A |
566 | * encountered. |
567 | * @see u_unescape() | |
374ca955 | 568 | * @draft 3.0 |
b75a7d8f A |
569 | */ |
570 | U_CAPI UChar32 U_EXPORT2 | |
374ca955 | 571 | u_fgetcx(UFILE *f); |
b75a7d8f A |
572 | |
573 | /** | |
574 | * Unget a UChar from a UFILE. | |
575 | * If this function is not the first to operate on <TT>f</TT> after a call | |
576 | * to <TT>u_fgetc</TT>, the results are undefined. | |
374ca955 A |
577 | * If this function is passed a character that was not recieved from the |
578 | * previous <TT>u_fgetc</TT> or <TT>u_fgetcx</TT> call, the results are undefined. | |
b75a7d8f A |
579 | * @param c The UChar to put back on the stream. |
580 | * @param f The UFILE to receive <TT>c</TT>. | |
374ca955 A |
581 | * @return The UChar32 value put back if successful, U_EOF otherwise. |
582 | * @draft 3.0 | |
b75a7d8f | 583 | */ |
374ca955 A |
584 | U_CAPI UChar32 U_EXPORT2 |
585 | u_fungetc(UChar32 c, | |
b75a7d8f A |
586 | UFILE *f); |
587 | ||
588 | /** | |
589 | * Read Unicode from a UFILE. | |
590 | * Bytes will be converted from the UFILE's underlying codepage, with | |
374ca955 | 591 | * subsequent conversion to Unicode. The data will not be NULL terminated. |
b75a7d8f A |
592 | * @param chars A pointer to receive the Unicode data. |
593 | * @param count The number of Unicode characters to read. | |
594 | * @param f The UFILE from which to read. | |
595 | * @return The number of Unicode characters read. | |
374ca955 | 596 | * @draft 3.0 |
b75a7d8f A |
597 | */ |
598 | U_CAPI int32_t U_EXPORT2 | |
599 | u_file_read(UChar *chars, | |
600 | int32_t count, | |
601 | UFILE *f); | |
602 | ||
603 | #if !UCONFIG_NO_TRANSLITERATION | |
604 | ||
605 | /** | |
606 | * Set a transliterator on the UFILE. The transliterator will be owned by the | |
607 | * UFILE. | |
608 | * @param file The UFILE to set transliteration on | |
609 | * @param adopt The UTransliterator to set. Can be NULL, which will | |
610 | * mean that no transliteration is used. | |
611 | * @param direction either U_READ, U_WRITE, or U_READWRITE - sets | |
612 | * which direction the transliterator is to be applied to. If | |
613 | * U_READWRITE, the "Read" transliteration will be in the inverse | |
614 | * direction. | |
615 | * @param status ICU error code. | |
616 | * @return The previously set transliterator, owned by the | |
617 | * caller. If U_READWRITE is specified, only the WRITE transliterator | |
618 | * is returned. In most cases, the caller should call utrans_close() | |
619 | * on the result of this function. | |
374ca955 | 620 | * @draft 3.0 |
b75a7d8f A |
621 | */ |
622 | U_CAPI UTransliterator* U_EXPORT2 | |
623 | u_fsettransliterator(UFILE *file, UFileDirection direction, | |
624 | UTransliterator *adopt, UErrorCode *status); | |
625 | ||
626 | #endif | |
627 | ||
628 | ||
629 | /* Output string functions */ | |
374ca955 | 630 | #if !UCONFIG_NO_FORMATTING |
b75a7d8f A |
631 | |
632 | ||
633 | /** | |
634 | * Write formatted data to a Unicode string. | |
635 | * | |
636 | * @param buffer The Unicode String to which to write. | |
b75a7d8f A |
637 | * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will |
638 | * interpret the variable arguments received and format the data. | |
639 | * @return The number of Unicode code units written to <TT>buffer</TT>. This | |
640 | * does not include the terminating null character. | |
374ca955 | 641 | * @draft 3.0 |
b75a7d8f A |
642 | */ |
643 | U_CAPI int32_t U_EXPORT2 | |
644 | u_sprintf(UChar *buffer, | |
b75a7d8f A |
645 | const char *patternSpecification, |
646 | ... ); | |
647 | ||
648 | /** | |
649 | * Write formatted data to a Unicode string. When the number of code units | |
650 | * required to store the data exceeds <TT>count</TT>, then <TT>count</TT> code | |
651 | * units of data are stored in <TT>buffer</TT> and a negative value is | |
652 | * returned. When the number of code units required to store the data equals | |
653 | * <TT>count</TT>, the string is not null terminated and <TT>count</TT> is | |
654 | * returned. | |
655 | * | |
656 | * @param buffer The Unicode String to which to write. | |
657 | * @param count The number of code units to read. | |
b75a7d8f A |
658 | * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will |
659 | * interpret the variable arguments received and format the data. | |
660 | * @return The number of Unicode code units written to <TT>buffer</TT>. This | |
661 | * does not include the terminating null character. | |
374ca955 | 662 | * @draft 3.0 |
b75a7d8f A |
663 | */ |
664 | U_CAPI int32_t U_EXPORT2 | |
665 | u_snprintf(UChar *buffer, | |
666 | int32_t count, | |
b75a7d8f A |
667 | const char *patternSpecification, |
668 | ... ); | |
669 | ||
670 | /** | |
671 | * Write formatted data to a Unicode string. | |
672 | * This is identical to <TT>u_sprintf</TT>, except that it will | |
374ca955 | 673 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>. |
b75a7d8f A |
674 | * |
675 | * @param buffer The Unicode string to which to write. | |
b75a7d8f A |
676 | * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will |
677 | * interpret the variable arguments received and format the data. | |
678 | * @param ap The argument list to use. | |
679 | * @return The number of Unicode characters written to <TT>buffer</TT>. | |
680 | * @see u_sprintf | |
374ca955 | 681 | * @draft 3.0 |
b75a7d8f A |
682 | */ |
683 | U_CAPI int32_t U_EXPORT2 | |
684 | u_vsprintf(UChar *buffer, | |
b75a7d8f A |
685 | const char *patternSpecification, |
686 | va_list ap); | |
687 | ||
688 | /** | |
689 | * Write formatted data to a Unicode string. | |
690 | * This is identical to <TT>u_snprintf</TT>, except that it will | |
374ca955 | 691 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.<br><br> |
b75a7d8f A |
692 | * When the number of code units required to store the data exceeds |
693 | * <TT>count</TT>, then <TT>count</TT> code units of data are stored in | |
694 | * <TT>buffer</TT> and a negative value is returned. When the number of code | |
695 | * units required to store the data equals <TT>count</TT>, the string is not | |
696 | * null terminated and <TT>count</TT> is returned. | |
697 | * | |
698 | * @param buffer The Unicode string to which to write. | |
699 | * @param count The number of code units to read. | |
b75a7d8f A |
700 | * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will |
701 | * interpret the variable arguments received and format the data. | |
702 | * @param ap The argument list to use. | |
703 | * @return The number of Unicode characters written to <TT>buffer</TT>. | |
704 | * @see u_sprintf | |
374ca955 | 705 | * @draft 3.0 |
b75a7d8f A |
706 | */ |
707 | U_CAPI int32_t U_EXPORT2 | |
708 | u_vsnprintf(UChar *buffer, | |
709 | int32_t count, | |
b75a7d8f A |
710 | const char *patternSpecification, |
711 | va_list ap); | |
712 | ||
713 | /** | |
714 | * Write formatted data to a Unicode string. | |
715 | * | |
716 | * @param buffer The Unicode string to which to write. | |
b75a7d8f A |
717 | * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will |
718 | * interpret the variable arguments received and format the data. | |
719 | * @return The number of Unicode characters written to <TT>buffer</TT>. | |
374ca955 | 720 | * @draft 3.0 |
b75a7d8f A |
721 | */ |
722 | U_CAPI int32_t U_EXPORT2 | |
723 | u_sprintf_u(UChar *buffer, | |
b75a7d8f A |
724 | const UChar *patternSpecification, |
725 | ... ); | |
726 | ||
727 | /** | |
728 | * Write formatted data to a Unicode string. When the number of code units | |
729 | * required to store the data exceeds <TT>count</TT>, then <TT>count</TT> code | |
730 | * units of data are stored in <TT>buffer</TT> and a negative value is | |
731 | * returned. When the number of code units required to store the data equals | |
732 | * <TT>count</TT>, the string is not null terminated and <TT>count</TT> is | |
733 | * returned. | |
734 | * | |
735 | * @param buffer The Unicode string to which to write. | |
736 | * @param count The number of code units to read. | |
b75a7d8f A |
737 | * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will |
738 | * interpret the variable arguments received and format the data. | |
739 | * @return The number of Unicode characters written to <TT>buffer</TT>. | |
374ca955 | 740 | * @draft 3.0 |
b75a7d8f A |
741 | */ |
742 | U_CAPI int32_t U_EXPORT2 | |
743 | u_snprintf_u(UChar *buffer, | |
744 | int32_t count, | |
b75a7d8f A |
745 | const UChar *patternSpecification, |
746 | ... ); | |
747 | ||
748 | /** | |
749 | * Write formatted data to a Unicode string. | |
750 | * This is identical to <TT>u_sprintf_u</TT>, except that it will | |
374ca955 | 751 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>. |
b75a7d8f A |
752 | * |
753 | * @param buffer The Unicode string to which to write. | |
b75a7d8f A |
754 | * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will |
755 | * interpret the variable arguments received and format the data. | |
756 | * @param ap The argument list to use. | |
757 | * @return The number of Unicode characters written to <TT>f</TT>. | |
758 | * @see u_sprintf_u | |
374ca955 | 759 | * @draft 3.0 |
b75a7d8f A |
760 | */ |
761 | U_CAPI int32_t U_EXPORT2 | |
762 | u_vsprintf_u(UChar *buffer, | |
b75a7d8f A |
763 | const UChar *patternSpecification, |
764 | va_list ap); | |
765 | ||
766 | /** | |
767 | * Write formatted data to a Unicode string. | |
768 | * This is identical to <TT>u_snprintf_u</TT>, except that it will | |
374ca955 | 769 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>. |
b75a7d8f A |
770 | * When the number of code units required to store the data exceeds |
771 | * <TT>count</TT>, then <TT>count</TT> code units of data are stored in | |
772 | * <TT>buffer</TT> and a negative value is returned. When the number of code | |
773 | * units required to store the data equals <TT>count</TT>, the string is not | |
774 | * null terminated and <TT>count</TT> is returned. | |
775 | * | |
776 | * @param buffer The Unicode string to which to write. | |
374ca955 | 777 | * @param count The number of code units to read. |
b75a7d8f A |
778 | * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will |
779 | * interpret the variable arguments received and format the data. | |
780 | * @param ap The argument list to use. | |
781 | * @return The number of Unicode characters written to <TT>f</TT>. | |
782 | * @see u_sprintf_u | |
374ca955 | 783 | * @draft 3.0 |
b75a7d8f A |
784 | */ |
785 | U_CAPI int32_t U_EXPORT2 | |
786 | u_vsnprintf_u(UChar *buffer, | |
787 | int32_t count, | |
b75a7d8f A |
788 | const UChar *patternSpecification, |
789 | va_list ap); | |
790 | ||
791 | /* Input string functions */ | |
792 | ||
793 | /** | |
794 | * Read formatted data from a Unicode string. | |
795 | * | |
796 | * @param buffer The Unicode string from which to read. | |
b75a7d8f A |
797 | * @param patternSpecification A pattern specifying how <TT>u_sscanf</TT> will |
798 | * interpret the variable arguments received and parse the data. | |
799 | * @return The number of items successfully converted and assigned, or EOF | |
800 | * if an error occurred. | |
374ca955 | 801 | * @draft 3.0 |
b75a7d8f A |
802 | */ |
803 | U_CAPI int32_t U_EXPORT2 | |
804 | u_sscanf(const UChar *buffer, | |
b75a7d8f A |
805 | const char *patternSpecification, |
806 | ... ); | |
807 | ||
808 | /** | |
809 | * Read formatted data from a Unicode string. | |
810 | * This is identical to <TT>u_sscanf</TT>, except that it will | |
374ca955 | 811 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>. |
b75a7d8f A |
812 | * |
813 | * @param buffer The Unicode string from which to read. | |
b75a7d8f A |
814 | * @param patternSpecification A pattern specifying how <TT>u_sscanf</TT> will |
815 | * interpret the variable arguments received and parse the data. | |
816 | * @param ap The argument list to use. | |
817 | * @return The number of items successfully converted and assigned, or EOF | |
818 | * if an error occurred. | |
819 | * @see u_sscanf | |
374ca955 | 820 | * @draft 3.0 |
b75a7d8f A |
821 | */ |
822 | U_CAPI int32_t U_EXPORT2 | |
823 | u_vsscanf(const UChar *buffer, | |
b75a7d8f A |
824 | const char *patternSpecification, |
825 | va_list ap); | |
826 | ||
827 | /** | |
828 | * Read formatted data from a Unicode string. | |
829 | * | |
830 | * @param buffer The Unicode string from which to read. | |
b75a7d8f A |
831 | * @param patternSpecification A pattern specifying how <TT>u_sscanf</TT> will |
832 | * interpret the variable arguments received and parse the data. | |
833 | * @return The number of items successfully converted and assigned, or EOF | |
834 | * if an error occurred. | |
374ca955 | 835 | * @draft 3.0 |
b75a7d8f A |
836 | */ |
837 | U_CAPI int32_t U_EXPORT2 | |
838 | u_sscanf_u(const UChar *buffer, | |
b75a7d8f A |
839 | const UChar *patternSpecification, |
840 | ... ); | |
841 | ||
842 | /** | |
843 | * Read formatted data from a Unicode string. | |
844 | * This is identical to <TT>u_sscanf_u</TT>, except that it will | |
374ca955 | 845 | * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>. |
b75a7d8f | 846 | * |
374ca955 | 847 | * @param buffer The Unicode string from which to read. |
b75a7d8f A |
848 | * @param patternSpecification A pattern specifying how <TT>u_sscanf</TT> will |
849 | * interpret the variable arguments received and parse the data. | |
850 | * @param ap The argument list to use. | |
851 | * @return The number of items successfully converted and assigned, or EOF | |
852 | * if an error occurred. | |
853 | * @see u_sscanf_u | |
374ca955 | 854 | * @draft 3.0 |
b75a7d8f A |
855 | */ |
856 | U_CAPI int32_t U_EXPORT2 | |
857 | u_vsscanf_u(const UChar *buffer, | |
b75a7d8f A |
858 | const UChar *patternSpecification, |
859 | va_list ap); | |
860 | ||
b75a7d8f | 861 | #endif |
374ca955 | 862 | #endif |
b75a7d8f A |
863 | |
864 |