michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1998-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * michael@0: * File ustdio.h michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 10/16/98 stephen Creation. michael@0: * 11/06/98 stephen Modified per code review. michael@0: * 03/12/99 stephen Modified for new C API. michael@0: * 07/19/99 stephen Minor doc update. michael@0: * 02/01/01 george Added sprintf & sscanf with all of its variants michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #ifndef USTDIO_H michael@0: #define USTDIO_H michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/ucnv.h" michael@0: #include "unicode/utrans.h" michael@0: #include "unicode/localpointer.h" michael@0: #include "unicode/unum.h" michael@0: michael@0: /* michael@0: TODO michael@0: The following is a small list as to what is currently wrong/suggestions for michael@0: ustdio. michael@0: michael@0: * Make sure that * in the scanf format specification works for all formats. michael@0: * Each UFILE takes up at least 2KB. michael@0: Look into adding setvbuf() for configurable buffers. michael@0: * This library does buffering. The OS should do this for us already. Check on michael@0: this, and remove it from this library, if this is the case. Double buffering michael@0: wastes a lot of time and space. michael@0: * Test stdin and stdout with the u_f* functions michael@0: * Testing should be done for reading and writing multi-byte encodings, michael@0: and make sure that a character that is contained across buffer boundries michael@0: works even for incomplete characters. michael@0: * Make sure that the last character is flushed when the file/string is closed. michael@0: * snprintf should follow the C99 standard for the return value, which is michael@0: return the number of characters (excluding the trailing '\0') michael@0: which would have been written to the destination string regardless michael@0: of available space. This is like pre-flighting. michael@0: * Everything that uses %s should do what operator>> does for UnicodeString. michael@0: It should convert one byte at a time, and once a character is michael@0: converted then check to see if it's whitespace or in the scanset. michael@0: If it's whitespace or in the scanset, put all the bytes back (do nothing michael@0: for sprintf/sscanf). michael@0: * If bad string data is encountered, make sure that the function fails michael@0: without memory leaks and the unconvertable characters are valid michael@0: substitution or are escaped characters. michael@0: * u_fungetc() can't unget a character when it's at the beginning of the michael@0: internal conversion buffer. For example, read the buffer size # of michael@0: characters, and then ungetc to get the previous character that was michael@0: at the end of the last buffer. michael@0: * u_fflush() and u_fclose should return an int32_t like C99 functions. michael@0: 0 is returned if the operation was successful and EOF otherwise. michael@0: * u_fsettransliterator does not support U_READ side of transliteration. michael@0: * The format specifier should limit the size of a format or honor it in michael@0: order to prevent buffer overruns. (e.g. %256.256d). michael@0: * u_fread and u_fwrite don't exist. They're needed for reading and writing michael@0: data structures without any conversion. michael@0: * u_file_read and u_file_write are used for writing strings. u_fgets and michael@0: u_fputs or u_fread and u_fwrite should be used to do this. michael@0: * The width parameter for all scanf formats, including scanset, needs michael@0: better testing. This prevents buffer overflows. michael@0: * Figure out what is suppose to happen when a codepage is changed midstream. michael@0: Maybe a flush or a rewind are good enough. michael@0: * Make sure that a UFile opened with "rw" can be used after using michael@0: u_fflush with a u_frewind. michael@0: * scanf(%i) should detect what type of number to use. michael@0: * Add more testing of the alternate format, %# michael@0: * Look at newline handling of fputs/puts michael@0: * Think more about codeunit/codepoint error handling/support in %S,%s,%C,%c,%[] michael@0: * Complete the file documentation with proper doxygen formatting. michael@0: See http://oss.software.ibm.com/pipermail/icu/2003-July/005647.html michael@0: */ michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Unicode stdio-like API michael@0: * michael@0: *

Unicode stdio-like C API

michael@0: * michael@0: *

This API provides an stdio-like API wrapper around ICU's other michael@0: * formatting and parsing APIs. It is meant to ease the transition of adding michael@0: * Unicode support to a preexisting applications using stdio. The following michael@0: * is a small list of noticable differences between stdio and ICU I/O's michael@0: * ustdio implementation.

michael@0: * michael@0: * michael@0: * michael@0: *

Formatting and Parsing Specification

