Logo Search packages:      
Sourcecode: icu version File versions  Download package

ustdio.h File Reference

C API: Unicode stdio-like API. More...

#include <stdio.h>
#include <stdarg.h>
#include "unicode/utypes.h"
#include "unicode/ucnv.h"
#include "unicode/utrans.h"
#include "unicode/localpointer.h"
Include dependency graph for ustdio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


#define U_EOF   0xFFFF


typedef struct UFILE UFILE


enum  UFileDirection { U_READ = 1, U_WRITE = 2, U_READWRITE = 3 }


U_STABLE UFILE *U_EXPORT2 u_fadopt (FILE *f, const char *locale, const char *codepage)
U_STABLE void U_EXPORT2 u_fclose (UFILE *file)
U_STABLE UBool U_EXPORT2 u_feof (UFILE *f)
U_STABLE void U_EXPORT2 u_fflush (UFILE *file)
U_STABLE UChar U_EXPORT2 u_fgetc (UFILE *f)
U_STABLE const char *U_EXPORT2 u_fgetcodepage (UFILE *file)
U_STABLE UConverter *U_EXPORT2 u_fgetConverter (UFILE *f)
U_STABLE UChar32 U_EXPORT2 u_fgetcx (UFILE *f)
U_STABLE FILE *U_EXPORT2 u_fgetfile (UFILE *f)
U_STABLE const char *U_EXPORT2 u_fgetlocale (UFILE *file)
U_STABLE UChar *U_EXPORT2 u_fgets (UChar *s, int32_t n, UFILE *f)
U_STABLE int32_t U_EXPORT2 u_file_read (UChar *chars, int32_t count, UFILE *f)
U_STABLE int32_t U_EXPORT2 u_file_write (const UChar *ustring, int32_t count, UFILE *f)
U_STABLE UFILE *U_EXPORT2 u_finit (FILE *f, const char *locale, const char *codepage)
U_STABLE UFILE *U_EXPORT2 u_fopen (const char *filename, const char *perm, const char *locale, const char *codepage)
U_STABLE int32_t U_EXPORT2 u_fprintf (UFILE *f, const char *patternSpecification,...)
U_STABLE int32_t U_EXPORT2 u_fprintf_u (UFILE *f, const UChar *patternSpecification,...)
U_STABLE UChar32 U_EXPORT2 u_fputc (UChar32 uc, UFILE *f)
U_STABLE int32_t U_EXPORT2 u_fputs (const UChar *s, UFILE *f)
U_STABLE void u_frewind (UFILE *file)
U_STABLE int32_t U_EXPORT2 u_fscanf (UFILE *f, const char *patternSpecification,...)
U_STABLE int32_t U_EXPORT2 u_fscanf_u (UFILE *f, const UChar *patternSpecification,...)
U_STABLE int32_t U_EXPORT2 u_fsetcodepage (const char *codepage, UFILE *file)
U_STABLE int32_t U_EXPORT2 u_fsetlocale (UFILE *file, const char *locale)
U_STABLE UTransliterator *U_EXPORT2 u_fsettransliterator (UFILE *file, UFileDirection direction, UTransliterator *adopt, UErrorCode *status)
U_STABLE UFILE *U_EXPORT2 u_fstropen (UChar *stringBuf, int32_t capacity, const char *locale)
U_STABLE UChar32 U_EXPORT2 u_fungetc (UChar32 c, UFILE *f)
U_STABLE int32_t U_EXPORT2 u_snprintf (UChar *buffer, int32_t count, const char *patternSpecification,...)
U_STABLE int32_t U_EXPORT2 u_snprintf_u (UChar *buffer, int32_t count, const UChar *patternSpecification,...)
U_STABLE int32_t U_EXPORT2 u_sprintf (UChar *buffer, const char *patternSpecification,...)
U_STABLE int32_t U_EXPORT2 u_sprintf_u (UChar *buffer, const UChar *patternSpecification,...)
U_STABLE int32_t U_EXPORT2 u_sscanf (const UChar *buffer, const char *patternSpecification,...)
U_STABLE int32_t U_EXPORT2 u_sscanf_u (const UChar *buffer, const UChar *patternSpecification,...)
U_STABLE int32_t U_EXPORT2 u_vfprintf (UFILE *f, const char *patternSpecification, va_list ap)
U_STABLE int32_t U_EXPORT2 u_vfprintf_u (UFILE *f, const UChar *patternSpecification, va_list ap)
U_STABLE int32_t U_EXPORT2 u_vfscanf (UFILE *f, const char *patternSpecification, va_list ap)
U_STABLE int32_t U_EXPORT2 u_vfscanf_u (UFILE *f, const UChar *patternSpecification, va_list ap)
U_STABLE int32_t U_EXPORT2 u_vsnprintf (UChar *buffer, int32_t count, const char *patternSpecification, va_list ap)
U_STABLE int32_t U_EXPORT2 u_vsnprintf_u (UChar *buffer, int32_t count, const UChar *patternSpecification, va_list ap)
U_STABLE int32_t U_EXPORT2 u_vsprintf (UChar *buffer, const char *patternSpecification, va_list ap)
U_STABLE int32_t U_EXPORT2 u_vsprintf_u (UChar *buffer, const UChar *patternSpecification, va_list ap)
U_STABLE int32_t U_EXPORT2 u_vsscanf (const UChar *buffer, const char *patternSpecification, va_list ap)
U_STABLE int32_t U_EXPORT2 u_vsscanf_u (const UChar *buffer, const UChar *patternSpecification, va_list ap)

Detailed Description

C API: Unicode stdio-like API.

Unicode stdio-like C API

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

  • Locale specific formatting and parsing is only done with file IO.
  • u_fstropen can be used to simulate file IO with strings. This is similar to the iostream API, and it allows locale specific formatting and parsing to be used.
  • This API provides uniform formatting and parsing behavior between platforms (unlike the standard stdio implementations found on various platforms).
  • This API is better suited for text data handling than binary data handling when compared to the typical stdio implementation.
  • You can specify a Transliterator while using the file IO.
  • You can specify a file's codepage separately from the default system codepage.

Formatting and Parsing Specification

General printf format:
%[format modifier][width][.precision][type modifier][format]

General scanf format:
%[*][format modifier][width][type modifier][format]

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
When width is specified for scanf, this acts like a non-NULL-terminated char * string.
By default, only one char is written.
SUChar *UChar *Null terminated UTF-16 string
CUCharUChar16-bit Unicode code unit
When width is specified for scanf, this acts like a non-NULL-terminated UChar * string
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

Format modifiers

hd, i, o, xint16_tshort format
huuint16_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
ld, i, o, xint32_tlong format (no effect)
luuint32_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
lld, i, o, xint64_tlong long format
lluuint64_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 decimal point for floats.
%nallN/AWidth of input/output. num is an actual number from 0 to some large number.
%.ne, f, g, E, F, GN/ASignificant digits precision. num is an actual number from 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.

printf modifier %* int32_t Next argument after this one specifies the width

scanf modifier %* N/A This field is scanned, but not stored

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

    UFILE *out = u_finit(stdout, NULL, NULL);
    UnicodeString string1("string 1");
    UnicodeString string2("string 2");
    u_fprintf(out, "%S\n", string1.getTerminatedBuffer());
    u_fprintf(out, "%.*S\n", string2.length(), string2.getBuffer());

Definition in file ustdio.h.

Generated by  Doxygen 1.6.0   Back to index