]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/io/unicode/ustdio.h
ICU-6.2.22.tar.gz
[apple/icu.git] / icuSources / io / unicode / ustdio.h
... / ...
CommitLineData
1/*
2******************************************************************************
3*
4* Copyright (C) 1998-2004, International Business Machines
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
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.
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.
43 * Test stdin and stdout with the u_f* functions
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
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.
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
68 order to prevent buffer overruns. (e.g. %256.256d).
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.
73 * The width parameter for all scanf formats, including scanset, needs
74 better testing. This prevents buffer overflows.
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
85*/
86
87/**
88 * \file
89 * \brief C API: Unicode stdio-like API
90 *
91 * <h2>Unicode stdio-like C API</h2>
92General printf format:<br>
93%[format modifier][width][.precision][type modifier][format]
94
95General 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>
115When width is specified, this acts like a non-NULL-terminated char * string.<br>
116By 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>
119When width is specified, this acts like a non-NULL-terminated UChar * string<br>
120By 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
125Format 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
153printf modifier
154%* int32_t Next argument after this one specifies the width
155
156scanf modifier
157%* N/A This field is scanned, but not stored
158
159 */
160
161
162/**
163 * When an end of file is encountered, this value can be returned.
164 * @see u_fgetc
165 * @draft 3.0
166 */
167#define U_EOF 0xFFFF
168
169/** Forward declaration of a Unicode-aware file @draft 3.0 */
170typedef struct UFILE UFILE;
171
172/**
173 * Enum for which direction of stream a transliterator applies to.
174 * @see u_fsettransliterator
175 * @draft 3.0
176 */
177typedef 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
195 * read from the file. If this paramter is NULL the system default codepage
196 * will be used.
197 * @return A new UFILE, or NULL if an error occurred.
198 * @draft 3.0
199 */
200U_CAPI UFILE* U_EXPORT2
201u_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.
217 * @draft 3.0
218 */
219U_CAPI UFILE* U_EXPORT2
220u_finit(FILE *f,
221 const char *locale,
222 const char *codepage);
223
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 */
238U_CAPI UFILE* U_EXPORT2
239u_fstropen(UChar *stringBuf,
240 int32_t capacity,
241 const char *locale);
242
243/**
244 * Close a UFILE.
245 * @param file The UFILE to close.
246 * @draft 3.0
247 */
248U_CAPI void U_EXPORT2
249u_fclose(UFILE *file);
250
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*/
259U_CAPI UBool U_EXPORT2
260u_feof(UFILE *f);
261
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.
268 * @draft 3.0
269 */
270U_CAPI void U_EXPORT2
271u_fflush(UFILE *file);
272
273/**
274 * Rewind the file pointer to the beginning of the file.
275 * @param file The UFILE to rewind.
276 * @draft 3.0
277 */
278U_CAPI void
279u_frewind(UFILE *file);
280
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.
285 * @draft 3.0
286 */
287U_CAPI FILE* U_EXPORT2
288u_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.
298 * @draft 3.0
299 */
300U_CAPI const char* U_EXPORT2
301u_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.
309 * @draft 3.0
310 */
311U_CAPI int32_t U_EXPORT2
312u_fsetlocale(UFILE *file,
313 const char *locale);
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.
324 * @draft 3.0
325 */
326U_CAPI const char* U_EXPORT2
327u_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
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>.
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.
340 * @return 0 if successful, otherwise a negative number.
341 * @see u_frewind
342 * @draft 3.0
343 */
344U_CAPI int32_t U_EXPORT2
345u_fsetcodepage(const char *codepage,
346 UFILE *file);
347
348
349/**
350 * Returns an alias to the converter being used for this file.
351 * @param f The UFILE to get the value from
352 * @return alias to the converter
353 * @draft 3.0
354 */
355U_CAPI UConverter* U_EXPORT2 u_fgetConverter(UFILE *f);
356
357#if !UCONFIG_NO_FORMATTING
358
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>.
367 * @draft 3.0
368 */
369U_CAPI int32_t U_EXPORT2
370u_fprintf(UFILE *f,
371 const char *patternSpecification,
372 ... );
373
374/**
375 * Write formatted data to a UFILE.
376 * This is identical to <TT>u_fprintf</TT>, except that it will
377 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
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
384 * @draft 3.0
385 */
386U_CAPI int32_t U_EXPORT2
387u_vfprintf(UFILE *f,
388 const char *patternSpecification,
389 va_list ap);
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>.
397 * @draft 3.0
398 */
399U_CAPI int32_t U_EXPORT2
400u_fprintf_u(UFILE *f,
401 const UChar *patternSpecification,
402 ... );
403
404/**
405 * Write formatted data to a UFILE.
406 * This is identical to <TT>u_fprintf_u</TT>, except that it will
407 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
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
414 * @draft 3.0
415 */
416U_CAPI int32_t U_EXPORT2
417u_vfprintf_u(UFILE *f,
418 const UChar *patternSpecification,
419 va_list ap);
420#endif
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.
428 * @see u_file_write
429 * @draft 3.0
430 */
431U_CAPI int32_t U_EXPORT2
432u_fputs(const UChar *s,
433 UFILE *f);
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.
440 * @draft 3.0
441 */
442U_CAPI UChar32 U_EXPORT2
443u_fputc(UChar32 uc,
444 UFILE *f);
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.
450 * @param ustring A pointer to the Unicode data to write.
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.
454 * @see u_fputs
455 * @draft 3.0
456 */
457U_CAPI int32_t U_EXPORT2
458u_file_write(const UChar *ustring,
459 int32_t count,
460 UFILE *f);
461
462
463/* Input functions */
464#if !UCONFIG_NO_FORMATTING
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.
473 * @draft 3.0
474 */
475U_CAPI int32_t U_EXPORT2
476u_fscanf(UFILE *f,
477 const char *patternSpecification,
478 ... );
479
480/**
481 * Read formatted data from a UFILE.
482 * This is identical to <TT>u_fscanf</TT>, except that it will
483 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
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
491 * @draft 3.0
492 */
493U_CAPI int32_t U_EXPORT2
494u_vfscanf(UFILE *f,
495 const char *patternSpecification,
496 va_list ap);
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.
505 * @draft 3.0
506 */
507U_CAPI int32_t U_EXPORT2
508u_fscanf_u(UFILE *f,
509 const UChar *patternSpecification,
510 ... );
511
512/**
513 * Read formatted data from a UFILE.
514 * This is identical to <TT>u_fscanf_u</TT>, except that it will
515 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
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
523 * @draft 3.0
524 */
525U_CAPI int32_t U_EXPORT2
526u_vfscanf_u(UFILE *f,
527 const UChar *patternSpecification,
528 va_list ap);
529#endif
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.
541 * @draft 3.0
542 */
543U_CAPI UChar* U_EXPORT2
544u_fgets(UChar *s,
545 int32_t n,
546 UFILE *f);
547
548/**
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 *
553 * @param f The UFILE from which to read.
554 * @return The UChar value read, or U+FFFF if no character was available.
555 * @draft 3.0
556 */
557U_CAPI UChar U_EXPORT2
558u_fgetc(UFILE *f);
559
560/**
561 * Read a UChar32 from a UFILE.
562 *
563 * @param f The UFILE from which to read.
564 * @return The UChar32 value read, or U_EOF if no character was
565 * available, or U+FFFFFFFF if an ill-formed character was
566 * encountered.
567 * @see u_unescape()
568 * @draft 3.0
569 */
570U_CAPI UChar32 U_EXPORT2
571u_fgetcx(UFILE *f);
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.
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.
579 * @param c The UChar to put back on the stream.
580 * @param f The UFILE to receive <TT>c</TT>.
581 * @return The UChar32 value put back if successful, U_EOF otherwise.
582 * @draft 3.0
583 */
584U_CAPI UChar32 U_EXPORT2
585u_fungetc(UChar32 c,
586 UFILE *f);
587
588/**
589 * Read Unicode from a UFILE.
590 * Bytes will be converted from the UFILE's underlying codepage, with
591 * subsequent conversion to Unicode. The data will not be NULL terminated.
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.
596 * @draft 3.0
597 */
598U_CAPI int32_t U_EXPORT2
599u_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.
620 * @draft 3.0
621 */
622U_CAPI UTransliterator* U_EXPORT2
623u_fsettransliterator(UFILE *file, UFileDirection direction,
624 UTransliterator *adopt, UErrorCode *status);
625
626#endif
627
628
629/* Output string functions */
630#if !UCONFIG_NO_FORMATTING
631
632
633/**
634 * Write formatted data to a Unicode string.
635 *
636 * @param buffer The Unicode String to which to write.
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.
641 * @draft 3.0
642 */
643U_CAPI int32_t U_EXPORT2
644u_sprintf(UChar *buffer,
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.
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.
662 * @draft 3.0
663 */
664U_CAPI int32_t U_EXPORT2
665u_snprintf(UChar *buffer,
666 int32_t count,
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
673 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
674 *
675 * @param buffer The Unicode string to which to write.
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
681 * @draft 3.0
682 */
683U_CAPI int32_t U_EXPORT2
684u_vsprintf(UChar *buffer,
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
691 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.<br><br>
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.
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
705 * @draft 3.0
706 */
707U_CAPI int32_t U_EXPORT2
708u_vsnprintf(UChar *buffer,
709 int32_t count,
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.
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>.
720 * @draft 3.0
721 */
722U_CAPI int32_t U_EXPORT2
723u_sprintf_u(UChar *buffer,
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.
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>.
740 * @draft 3.0
741 */
742U_CAPI int32_t U_EXPORT2
743u_snprintf_u(UChar *buffer,
744 int32_t count,
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
751 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
752 *
753 * @param buffer The Unicode string to which to write.
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
759 * @draft 3.0
760 */
761U_CAPI int32_t U_EXPORT2
762u_vsprintf_u(UChar *buffer,
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
769 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
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.
777 * @param count The number of code units to read.
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
783 * @draft 3.0
784 */
785U_CAPI int32_t U_EXPORT2
786u_vsnprintf_u(UChar *buffer,
787 int32_t count,
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.
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.
801 * @draft 3.0
802 */
803U_CAPI int32_t U_EXPORT2
804u_sscanf(const UChar *buffer,
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
811 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
812 *
813 * @param buffer The Unicode string from which to read.
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
820 * @draft 3.0
821 */
822U_CAPI int32_t U_EXPORT2
823u_vsscanf(const UChar *buffer,
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.
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.
835 * @draft 3.0
836 */
837U_CAPI int32_t U_EXPORT2
838u_sscanf_u(const UChar *buffer,
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
845 * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
846 *
847 * @param buffer The Unicode string from which to read.
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
854 * @draft 3.0
855 */
856U_CAPI int32_t U_EXPORT2
857u_vsscanf_u(const UChar *buffer,
858 const UChar *patternSpecification,
859 va_list ap);
860
861#endif
862#endif
863
864