michael@0: * michael@0: * General printf format:
michael@0: * %[format modifier][width][.precision][type modifier][format] michael@0: * michael@0: * General scanf format:
michael@0: * %[*][format modifier][width][type modifier][format] michael@0: * michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0:
formatdefault
printf
type
default
scanf
type
description
%EdoublefloatScientific with an uppercase exponent
%edoublefloatScientific with a lowercase exponent
%GdoublefloatUse %E or %f for best format
%gdoublefloatUse %e or %f for best format
%fdoublefloatSimple floating point without the exponent
%Xint32_tint32_tustdio special uppercase hex radix formatting
%xint32_tint32_tustdio special lowercase hex radix formatting
%dint32_tint32_tDecimal format
%iint32_tint32_tSame as %d
%nint32_tint32_tcount (write the number of UTF-16 codeunits read/written)
%oint32_tint32_tustdio special octal radix formatting
%uuint32_tuint32_tDecimal format
%pvoid *void *Prints the pointer value
%schar *char *Use default converter or specified converter from fopen
%ccharcharUse default converter or specified converter from fopen
michael@0: When width is specified for scanf, this acts like a non-NULL-terminated char * string.
michael@0: By default, only one char is written.
%SUChar *UChar *Null terminated UTF-16 string
%CUCharUChar16-bit Unicode code unit
michael@0: When width is specified for scanf, this acts like a non-NULL-terminated UChar * string
michael@0: By default, only one codepoint is written.
%[] UChar *Null terminated UTF-16 string which contains the filtered set of characters specified by the UnicodeSet
%%  Show a percent sign
michael@0: michael@0: Format modifiers michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0:
modifierformatstypecomments
%h%d, %i, %o, %xint16_tshort format
%h%uuint16_tshort format
%hcchar(Unimplemented) Use invariant converter
%hschar *(Unimplemented) Use invariant converter
%hCchar(Unimplemented) 8-bit Unicode code unit
%hSchar *(Unimplemented) Null terminated UTF-8 string
%l%d, %i, %o, %xint32_tlong format (no effect)
%l%uuint32_tlong format (no effect)
%lcN/A(Unimplemented) Reserved for future implementation
%lsN/A(Unimplemented) Reserved for future implementation
%lCUChar32(Unimplemented) 32-bit Unicode code unit
%lSUChar32 *(Unimplemented) Null terminated UTF-32 string
%ll%d, %i, %o, %xint64_tlong long format
%ll%uuint64_t(Unimplemented) long long format
%-allN/ALeft justify
%+%d, %i, %o, %x, %e, %f, %g, %E, %GN/AAlways show the plus or minus sign. Needs data for plus sign.
% %d, %i, %o, %x, %e, %f, %g, %E, %GN/AInstead of a "+" output a blank character for positive numbers.
%#%d, %i, %o, %x, %e, %f, %g, %E, %GN/APrecede octal value with 0, hex with 0x and show the michael@0: decimal point for floats.
%nallN/AWidth of input/output. num is an actual number from 0 to michael@0: some large number.
%.n%e, %f, %g, %E, %F, %GN/ASignificant digits precision. num is an actual number from michael@0: 0 to some large number.
If * is used in printf, then the precision is passed in as an argument before the number to be formatted.
michael@0: michael@0: printf modifier michael@0: %* int32_t Next argument after this one specifies the width michael@0: michael@0: scanf modifier michael@0: %* N/A This field is scanned, but not stored michael@0: michael@0:

If you are using this C API instead of the ustream.h API for C++, michael@0: you can use one of the following u_fprintf examples to display a UnicodeString.

michael@0: michael@0:

michael@0:     UFILE *out = u_finit(stdout, NULL, NULL);
michael@0:     UnicodeString string1("string 1");
michael@0:     UnicodeString string2("string 2");
michael@0:     u_fprintf(out, "%S\n", string1.getTerminatedBuffer());
michael@0:     u_fprintf(out, "%.*S\n", string2.length(), string2.getBuffer());
michael@0:     u_fclose(out);
michael@0: 
michael@0: michael@0: */ michael@0: michael@0: michael@0: /** michael@0: * When an end of file is encountered, this value can be returned. michael@0: * @see u_fgetc michael@0: * @stable 3.0 michael@0: */ michael@0: #define U_EOF 0xFFFF michael@0: michael@0: /** Forward declaration of a Unicode-aware file @stable 3.0 */ michael@0: typedef struct UFILE UFILE; michael@0: michael@0: /** michael@0: * Enum for which direction of stream a transliterator applies to. michael@0: * @see u_fsettransliterator michael@0: * @stable ICU 3.0 michael@0: */ michael@0: typedef enum { michael@0: U_READ = 1, michael@0: U_WRITE = 2, michael@0: U_READWRITE =3 /* == (U_READ | U_WRITE) */ michael@0: } UFileDirection; michael@0: michael@0: /** michael@0: * Open a UFILE. michael@0: * A UFILE is a wrapper around a FILE* that is locale and codepage aware. michael@0: * That is, data written to a UFILE will be formatted using the conventions michael@0: * specified by that UFILE's Locale; this data will be in the character set michael@0: * specified by that UFILE's codepage. michael@0: * @param filename The name of the file to open. michael@0: * @param perm The read/write permission for the UFILE; one of "r", "w", "rw" michael@0: * @param locale The locale whose conventions will be used to format michael@0: * and parse output. If this parameter is NULL, the default locale will michael@0: * be used. michael@0: * @param codepage The codepage in which data will be written to and michael@0: * read from the file. If this paramter is NULL the system default codepage michael@0: * will be used. michael@0: * @return A new UFILE, or NULL if an error occurred. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UFILE* U_EXPORT2 michael@0: u_fopen(const char *filename, michael@0: const char *perm, michael@0: const char *locale, michael@0: const char *codepage); michael@0: michael@0: /** michael@0: * Open a UFILE on top of an existing FILE* stream. The FILE* stream michael@0: * ownership remains with the caller. To have the UFILE take over michael@0: * ownership and responsibility for the FILE* stream, use the michael@0: * function u_fadopt. michael@0: * @param f The FILE* to which this UFILE will attach and use. michael@0: * @param locale The locale whose conventions will be used to format michael@0: * and parse output. If this parameter is NULL, the default locale will michael@0: * be used. michael@0: * @param codepage The codepage in which data will be written to and michael@0: * read from the file. If this paramter is NULL, data will be written and michael@0: * read using the default codepage for locale, unless locale michael@0: * is NULL, in which case the system default codepage will be used. michael@0: * @return A new UFILE, or NULL if an error occurred. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UFILE* U_EXPORT2 michael@0: u_finit(FILE *f, michael@0: const char *locale, michael@0: const char *codepage); michael@0: michael@0: /** michael@0: * Open a UFILE on top of an existing FILE* stream. The FILE* stream michael@0: * ownership is transferred to the new UFILE. It will be closed when the michael@0: * UFILE is closed. michael@0: * @param f The FILE* which this UFILE will take ownership of. michael@0: * @param locale The locale whose conventions will be used to format michael@0: * and parse output. If this parameter is NULL, the default locale will michael@0: * be used. michael@0: * @param codepage The codepage in which data will be written to and michael@0: * read from the file. If this paramter is NULL, data will be written and michael@0: * read using the default codepage for locale, unless locale michael@0: * is NULL, in which case the system default codepage will be used. michael@0: * @return A new UFILE, or NULL if an error occurred. If an error occurs michael@0: * the ownership of the FILE* stream remains with the caller. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: U_STABLE UFILE* U_EXPORT2 michael@0: u_fadopt(FILE *f, michael@0: const char *locale, michael@0: const char *codepage); michael@0: michael@0: /** michael@0: * Create a UFILE that can be used for localized formatting or parsing. michael@0: * The u_sprintf and u_sscanf functions do not read or write numbers for a michael@0: * specific locale. The ustdio.h file functions can be used on this UFILE. michael@0: * The string is usable once u_fclose or u_fflush has been called on the michael@0: * returned UFILE. michael@0: * @param stringBuf The string used for reading or writing. michael@0: * @param capacity The number of code units available for use in stringBuf michael@0: * @param locale The locale whose conventions will be used to format michael@0: * and parse output. If this parameter is NULL, the default locale will michael@0: * be used. michael@0: * @return A new UFILE, or NULL if an error occurred. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UFILE* U_EXPORT2 michael@0: u_fstropen(UChar *stringBuf, michael@0: int32_t capacity, michael@0: const char *locale); michael@0: michael@0: /** michael@0: * Close a UFILE. Implies u_fflush first. michael@0: * @param file The UFILE to close. michael@0: * @stable ICU 3.0 michael@0: * @see u_fflush michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: u_fclose(UFILE *file); michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * \class LocalUFILEPointer michael@0: * "Smart pointer" class, closes a UFILE via u_fclose(). michael@0: * For most methods see the LocalPointerBase base class. michael@0: * michael@0: * @see LocalPointerBase michael@0: * @see LocalPointer michael@0: * @stable ICU 4.4 michael@0: */ michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalUFILEPointer, UFILE, u_fclose); michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Tests if the UFILE is at the end of the file stream. michael@0: * @param f The UFILE from which to read. michael@0: * @return Returns TRUE after the first read operation that attempts to michael@0: * read past the end of the file. It returns FALSE if the current position is michael@0: * not end of file. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: u_feof(UFILE *f); michael@0: michael@0: /** michael@0: * Flush output of a UFILE. Implies a flush of michael@0: * converter/transliterator state. (That is, a logical break is michael@0: * made in the output stream - for example if a different type of michael@0: * output is desired.) The underlying OS level file is also flushed. michael@0: * Note that for a stateful encoding, the converter may write additional michael@0: * bytes to return the stream to default state. michael@0: * @param file The UFILE to flush. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: u_fflush(UFILE *file); michael@0: michael@0: /** michael@0: * Rewind the file pointer to the beginning of the file. michael@0: * @param file The UFILE to rewind. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE void michael@0: u_frewind(UFILE *file); michael@0: michael@0: /** michael@0: * Get the FILE* associated with a UFILE. michael@0: * @param f The UFILE michael@0: * @return A FILE*, owned by the UFILE. (The FILE must not be modified or closed) michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE FILE* U_EXPORT2 michael@0: u_fgetfile(UFILE *f); michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: /** michael@0: * Get the locale whose conventions are used to format and parse output. michael@0: * This is the same locale passed in the preceding call tou_fsetlocale michael@0: * or u_fopen. michael@0: * @param file The UFILE to set. michael@0: * @return The locale whose conventions are used to format and parse output. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE const char* U_EXPORT2 michael@0: u_fgetlocale(UFILE *file); michael@0: michael@0: /** michael@0: * Set the locale whose conventions will be used to format and parse output. michael@0: * @param locale The locale whose conventions will be used to format michael@0: * and parse output. michael@0: * @param file The UFILE to query. michael@0: * @return NULL if successful, otherwise a negative number. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_fsetlocale(UFILE *file, michael@0: const char *locale); michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Get the codepage in which data is written to and read from the UFILE. michael@0: * This is the same codepage passed in the preceding call to michael@0: * u_fsetcodepage or u_fopen. michael@0: * @param file The UFILE to query. michael@0: * @return The codepage in which data is written to and read from the UFILE, michael@0: * or NULL if an error occurred. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE const char* U_EXPORT2 michael@0: u_fgetcodepage(UFILE *file); michael@0: michael@0: /** michael@0: * Set the codepage in which data will be written to and read from the UFILE. michael@0: * All Unicode data written to the UFILE will be converted to this codepage michael@0: * before it is written to the underlying FILE*. It it generally a bad idea to michael@0: * mix codepages within a file. This should only be called right michael@0: * after opening the UFile, or after calling u_frewind. michael@0: * @param codepage The codepage in which data will be written to michael@0: * and read from the file. For example "latin-1" or "ibm-943". michael@0: * A value of NULL means the default codepage for the UFILE's current michael@0: * locale will be used. michael@0: * @param file The UFILE to set. michael@0: * @return 0 if successful, otherwise a negative number. michael@0: * @see u_frewind michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_fsetcodepage(const char *codepage, michael@0: UFILE *file); michael@0: michael@0: michael@0: /** michael@0: * Returns an alias to the converter being used for this file. michael@0: * @param f The UFILE to get the value from michael@0: * @return alias to the converter (The converter must not be modified or closed) michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UConverter* U_EXPORT2 u_fgetConverter(UFILE *f); michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: #ifndef U_HIDE_DRAFT_API michael@0: /** michael@0: * Returns an alias to the number formatter being used for this file. michael@0: * @param f The UFILE to get the value from michael@0: * @return alias to the number formatter (The formatter must not be modified or closed) michael@0: * @draft ICU 51 michael@0: */ michael@0: U_DRAFT const UNumberFormat* U_EXPORT2 u_fgetNumberFormat(UFILE *f); michael@0: #endif /* U_HIDE_DRAFT_API */ michael@0: michael@0: /* Output functions */ michael@0: michael@0: /** michael@0: * Write formatted data to stdout. michael@0: * @param patternSpecification A pattern specifying how u_printf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @return The number of Unicode characters written to stdout michael@0: * @stable ICU 49 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_printf(const char *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Write formatted data to a UFILE. michael@0: * @param f The UFILE to which to write. michael@0: * @param patternSpecification A pattern specifying how u_fprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @return The number of Unicode characters written to f. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_fprintf(UFILE *f, michael@0: const char *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Write formatted data to a UFILE. michael@0: * This is identical to u_fprintf, except that it will michael@0: * not call va_start and va_end. michael@0: * @param f The UFILE to which to write. michael@0: * @param patternSpecification A pattern specifying how u_fprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of Unicode characters written to f. michael@0: * @see u_fprintf michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vfprintf(UFILE *f, michael@0: const char *patternSpecification, michael@0: va_list ap); michael@0: michael@0: /** michael@0: * Write formatted data to stdout. michael@0: * @param patternSpecification A pattern specifying how u_printf_u will michael@0: * interpret the variable arguments received and format the data. michael@0: * @return The number of Unicode characters written to stdout michael@0: * @stable ICU 49 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_printf_u(const UChar *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Get a UFILE for stdout. michael@0: * @return UFILE that writes to stdout michael@0: * @stable ICU 49 michael@0: */ michael@0: U_STABLE UFILE * U_EXPORT2 michael@0: u_get_stdout(void); michael@0: michael@0: /** michael@0: * Write formatted data to a UFILE. michael@0: * @param f The UFILE to which to write. michael@0: * @param patternSpecification A pattern specifying how u_fprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @return The number of Unicode characters written to f. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_fprintf_u(UFILE *f, michael@0: const UChar *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Write formatted data to a UFILE. michael@0: * This is identical to u_fprintf_u, except that it will michael@0: * not call va_start and va_end. michael@0: * @param f The UFILE to which to write. michael@0: * @param patternSpecification A pattern specifying how u_fprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of Unicode characters written to f. michael@0: * @see u_fprintf_u michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vfprintf_u(UFILE *f, michael@0: const UChar *patternSpecification, michael@0: va_list ap); michael@0: #endif michael@0: /** michael@0: * Write a Unicode to a UFILE. The null (U+0000) terminated UChar* michael@0: * s will be written to f, excluding the NULL terminator. michael@0: * A newline will be added to f. michael@0: * @param s The UChar* to write. michael@0: * @param f The UFILE to which to write. michael@0: * @return A non-negative number if successful, EOF otherwise. michael@0: * @see u_file_write michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_fputs(const UChar *s, michael@0: UFILE *f); michael@0: michael@0: /** michael@0: * Write a UChar to a UFILE. michael@0: * @param uc The UChar to write. michael@0: * @param f The UFILE to which to write. michael@0: * @return The character written if successful, EOF otherwise. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UChar32 U_EXPORT2 michael@0: u_fputc(UChar32 uc, michael@0: UFILE *f); michael@0: michael@0: /** michael@0: * Write Unicode to a UFILE. michael@0: * The ustring passed in will be converted to the UFILE's underlying michael@0: * codepage before it is written. michael@0: * @param ustring A pointer to the Unicode data to write. michael@0: * @param count The number of Unicode characters to write michael@0: * @param f The UFILE to which to write. michael@0: * @return The number of Unicode characters written. michael@0: * @see u_fputs michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_file_write(const UChar *ustring, michael@0: int32_t count, michael@0: UFILE *f); michael@0: michael@0: michael@0: /* Input functions */ michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: /** michael@0: * Read formatted data from a UFILE. michael@0: * @param f The UFILE from which to read. michael@0: * @param patternSpecification A pattern specifying how u_fscanf will michael@0: * interpret the variable arguments received and parse the data. michael@0: * @return The number of items successfully converted and assigned, or EOF michael@0: * if an error occurred. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_fscanf(UFILE *f, michael@0: const char *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Read formatted data from a UFILE. michael@0: * This is identical to u_fscanf, except that it will michael@0: * not call va_start and va_end. michael@0: * @param f The UFILE from which to read. michael@0: * @param patternSpecification A pattern specifying how u_fscanf will michael@0: * interpret the variable arguments received and parse the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of items successfully converted and assigned, or EOF michael@0: * if an error occurred. michael@0: * @see u_fscanf michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vfscanf(UFILE *f, michael@0: const char *patternSpecification, michael@0: va_list ap); michael@0: michael@0: /** michael@0: * Read formatted data from a UFILE. michael@0: * @param f The UFILE from which to read. michael@0: * @param patternSpecification A pattern specifying how u_fscanf will michael@0: * interpret the variable arguments received and parse the data. michael@0: * @return The number of items successfully converted and assigned, or EOF michael@0: * if an error occurred. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_fscanf_u(UFILE *f, michael@0: const UChar *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Read formatted data from a UFILE. michael@0: * This is identical to u_fscanf_u, except that it will michael@0: * not call va_start and va_end. michael@0: * @param f The UFILE from which to read. michael@0: * @param patternSpecification A pattern specifying how u_fscanf will michael@0: * interpret the variable arguments received and parse the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of items successfully converted and assigned, or EOF michael@0: * if an error occurred. michael@0: * @see u_fscanf_u michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vfscanf_u(UFILE *f, michael@0: const UChar *patternSpecification, michael@0: va_list ap); michael@0: #endif michael@0: michael@0: /** michael@0: * Read one line of text into a UChar* string from a UFILE. The newline michael@0: * at the end of the line is read into the string. The string is always michael@0: * null terminated michael@0: * @param f The UFILE from which to read. michael@0: * @param n The maximum number of characters - 1 to read. michael@0: * @param s The UChar* to receive the read data. Characters will be michael@0: * stored successively in s until a newline or EOF is michael@0: * reached. A null character (U+0000) will be appended to s. michael@0: * @return A pointer to s, or NULL if no characters were available. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UChar* U_EXPORT2 michael@0: u_fgets(UChar *s, michael@0: int32_t n, michael@0: UFILE *f); michael@0: michael@0: /** michael@0: * Read a UChar from a UFILE. It is recommended that u_fgetcx michael@0: * used instead for proper parsing functions, but sometimes reading michael@0: * code units is needed instead of codepoints. michael@0: * michael@0: * @param f The UFILE from which to read. michael@0: * @return The UChar value read, or U+FFFF if no character was available. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UChar U_EXPORT2 michael@0: u_fgetc(UFILE *f); michael@0: michael@0: /** michael@0: * Read a UChar32 from a UFILE. michael@0: * michael@0: * @param f The UFILE from which to read. michael@0: * @return The UChar32 value read, or U_EOF if no character was michael@0: * available, or U+FFFFFFFF if an ill-formed character was michael@0: * encountered. michael@0: * @see u_unescape() michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UChar32 U_EXPORT2 michael@0: u_fgetcx(UFILE *f); michael@0: michael@0: /** michael@0: * Unget a UChar from a UFILE. michael@0: * If this function is not the first to operate on f after a call michael@0: * to u_fgetc, the results are undefined. michael@0: * If this function is passed a character that was not recieved from the michael@0: * previous u_fgetc or u_fgetcx call, the results are undefined. michael@0: * @param c The UChar to put back on the stream. michael@0: * @param f The UFILE to receive c. michael@0: * @return The UChar32 value put back if successful, U_EOF otherwise. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UChar32 U_EXPORT2 michael@0: u_fungetc(UChar32 c, michael@0: UFILE *f); michael@0: michael@0: /** michael@0: * Read Unicode from a UFILE. michael@0: * Bytes will be converted from the UFILE's underlying codepage, with michael@0: * subsequent conversion to Unicode. The data will not be NULL terminated. michael@0: * @param chars A pointer to receive the Unicode data. michael@0: * @param count The number of Unicode characters to read. michael@0: * @param f The UFILE from which to read. michael@0: * @return The number of Unicode characters read. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_file_read(UChar *chars, michael@0: int32_t count, michael@0: UFILE *f); michael@0: michael@0: #if !UCONFIG_NO_TRANSLITERATION michael@0: michael@0: /** michael@0: * Set a transliterator on the UFILE. The transliterator will be owned by the michael@0: * UFILE. michael@0: * @param file The UFILE to set transliteration on michael@0: * @param adopt The UTransliterator to set. Can be NULL, which will michael@0: * mean that no transliteration is used. michael@0: * @param direction either U_READ, U_WRITE, or U_READWRITE - sets michael@0: * which direction the transliterator is to be applied to. If michael@0: * U_READWRITE, the "Read" transliteration will be in the inverse michael@0: * direction. michael@0: * @param status ICU error code. michael@0: * @return The previously set transliterator, owned by the michael@0: * caller. If U_READWRITE is specified, only the WRITE transliterator michael@0: * is returned. In most cases, the caller should call utrans_close() michael@0: * on the result of this function. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE UTransliterator* U_EXPORT2 michael@0: u_fsettransliterator(UFILE *file, UFileDirection direction, michael@0: UTransliterator *adopt, UErrorCode *status); michael@0: michael@0: #endif michael@0: michael@0: michael@0: /* Output string functions */ michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: michael@0: /** michael@0: * Write formatted data to a Unicode string. michael@0: * michael@0: * @param buffer The Unicode String to which to write. michael@0: * @param patternSpecification A pattern specifying how u_sprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @return The number of Unicode code units written to buffer. This michael@0: * does not include the terminating null character. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_sprintf(UChar *buffer, michael@0: const char *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Write formatted data to a Unicode string. When the number of code units michael@0: * required to store the data exceeds count, then count code michael@0: * units of data are stored in buffer and a negative value is michael@0: * returned. When the number of code units required to store the data equals michael@0: * count, the string is not null terminated and count is michael@0: * returned. michael@0: * michael@0: * @param buffer The Unicode String to which to write. michael@0: * @param count The number of code units to read. michael@0: * @param patternSpecification A pattern specifying how u_sprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @return The number of Unicode characters that would have been written to michael@0: * buffer had count been sufficiently large. This does not include michael@0: * the terminating null character. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_snprintf(UChar *buffer, michael@0: int32_t count, michael@0: const char *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Write formatted data to a Unicode string. michael@0: * This is identical to u_sprintf, except that it will michael@0: * not call va_start and va_end. michael@0: * michael@0: * @param buffer The Unicode string to which to write. michael@0: * @param patternSpecification A pattern specifying how u_sprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of Unicode characters written to buffer. michael@0: * @see u_sprintf michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vsprintf(UChar *buffer, michael@0: const char *patternSpecification, michael@0: va_list ap); michael@0: michael@0: /** michael@0: * Write formatted data to a Unicode string. michael@0: * This is identical to u_snprintf, except that it will michael@0: * not call va_start and va_end.

michael@0: * When the number of code units required to store the data exceeds michael@0: * count, then count code units of data are stored in michael@0: * buffer and a negative value is returned. When the number of code michael@0: * units required to store the data equals count, the string is not michael@0: * null terminated and count is returned. michael@0: * michael@0: * @param buffer The Unicode string to which to write. michael@0: * @param count The number of code units to read. michael@0: * @param patternSpecification A pattern specifying how u_sprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of Unicode characters that would have been written to michael@0: * buffer had count been sufficiently large. michael@0: * @see u_sprintf michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vsnprintf(UChar *buffer, michael@0: int32_t count, michael@0: const char *patternSpecification, michael@0: va_list ap); michael@0: michael@0: /** michael@0: * Write formatted data to a Unicode string. michael@0: * michael@0: * @param buffer The Unicode string to which to write. michael@0: * @param patternSpecification A pattern specifying how u_sprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @return The number of Unicode characters written to buffer. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_sprintf_u(UChar *buffer, michael@0: const UChar *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Write formatted data to a Unicode string. When the number of code units michael@0: * required to store the data exceeds count, then count code michael@0: * units of data are stored in buffer and a negative value is michael@0: * returned. When the number of code units required to store the data equals michael@0: * count, the string is not null terminated and count is michael@0: * returned. michael@0: * michael@0: * @param buffer The Unicode string to which to write. michael@0: * @param count The number of code units to read. michael@0: * @param patternSpecification A pattern specifying how u_sprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @return The number of Unicode characters that would have been written to michael@0: * buffer had count been sufficiently large. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_snprintf_u(UChar *buffer, michael@0: int32_t count, michael@0: const UChar *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Write formatted data to a Unicode string. michael@0: * This is identical to u_sprintf_u, except that it will michael@0: * not call va_start and va_end. michael@0: * michael@0: * @param buffer The Unicode string to which to write. michael@0: * @param patternSpecification A pattern specifying how u_sprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of Unicode characters written to f. michael@0: * @see u_sprintf_u michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vsprintf_u(UChar *buffer, michael@0: const UChar *patternSpecification, michael@0: va_list ap); michael@0: michael@0: /** michael@0: * Write formatted data to a Unicode string. michael@0: * This is identical to u_snprintf_u, except that it will michael@0: * not call va_start and va_end. michael@0: * When the number of code units required to store the data exceeds michael@0: * count, then count code units of data are stored in michael@0: * buffer and a negative value is returned. When the number of code michael@0: * units required to store the data equals count, the string is not michael@0: * null terminated and count is returned. michael@0: * michael@0: * @param buffer The Unicode string to which to write. michael@0: * @param count The number of code units to read. michael@0: * @param patternSpecification A pattern specifying how u_sprintf will michael@0: * interpret the variable arguments received and format the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of Unicode characters that would have been written to michael@0: * f had count been sufficiently large. michael@0: * @see u_sprintf_u michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vsnprintf_u(UChar *buffer, michael@0: int32_t count, michael@0: const UChar *patternSpecification, michael@0: va_list ap); michael@0: michael@0: /* Input string functions */ michael@0: michael@0: /** michael@0: * Read formatted data from a Unicode string. michael@0: * michael@0: * @param buffer The Unicode string from which to read. michael@0: * @param patternSpecification A pattern specifying how u_sscanf will michael@0: * interpret the variable arguments received and parse the data. michael@0: * @return The number of items successfully converted and assigned, or EOF michael@0: * if an error occurred. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_sscanf(const UChar *buffer, michael@0: const char *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Read formatted data from a Unicode string. michael@0: * This is identical to u_sscanf, except that it will michael@0: * not call va_start and va_end. michael@0: * michael@0: * @param buffer The Unicode string from which to read. michael@0: * @param patternSpecification A pattern specifying how u_sscanf will michael@0: * interpret the variable arguments received and parse the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of items successfully converted and assigned, or EOF michael@0: * if an error occurred. michael@0: * @see u_sscanf michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vsscanf(const UChar *buffer, michael@0: const char *patternSpecification, michael@0: va_list ap); michael@0: michael@0: /** michael@0: * Read formatted data from a Unicode string. michael@0: * michael@0: * @param buffer The Unicode string from which to read. michael@0: * @param patternSpecification A pattern specifying how u_sscanf will michael@0: * interpret the variable arguments received and parse the data. michael@0: * @return The number of items successfully converted and assigned, or EOF michael@0: * if an error occurred. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_sscanf_u(const UChar *buffer, michael@0: const UChar *patternSpecification, michael@0: ... ); michael@0: michael@0: /** michael@0: * Read formatted data from a Unicode string. michael@0: * This is identical to u_sscanf_u, except that it will michael@0: * not call va_start and va_end. michael@0: * michael@0: * @param buffer The Unicode string from which to read. michael@0: * @param patternSpecification A pattern specifying how u_sscanf will michael@0: * interpret the variable arguments received and parse the data. michael@0: * @param ap The argument list to use. michael@0: * @return The number of items successfully converted and assigned, or EOF michael@0: * if an error occurred. michael@0: * @see u_sscanf_u michael@0: * @stable ICU 3.0 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_vsscanf_u(const UChar *buffer, michael@0: const UChar *patternSpecification, michael@0: va_list ap); michael@0: michael@0: #endif michael@0: #endif michael@0: michael@0: