Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/ustdio.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 ******************************************************************************
0005 *
0006 *   Copyright (C) 1998-2015, International Business Machines
0007 *   Corporation and others.  All Rights Reserved.
0008 *
0009 ******************************************************************************
0010 *
0011 * File ustdio.h
0012 *
0013 * Modification History:
0014 *
0015 *   Date        Name        Description
0016 *   10/16/98    stephen     Creation.
0017 *   11/06/98    stephen     Modified per code review.
0018 *   03/12/99    stephen     Modified for new C API.
0019 *   07/19/99    stephen     Minor doc update.
0020 *   02/01/01    george      Added sprintf & sscanf with all of its variants
0021 ******************************************************************************
0022 */
0023 
0024 #ifndef USTDIO_H
0025 #define USTDIO_H
0026 
0027 #include <stdio.h>
0028 #include <stdarg.h>
0029 
0030 #include "unicode/utypes.h"
0031 #include "unicode/ucnv.h"
0032 #include "unicode/utrans.h"
0033 #include "unicode/unum.h"
0034 
0035 #if U_SHOW_CPLUSPLUS_API
0036 #include "unicode/localpointer.h"
0037 #endif   // U_SHOW_CPLUSPLUS_API
0038 
0039 #if !UCONFIG_NO_CONVERSION
0040 
0041 /*
0042     TODO
0043  The following is a small list as to what is currently wrong/suggestions for
0044  ustdio.
0045 
0046  * Make sure that * in the scanf format specification works for all formats.
0047  * Each UFILE takes up at least 2KB.
0048     Look into adding setvbuf() for configurable buffers.
0049  * This library does buffering. The OS should do this for us already. Check on
0050     this, and remove it from this library, if this is the case. Double buffering
0051     wastes a lot of time and space.
0052  * Test stdin and stdout with the u_f* functions
0053  * Testing should be done for reading and writing multi-byte encodings,
0054     and make sure that a character that is contained across buffer boundaries
0055     works even for incomplete characters.
0056  * Make sure that the last character is flushed when the file/string is closed.
0057  * snprintf should follow the C99 standard for the return value, which is
0058     return the number of characters (excluding the trailing '\0')
0059     which would have been written to the destination string regardless
0060     of available space. This is like pre-flighting.
0061  * Everything that uses %s should do what operator>> does for UnicodeString.
0062     It should convert one byte at a time, and once a character is
0063     converted then check to see if it's whitespace or in the scanset.
0064     If it's whitespace or in the scanset, put all the bytes back (do nothing
0065     for sprintf/sscanf).
0066  * If bad string data is encountered, make sure that the function fails
0067     without memory leaks and the unconvertable characters are valid
0068     substitution or are escaped characters.
0069  * u_fungetc() can't unget a character when it's at the beginning of the
0070     internal conversion buffer. For example, read the buffer size # of
0071     characters, and then ungetc to get the previous character that was
0072     at the end of the last buffer.
0073  * u_fflush() and u_fclose should return an int32_t like C99 functions.
0074     0 is returned if the operation was successful and EOF otherwise.
0075  * u_fsettransliterator does not support U_READ side of transliteration.
0076  * The format specifier should limit the size of a format or honor it in
0077     order to prevent buffer overruns.  (e.g. %256.256d).
0078  * u_fread and u_fwrite don't exist. They're needed for reading and writing
0079     data structures without any conversion.
0080  * u_file_read and u_file_write are used for writing strings. u_fgets and
0081     u_fputs or u_fread and u_fwrite should be used to do this.
0082  * The width parameter for all scanf formats, including scanset, needs
0083     better testing. This prevents buffer overflows.
0084  * Figure out what is suppose to happen when a codepage is changed midstream.
0085     Maybe a flush or a rewind are good enough.
0086  * Make sure that a UFile opened with "rw" can be used after using
0087     u_fflush with a u_frewind.
0088  * scanf(%i) should detect what type of number to use.
0089  * Add more testing of the alternate format, %#
0090  * Look at newline handling of fputs/puts
0091  * Think more about codeunit/codepoint error handling/support in %S,%s,%C,%c,%[]
0092  * Complete the file documentation with proper doxygen formatting.
0093     See http://oss.software.ibm.com/pipermail/icu/2003-July/005647.html
0094 */
0095 
0096 /**
0097  * \file
0098  * \brief C API: Unicode stdio-like API
0099  *
0100  * <h2>Unicode stdio-like C API</h2>
0101  *
0102  * <p>This API provides an stdio-like API wrapper around ICU's other
0103  * formatting and parsing APIs. It is meant to ease the transition of adding
0104  * Unicode support to a preexisting applications using stdio. The following
0105  * is a small list of noticeable differences between stdio and ICU I/O's
0106  * ustdio implementation.</p>
0107  *
0108  * <ul>
0109  * <li>Locale specific formatting and parsing is only done with file IO.</li>
0110  * <li>u_fstropen can be used to simulate file IO with strings.
0111  * This is similar to the iostream API, and it allows locale specific
0112  * formatting and parsing to be used.</li>
0113  * <li>This API provides uniform formatting and parsing behavior between
0114  * platforms (unlike the standard stdio implementations found on various
0115  * platforms).</li>
0116  * <li>This API is better suited for text data handling than binary data
0117  * handling when compared to the typical stdio implementation.</li>
0118  * <li>You can specify a Transliterator while using the file IO.</li>
0119  * <li>You can specify a file's codepage separately from the default
0120  * system codepage.</li>
0121  * </ul>
0122  *
0123  * <h2>Formatting and Parsing Specification</h2>
0124  *
0125  * General printf format:<br>
0126  * %[format modifier][width][.precision][type modifier][format]
0127  * 
0128  * General scanf format:<br>
0129  * %[*][format modifier][width][type modifier][format]
0130  * 
0131 <table cellspacing="3">
0132 <tr><td>format</td><td>default<br>printf<br>type</td><td>default<br>scanf<br>type</td><td>description</td></tr>
0133 <tr><td>%E</td><td>double</td><td>float</td><td>Scientific with an uppercase exponent</td></tr>
0134 <tr><td>%e</td><td>double</td><td>float</td><td>Scientific with a lowercase exponent</td></tr>
0135 <tr><td>%G</td><td>double</td><td>float</td><td>Use %E or %f for best format</td></tr>
0136 <tr><td>%g</td><td>double</td><td>float</td><td>Use %e or %f for best format</td></tr>
0137 <tr><td>%f</td><td>double</td><td>float</td><td>Simple floating point without the exponent</td></tr>
0138 <tr><td>%X</td><td>int32_t</td><td>int32_t</td><td>ustdio special uppercase hex radix formatting</td></tr>
0139 <tr><td>%x</td><td>int32_t</td><td>int32_t</td><td>ustdio special lowercase hex radix formatting</td></tr>
0140 <tr><td>%d</td><td>int32_t</td><td>int32_t</td><td>Decimal format</td></tr>
0141 <tr><td>%i</td><td>int32_t</td><td>int32_t</td><td>Same as %d</td></tr>
0142 <tr><td>%n</td><td>int32_t</td><td>int32_t</td><td>count (write the number of UTF-16 codeunits read/written)</td></tr>
0143 <tr><td>%o</td><td>int32_t</td><td>int32_t</td><td>ustdio special octal radix formatting</td></tr>
0144 <tr><td>%u</td><td>uint32_t</td><td>uint32_t</td><td>Decimal format</td></tr>
0145 <tr><td>%p</td><td>void *</td><td>void *</td><td>Prints the pointer value</td></tr>
0146 <tr><td>%s</td><td>char *</td><td>char *</td><td>Use default converter or specified converter from fopen</td></tr>
0147 <tr><td>%c</td><td>char</td><td>char</td><td>Use default converter or specified converter from fopen<br>
0148 When width is specified for scanf, this acts like a non-NULL-terminated char * string.<br>
0149 By default, only one char is written.</td></tr>
0150 <tr><td>%S</td><td>UChar *</td><td>UChar *</td><td>Null terminated UTF-16 string</td></tr>
0151 <tr><td>%C</td><td>UChar</td><td>UChar</td><td>16-bit Unicode code unit<br>
0152 When width is specified for scanf, this acts like a non-NULL-terminated UChar * string<br>
0153 By default, only one codepoint is written.</td></tr>
0154 <tr><td>%[]</td><td>&nbsp;</td><td>UChar *</td><td>Null terminated UTF-16 string which contains the filtered set of characters specified by the UnicodeSet</td></tr>
0155 <tr><td>%%</td><td>&nbsp;</td><td>&nbsp;</td><td>Show a percent sign</td></tr>
0156 </table>
0157 
0158 Format modifiers
0159 <table>
0160 <tr><td>modifier</td><td>formats</td><td>type</td><td>comments</td></tr>
0161 <tr><td>%h</td><td>%d, %i, %o, %x</td><td>int16_t</td><td>short format</td></tr>
0162 <tr><td>%h</td><td>%u</td><td>uint16_t</td><td>short format</td></tr>
0163 <tr><td>%h</td><td>c</td><td>char</td><td><b>(Unimplemented)</b> Use invariant converter</td></tr>
0164 <tr><td>%h</td><td>s</td><td>char *</td><td><b>(Unimplemented)</b> Use invariant converter</td></tr>
0165 <tr><td>%h</td><td>C</td><td>char</td><td><b>(Unimplemented)</b> 8-bit Unicode code unit</td></tr>
0166 <tr><td>%h</td><td>S</td><td>char *</td><td><b>(Unimplemented)</b> Null terminated UTF-8 string</td></tr>
0167 <tr><td>%l</td><td>%d, %i, %o, %x</td><td>int32_t</td><td>long format (no effect)</td></tr>
0168 <tr><td>%l</td><td>%u</td><td>uint32_t</td><td>long format (no effect)</td></tr>
0169 <tr><td>%l</td><td>c</td><td>N/A</td><td><b>(Unimplemented)</b> Reserved for future implementation</td></tr>
0170 <tr><td>%l</td><td>s</td><td>N/A</td><td><b>(Unimplemented)</b> Reserved for future implementation</td></tr>
0171 <tr><td>%l</td><td>C</td><td>UChar32</td><td><b>(Unimplemented)</b> 32-bit Unicode code unit</td></tr>
0172 <tr><td>%l</td><td>S</td><td>UChar32 *</td><td><b>(Unimplemented)</b> Null terminated UTF-32 string</td></tr>
0173 <tr><td>%ll</td><td>%d, %i, %o, %x</td><td>int64_t</td><td>long long format</td></tr>
0174 <tr><td>%ll</td><td>%u</td><td>uint64_t</td><td><b>(Unimplemented)</b> long long format</td></tr>
0175 <tr><td>%-</td><td><i>all</i></td><td>N/A</td><td>Left justify</td></tr>
0176 <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>
0177 <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>
0178 <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 
0179                 decimal point for floats.</td></tr>
0180 <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 
0181                 some large number.</td></tr>
0182 <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
0183                 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>
0184 </table>
0185 
0186 printf modifier
0187 %*  int32_t     Next argument after this one specifies the width
0188 
0189 scanf modifier
0190 %*  N/A         This field is scanned, but not stored
0191 
0192 <p>If you are using this C API instead of the ustream.h API for C++,
0193 you can use one of the following u_fprintf examples to display a UnicodeString.</p>
0194 
0195 <pre><code>
0196     UFILE *out = u_finit(stdout, NULL, NULL);
0197     UnicodeString string1("string 1");
0198     UnicodeString string2("string 2");
0199     u_fprintf(out, "%S\n", string1.getTerminatedBuffer());
0200     u_fprintf(out, "%.*S\n", string2.length(), string2.getBuffer());
0201     u_fclose(out);
0202 </code></pre>
0203 
0204  */
0205 
0206 
0207 /**
0208  * When an end of file is encountered, this value can be returned.
0209  * @see u_fgetc
0210  * @stable 3.0
0211  */
0212 #define U_EOF 0xFFFF
0213 
0214 /** Forward declaration of a Unicode-aware file @stable 3.0 */
0215 typedef struct UFILE UFILE;
0216 
0217 /**
0218  * Enum for which direction of stream a transliterator applies to.
0219  * @see u_fsettransliterator
0220  * @stable ICU 3.0
0221  */
0222 typedef enum { 
0223    U_READ = 1,
0224    U_WRITE = 2, 
0225    U_READWRITE =3  /* == (U_READ | U_WRITE) */ 
0226 } UFileDirection;
0227 
0228 /**
0229  * Open a UFILE.
0230  * A UFILE is a wrapper around a FILE* that is locale and codepage aware.
0231  * That is, data written to a UFILE will be formatted using the conventions
0232  * specified by that UFILE's Locale; this data will be in the character set
0233  * specified by that UFILE's codepage.
0234  * @param filename The name of the file to open. Must be 0-terminated.
0235  * @param perm The read/write permission for the UFILE; one of "r", "w", "rw"
0236  * @param locale The locale whose conventions will be used to format 
0237  * and parse output. If this parameter is NULL, the default locale will 
0238  * be used.
0239  * @param codepage The codepage in which data will be written to and
0240  * read from the file. If this parameter is NULL the system default codepage
0241  * will be used.
0242  * @return A new UFILE, or NULL if an error occurred.
0243  * @stable ICU 3.0
0244  */
0245 U_CAPI UFILE* U_EXPORT2
0246 u_fopen(const char    *filename,
0247     const char    *perm,
0248     const char    *locale,
0249     const char    *codepage);
0250 
0251 /**
0252  * Open a UFILE with a UChar* filename
0253  * A UFILE is a wrapper around a FILE* that is locale and codepage aware.
0254  * That is, data written to a UFILE will be formatted using the conventions
0255  * specified by that UFILE's Locale; this data will be in the character set
0256  * specified by that UFILE's codepage.
0257  * @param filename The name of the file to open. Must be 0-terminated.
0258  * @param perm The read/write permission for the UFILE; one of "r", "w", "rw"
0259  * @param locale The locale whose conventions will be used to format
0260  * and parse output. If this parameter is NULL, the default locale will
0261  * be used.
0262  * @param codepage The codepage in which data will be written to and
0263  * read from the file. If this parameter is NULL the system default codepage
0264  * will be used.
0265  * @return A new UFILE, or NULL if an error occurred.
0266  * @stable ICU 54
0267  */
0268 U_CAPI UFILE* U_EXPORT2
0269 u_fopen_u(const UChar    *filename,
0270     const char    *perm,
0271     const char    *locale,
0272     const char    *codepage);
0273 
0274 /**
0275  * Open a UFILE on top of an existing FILE* stream. The FILE* stream
0276  * ownership remains with the caller. To have the UFILE take over
0277  * ownership and responsibility for the FILE* stream, use the
0278  * function u_fadopt.
0279  * @param f The FILE* to which this UFILE will attach and use.
0280  * @param locale The locale whose conventions will be used to format 
0281  * and parse output. If this parameter is NULL, the default locale will 
0282  * be used.
0283  * @param codepage The codepage in which data will be written to and
0284  * read from the file. If this parameter is NULL, data will be written and
0285  * read using the default codepage for <TT>locale</TT>, unless <TT>locale</TT>
0286  * is NULL, in which case the system default codepage will be used.
0287  * @return A new UFILE, or NULL if an error occurred.
0288  * @stable ICU 3.0
0289  */
0290 U_CAPI UFILE* U_EXPORT2
0291 u_finit(FILE        *f,
0292     const char    *locale,
0293     const char    *codepage);
0294 
0295 /**
0296  * Open a UFILE on top of an existing FILE* stream. The FILE* stream
0297  * ownership is transferred to the new UFILE. It will be closed when the
0298  * UFILE is closed.
0299  * @param f The FILE* which this UFILE will take ownership of.
0300  * @param locale The locale whose conventions will be used to format
0301  * and parse output. If this parameter is NULL, the default locale will
0302  * be used.
0303  * @param codepage The codepage in which data will be written to and
0304  * read from the file. If this parameter is NULL, data will be written and
0305  * read using the default codepage for <TT>locale</TT>, unless <TT>locale</TT>
0306  * is NULL, in which case the system default codepage will be used.
0307  * @return A new UFILE, or NULL if an error occurred. If an error occurs
0308  * the ownership of the FILE* stream remains with the caller.
0309  * @stable ICU 4.4
0310  */
0311 U_CAPI UFILE* U_EXPORT2
0312 u_fadopt(FILE     *f,
0313     const char    *locale,
0314     const char    *codepage);
0315 
0316 /**
0317  * Create a UFILE that can be used for localized formatting or parsing.
0318  * The u_sprintf and u_sscanf functions do not read or write numbers for a
0319  * specific locale. The ustdio.h file functions can be used on this UFILE.
0320  * The string is usable once u_fclose or u_fflush has been called on the
0321  * returned UFILE.
0322  * @param stringBuf The string used for reading or writing.
0323  * @param capacity The number of code units available for use in stringBuf
0324  * @param locale The locale whose conventions will be used to format 
0325  * and parse output. If this parameter is NULL, the default locale will 
0326  * be used.
0327  * @return A new UFILE, or NULL if an error occurred.
0328  * @stable ICU 3.0
0329  */
0330 U_CAPI UFILE* U_EXPORT2
0331 u_fstropen(UChar      *stringBuf,
0332            int32_t     capacity,
0333            const char *locale);
0334 
0335 /**
0336  * Close a UFILE. Implies u_fflush first.
0337  * @param file The UFILE to close.
0338  * @stable ICU 3.0
0339  * @see u_fflush
0340  */
0341 U_CAPI void U_EXPORT2
0342 u_fclose(UFILE *file);
0343 
0344 #if U_SHOW_CPLUSPLUS_API
0345 
0346 U_NAMESPACE_BEGIN
0347 
0348 /**
0349  * \class LocalUFILEPointer
0350  * "Smart pointer" class, closes a UFILE via u_fclose().
0351  * For most methods see the LocalPointerBase base class.
0352  *
0353  * @see LocalPointerBase
0354  * @see LocalPointer
0355  * @stable ICU 4.4
0356  */
0357 U_DEFINE_LOCAL_OPEN_POINTER(LocalUFILEPointer, UFILE, u_fclose);
0358 
0359 U_NAMESPACE_END
0360 
0361 #endif
0362 
0363 /**
0364  * Tests if the UFILE is at the end of the file stream.
0365  * @param f The UFILE from which to read.
0366  * @return Returns true after the first read operation that attempts to
0367  * read past the end of the file. It returns false if the current position is
0368  * not end of file.
0369  * @stable ICU 3.0
0370 */
0371 U_CAPI UBool U_EXPORT2
0372 u_feof(UFILE  *f);
0373 
0374 /**
0375  * Flush output of a UFILE. Implies a flush of
0376  * converter/transliterator state. (That is, a logical break is
0377  * made in the output stream - for example if a different type of
0378  * output is desired.)  The underlying OS level file is also flushed.
0379  * Note that for a stateful encoding, the converter may write additional
0380  * bytes to return the stream to default state.
0381  * @param file The UFILE to flush.
0382  * @stable ICU 3.0
0383  */
0384 U_CAPI void U_EXPORT2
0385 u_fflush(UFILE *file);
0386 
0387 /**
0388  * Rewind the file pointer to the beginning of the file.
0389  * @param file The UFILE to rewind.
0390  * @stable ICU 3.0
0391  */
0392 U_CAPI void
0393 u_frewind(UFILE *file);
0394 
0395 /**
0396  * Get the FILE* associated with a UFILE.
0397  * @param f The UFILE
0398  * @return A FILE*, owned by the UFILE. (The FILE <EM>must not</EM> be modified or closed)
0399  * @stable ICU 3.0
0400  */
0401 U_CAPI FILE* U_EXPORT2
0402 u_fgetfile(UFILE *f);
0403 
0404 #if !UCONFIG_NO_FORMATTING
0405 
0406 /**
0407  * Get the locale whose conventions are used to format and parse output.
0408  * This is the same locale passed in the preceding call to<TT>u_fsetlocale</TT>
0409  * or <TT>u_fopen</TT>.
0410  * @param file The UFILE to set.
0411  * @return The locale whose conventions are used to format and parse output.
0412  * @stable ICU 3.0
0413  */
0414 U_CAPI const char* U_EXPORT2
0415 u_fgetlocale(UFILE *file);
0416 
0417 /**
0418  * Set the locale whose conventions will be used to format and parse output.
0419  * @param locale The locale whose conventions will be used to format 
0420  * and parse output.
0421  * @param file The UFILE to query.
0422  * @return NULL if successful, otherwise a negative number.
0423  * @stable ICU 3.0
0424  */
0425 U_CAPI int32_t U_EXPORT2
0426 u_fsetlocale(UFILE      *file,
0427              const char *locale);
0428 
0429 #endif
0430 
0431 /**
0432  * Get the codepage in which data is written to and read from the UFILE.
0433  * This is the same codepage passed in the preceding call to 
0434  * <TT>u_fsetcodepage</TT> or <TT>u_fopen</TT>.
0435  * @param file The UFILE to query.
0436  * @return The codepage in which data is written to and read from the UFILE,
0437  * or NULL if an error occurred.
0438  * @stable ICU 3.0
0439  */
0440 U_CAPI const char* U_EXPORT2
0441 u_fgetcodepage(UFILE *file);
0442 
0443 /**
0444  * Set the codepage in which data will be written to and read from the UFILE.
0445  * All Unicode data written to the UFILE will be converted to this codepage
0446  * before it is written to the underlying FILE*. It it generally a bad idea to
0447  * mix codepages within a file. This should only be called right
0448  * after opening the <TT>UFile</TT>, or after calling <TT>u_frewind</TT>.
0449  * @param codepage The codepage in which data will be written to 
0450  * and read from the file. For example <TT>"latin-1"</TT> or <TT>"ibm-943"</TT>.
0451  * A value of NULL means the default codepage for the UFILE's current 
0452  * locale will be used.
0453  * @param file The UFILE to set.
0454  * @return 0 if successful, otherwise a negative number.
0455  * @see u_frewind
0456  * @stable ICU 3.0
0457  */
0458 U_CAPI int32_t U_EXPORT2
0459 u_fsetcodepage(const char   *codepage,
0460                UFILE        *file);
0461 
0462 
0463 /**
0464  * Returns an alias to the converter being used for this file.
0465  * @param f The UFILE to get the value from
0466  * @return alias to the converter (The converter <EM>must not</EM> be modified or closed)
0467  * @stable ICU 3.0
0468  */
0469 U_CAPI UConverter* U_EXPORT2 u_fgetConverter(UFILE *f);
0470 
0471 #if !UCONFIG_NO_FORMATTING
0472 /**
0473  * Returns an alias to the number formatter being used for this file.
0474  * @param f The UFILE to get the value from
0475  * @return alias to the number formatter (The formatter <EM>must not</EM> be modified or closed)
0476  * @stable ICU 51
0477 */
0478  U_CAPI const UNumberFormat* U_EXPORT2 u_fgetNumberFormat(UFILE *f);
0479 
0480 /* Output functions */
0481 
0482 /**
0483  * Write formatted data to <TT>stdout</TT>.
0484  * @param patternSpecification A pattern specifying how <TT>u_printf</TT> will
0485  * interpret the variable arguments received and format the data.
0486  * @return The number of Unicode characters written to <TT>stdout</TT>
0487  * @stable ICU 49
0488  */
0489 U_CAPI int32_t U_EXPORT2
0490 u_printf(const char *patternSpecification,
0491          ... );
0492 
0493 /**
0494  * Write formatted data to a UFILE.
0495  * @param f The UFILE to which to write.
0496  * @param patternSpecification A pattern specifying how <TT>u_fprintf</TT> will
0497  * interpret the variable arguments received and format the data.
0498  * @return The number of Unicode characters written to <TT>f</TT>.
0499  * @stable ICU 3.0
0500  */
0501 U_CAPI int32_t U_EXPORT2
0502 u_fprintf(UFILE         *f,
0503           const char    *patternSpecification,
0504           ... );
0505 
0506 /**
0507  * Write formatted data to a UFILE.
0508  * This is identical to <TT>u_fprintf</TT>, except that it will
0509  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
0510  * @param f The UFILE to which to write.
0511  * @param patternSpecification A pattern specifying how <TT>u_fprintf</TT> will
0512  * interpret the variable arguments received and format the data.
0513  * @param ap The argument list to use.
0514  * @return The number of Unicode characters written to <TT>f</TT>.
0515  * @see u_fprintf
0516  * @stable ICU 3.0
0517  */
0518 U_CAPI int32_t U_EXPORT2
0519 u_vfprintf(UFILE        *f,
0520            const char   *patternSpecification,
0521            va_list      ap);
0522 
0523 /**
0524  * Write formatted data to <TT>stdout</TT>.
0525  * @param patternSpecification A pattern specifying how <TT>u_printf_u</TT> will
0526  * interpret the variable arguments received and format the data.
0527  * @return The number of Unicode characters written to <TT>stdout</TT>
0528  * @stable ICU 49
0529  */
0530 U_CAPI int32_t U_EXPORT2
0531 u_printf_u(const UChar *patternSpecification,
0532            ... );
0533 
0534 /**
0535  * Get a UFILE for <TT>stdout</TT>.
0536  * @return UFILE that writes to <TT>stdout</TT>
0537  * @stable ICU 49
0538  */
0539 U_CAPI UFILE * U_EXPORT2
0540 u_get_stdout(void);
0541 
0542 /**
0543  * Write formatted data to a UFILE.
0544  * @param f The UFILE to which to write.
0545  * @param patternSpecification A pattern specifying how <TT>u_fprintf</TT> will
0546  * interpret the variable arguments received and format the data.
0547  * @return The number of Unicode characters written to <TT>f</TT>.
0548  * @stable ICU 3.0
0549  */
0550 U_CAPI int32_t U_EXPORT2
0551 u_fprintf_u(UFILE       *f,
0552             const UChar *patternSpecification,
0553             ... );
0554 
0555 /**
0556  * Write formatted data to a UFILE.
0557  * This is identical to <TT>u_fprintf_u</TT>, except that it will
0558  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
0559  * @param f The UFILE to which to write.
0560  * @param patternSpecification A pattern specifying how <TT>u_fprintf</TT> will
0561  * interpret the variable arguments received and format the data.
0562  * @param ap The argument list to use.
0563  * @return The number of Unicode characters written to <TT>f</TT>.
0564  * @see u_fprintf_u
0565  * @stable ICU 3.0
0566  */
0567 U_CAPI int32_t U_EXPORT2
0568 u_vfprintf_u(UFILE      *f,
0569             const UChar *patternSpecification,
0570             va_list     ap);
0571 #endif
0572 /**
0573  * Write a Unicode to a UFILE.  The null (U+0000) terminated UChar*
0574  * <TT>s</TT> will be written to <TT>f</TT>, excluding the NULL terminator.
0575  * A newline will be added to <TT>f</TT>.
0576  * @param s The UChar* to write.
0577  * @param f The UFILE to which to write.
0578  * @return A non-negative number if successful, EOF otherwise.
0579  * @see u_file_write
0580  * @stable ICU 3.0
0581  */
0582 U_CAPI int32_t U_EXPORT2
0583 u_fputs(const UChar *s,
0584         UFILE       *f);
0585 
0586 /**
0587  * Write a UChar to a UFILE.
0588  * @param uc The UChar to write.
0589  * @param f The UFILE to which to write.
0590  * @return The character written if successful, EOF otherwise.
0591  * @stable ICU 3.0
0592  */
0593 U_CAPI UChar32 U_EXPORT2
0594 u_fputc(UChar32  uc,
0595         UFILE  *f);
0596 
0597 /**
0598  * Write Unicode to a UFILE.
0599  * The ustring passed in will be converted to the UFILE's underlying
0600  * codepage before it is written.
0601  * @param ustring A pointer to the Unicode data to write.
0602  * @param count The number of Unicode characters to write
0603  * @param f The UFILE to which to write.
0604  * @return The number of Unicode characters written.
0605  * @see u_fputs
0606  * @stable ICU 3.0
0607  */
0608 U_CAPI int32_t U_EXPORT2
0609 u_file_write(const UChar    *ustring, 
0610              int32_t        count, 
0611              UFILE          *f);
0612 
0613 
0614 /* Input functions */
0615 #if !UCONFIG_NO_FORMATTING
0616 
0617 /**
0618  * Read formatted data from a UFILE.
0619  * @param f The UFILE from which to read.
0620  * @param patternSpecification A pattern specifying how <TT>u_fscanf</TT> will
0621  * interpret the variable arguments received and parse the data.
0622  * @return The number of items successfully converted and assigned, or EOF
0623  * if an error occurred.
0624  * @stable ICU 3.0
0625  */
0626 U_CAPI int32_t U_EXPORT2
0627 u_fscanf(UFILE      *f,
0628          const char *patternSpecification,
0629          ... );
0630 
0631 /**
0632  * Read formatted data from a UFILE.
0633  * This is identical to <TT>u_fscanf</TT>, except that it will
0634  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
0635  * @param f The UFILE from which to read.
0636  * @param patternSpecification A pattern specifying how <TT>u_fscanf</TT> will
0637  * interpret the variable arguments received and parse the data.
0638  * @param ap The argument list to use.
0639  * @return The number of items successfully converted and assigned, or EOF
0640  * if an error occurred.
0641  * @see u_fscanf
0642  * @stable ICU 3.0
0643  */
0644 U_CAPI int32_t U_EXPORT2
0645 u_vfscanf(UFILE         *f,
0646           const char    *patternSpecification,
0647           va_list        ap);
0648 
0649 /**
0650  * Read formatted data from a UFILE.
0651  * @param f The UFILE from which to read.
0652  * @param patternSpecification A pattern specifying how <TT>u_fscanf</TT> will
0653  * interpret the variable arguments received and parse the data.
0654  * @return The number of items successfully converted and assigned, or EOF
0655  * if an error occurred.
0656  * @stable ICU 3.0
0657  */
0658 U_CAPI int32_t U_EXPORT2
0659 u_fscanf_u(UFILE        *f,
0660            const UChar  *patternSpecification,
0661            ... );
0662 
0663 /**
0664  * Read formatted data from a UFILE.
0665  * This is identical to <TT>u_fscanf_u</TT>, except that it will
0666  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
0667  * @param f The UFILE from which to read.
0668  * @param patternSpecification A pattern specifying how <TT>u_fscanf</TT> will
0669  * interpret the variable arguments received and parse the data.
0670  * @param ap The argument list to use.
0671  * @return The number of items successfully converted and assigned, or EOF
0672  * if an error occurred.
0673  * @see u_fscanf_u
0674  * @stable ICU 3.0
0675  */
0676 U_CAPI int32_t U_EXPORT2
0677 u_vfscanf_u(UFILE       *f,
0678             const UChar *patternSpecification,
0679             va_list      ap);
0680 #endif
0681 
0682 /**
0683  * Read one line of text into a UChar* string from a UFILE. The newline
0684  * at the end of the line is read into the string. The string is always
0685  * null terminated
0686  * @param f The UFILE from which to read.
0687  * @param n The maximum number of characters - 1 to read.
0688  * @param s The UChar* to receive the read data.  Characters will be
0689  * stored successively in <TT>s</TT> until a newline or EOF is
0690  * reached. A null character (U+0000) will be appended to <TT>s</TT>.
0691  * @return A pointer to <TT>s</TT>, or NULL if no characters were available.
0692  * @stable ICU 3.0
0693  */
0694 U_CAPI UChar* U_EXPORT2
0695 u_fgets(UChar  *s,
0696         int32_t n,
0697         UFILE  *f);
0698 
0699 /**
0700  * Read a UChar from a UFILE. It is recommended that <TT>u_fgetcx</TT>
0701  * used instead for proper parsing functions, but sometimes reading
0702  * code units is needed instead of codepoints.
0703  *
0704  * @param f The UFILE from which to read.
0705  * @return The UChar value read, or U+FFFF if no character was available.
0706  * @stable ICU 3.0
0707  */
0708 U_CAPI UChar U_EXPORT2
0709 u_fgetc(UFILE   *f);
0710 
0711 /**
0712  * Read a UChar32 from a UFILE.
0713  *
0714  * @param f The UFILE from which to read.
0715  * @return The UChar32 value read, or U_EOF if no character was
0716  * available, or U+FFFFFFFF if an ill-formed character was
0717  * encountered.
0718  * @see u_unescape()
0719  * @stable ICU 3.0
0720  */
0721 U_CAPI UChar32 U_EXPORT2
0722 u_fgetcx(UFILE  *f);
0723 
0724 /**
0725  * Unget a UChar from a UFILE.
0726  * If this function is not the first to operate on <TT>f</TT> after a call
0727  * to <TT>u_fgetc</TT>, the results are undefined.
0728  * If this function is passed a character that was not received from the
0729  * previous <TT>u_fgetc</TT> or <TT>u_fgetcx</TT> call, the results are undefined.
0730  * @param c The UChar to put back on the stream.
0731  * @param f The UFILE to receive <TT>c</TT>.
0732  * @return The UChar32 value put back if successful, U_EOF otherwise.
0733  * @stable ICU 3.0
0734  */
0735 U_CAPI UChar32 U_EXPORT2
0736 u_fungetc(UChar32   c,
0737       UFILE        *f);
0738 
0739 /**
0740  * Read Unicode from a UFILE.
0741  * Bytes will be converted from the UFILE's underlying codepage, with
0742  * subsequent conversion to Unicode. The data will not be NULL terminated.
0743  * @param chars A pointer to receive the Unicode data.
0744  * @param count The number of Unicode characters to read.
0745  * @param f The UFILE from which to read.
0746  * @return The number of Unicode characters read.
0747  * @stable ICU 3.0
0748  */
0749 U_CAPI int32_t U_EXPORT2
0750 u_file_read(UChar        *chars, 
0751         int32_t        count, 
0752         UFILE         *f);
0753 
0754 #if !UCONFIG_NO_TRANSLITERATION
0755 
0756 /**
0757  * Set a transliterator on the UFILE. The transliterator will be owned by the
0758  * UFILE. 
0759  * @param file The UFILE to set transliteration on
0760  * @param adopt The UTransliterator to set. Can be NULL, which will
0761  * mean that no transliteration is used.
0762  * @param direction either U_READ, U_WRITE, or U_READWRITE - sets
0763  *  which direction the transliterator is to be applied to. If
0764  * U_READWRITE, the "Read" transliteration will be in the inverse
0765  * direction.
0766  * @param status ICU error code.
0767  * @return The previously set transliterator, owned by the
0768  * caller. If U_READWRITE is specified, only the WRITE transliterator
0769  * is returned. In most cases, the caller should call utrans_close()
0770  * on the result of this function.
0771  * @stable ICU 3.0
0772  */
0773 U_CAPI UTransliterator* U_EXPORT2
0774 u_fsettransliterator(UFILE *file, UFileDirection direction,
0775                      UTransliterator *adopt, UErrorCode *status);
0776 
0777 #endif
0778 
0779 
0780 /* Output string functions */
0781 #if !UCONFIG_NO_FORMATTING
0782 
0783 
0784 /**
0785  * Write formatted data to a Unicode string.
0786  *
0787  * @param buffer The Unicode String to which to write.
0788  * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will
0789  * interpret the variable arguments received and format the data.
0790  * @return The number of Unicode code units written to <TT>buffer</TT>. This
0791  * does not include the terminating null character.
0792  * @stable ICU 3.0
0793  */
0794 U_CAPI int32_t U_EXPORT2
0795 u_sprintf(UChar       *buffer,
0796         const char    *patternSpecification,
0797         ... );
0798 
0799 /**
0800  * Write formatted data to a Unicode string. When the number of code units
0801  * required to store the data exceeds <TT>count</TT>, then <TT>count</TT> code
0802  * units of data are stored in <TT>buffer</TT> and a negative value is
0803  * returned. When the number of code units required to store the data equals
0804  * <TT>count</TT>, the string is not null terminated and <TT>count</TT> is
0805  * returned.
0806  *
0807  * @param buffer The Unicode String to which to write.
0808  * @param count The number of code units to read.
0809  * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will
0810  * interpret the variable arguments received and format the data.
0811  * @return The number of Unicode characters that would have been written to
0812  * <TT>buffer</TT> had count been sufficiently large. This does not include
0813  * the terminating null character.
0814  * @stable ICU 3.0
0815  */
0816 U_CAPI int32_t U_EXPORT2
0817 u_snprintf(UChar      *buffer,
0818         int32_t       count,
0819         const char    *patternSpecification,
0820         ... );
0821 
0822 /**
0823  * Write formatted data to a Unicode string.
0824  * This is identical to <TT>u_sprintf</TT>, except that it will
0825  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
0826  *
0827  * @param buffer The Unicode string to which to write.
0828  * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will
0829  * interpret the variable arguments received and format the data.
0830  * @param ap The argument list to use.
0831  * @return The number of Unicode characters written to <TT>buffer</TT>.
0832  * @see u_sprintf
0833  * @stable ICU 3.0
0834  */
0835 U_CAPI int32_t U_EXPORT2
0836 u_vsprintf(UChar      *buffer,
0837         const char    *patternSpecification,
0838         va_list        ap);
0839 
0840 /**
0841  * Write formatted data to a Unicode string.
0842  * This is identical to <TT>u_snprintf</TT>, except that it will
0843  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.<br><br>
0844  * When the number of code units required to store the data exceeds
0845  * <TT>count</TT>, then <TT>count</TT> code units of data are stored in
0846  * <TT>buffer</TT> and a negative value is returned. When the number of code
0847  * units required to store the data equals <TT>count</TT>, the string is not
0848  * null terminated and <TT>count</TT> is returned.
0849  *
0850  * @param buffer The Unicode string to which to write.
0851  * @param count The number of code units to read.
0852  * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will
0853  * interpret the variable arguments received and format the data.
0854  * @param ap The argument list to use.
0855  * @return The number of Unicode characters that would have been written to
0856  * <TT>buffer</TT> had count been sufficiently large.
0857  * @see u_sprintf
0858  * @stable ICU 3.0
0859  */
0860 U_CAPI int32_t U_EXPORT2
0861 u_vsnprintf(UChar     *buffer,
0862         int32_t       count,
0863         const char    *patternSpecification,
0864         va_list        ap);
0865 
0866 /**
0867  * Write formatted data to a Unicode string.
0868  *
0869  * @param buffer The Unicode string to which to write.
0870  * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will
0871  * interpret the variable arguments received and format the data.
0872  * @return The number of Unicode characters written to <TT>buffer</TT>.
0873  * @stable ICU 3.0
0874  */
0875 U_CAPI int32_t U_EXPORT2
0876 u_sprintf_u(UChar      *buffer,
0877         const UChar    *patternSpecification,
0878         ... );
0879 
0880 /**
0881  * Write formatted data to a Unicode string. When the number of code units
0882  * required to store the data exceeds <TT>count</TT>, then <TT>count</TT> code
0883  * units of data are stored in <TT>buffer</TT> and a negative value is
0884  * returned. When the number of code units required to store the data equals
0885  * <TT>count</TT>, the string is not null terminated and <TT>count</TT> is
0886  * returned.
0887  *
0888  * @param buffer The Unicode string to which to write.
0889  * @param count The number of code units to read.
0890  * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will
0891  * interpret the variable arguments received and format the data.
0892  * @return The number of Unicode characters that would have been written to
0893  * <TT>buffer</TT> had count been sufficiently large.
0894  * @stable ICU 3.0
0895  */
0896 U_CAPI int32_t U_EXPORT2
0897 u_snprintf_u(UChar     *buffer,
0898         int32_t        count,
0899         const UChar    *patternSpecification,
0900         ... );
0901 
0902 /**
0903  * Write formatted data to a Unicode string.
0904  * This is identical to <TT>u_sprintf_u</TT>, except that it will
0905  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
0906  *
0907  * @param buffer The Unicode string to which to write.
0908  * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will
0909  * interpret the variable arguments received and format the data.
0910  * @param ap The argument list to use.
0911  * @return The number of Unicode characters written to <TT>f</TT>.
0912  * @see u_sprintf_u
0913  * @stable ICU 3.0
0914  */
0915 U_CAPI int32_t U_EXPORT2
0916 u_vsprintf_u(UChar     *buffer,
0917         const UChar    *patternSpecification,
0918         va_list        ap);
0919 
0920 /**
0921  * Write formatted data to a Unicode string.
0922  * This is identical to <TT>u_snprintf_u</TT>, except that it will
0923  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
0924  * When the number of code units required to store the data exceeds
0925  * <TT>count</TT>, then <TT>count</TT> code units of data are stored in
0926  * <TT>buffer</TT> and a negative value is returned. When the number of code
0927  * units required to store the data equals <TT>count</TT>, the string is not
0928  * null terminated and <TT>count</TT> is returned.
0929  *
0930  * @param buffer The Unicode string to which to write.
0931  * @param count The number of code units to read.
0932  * @param patternSpecification A pattern specifying how <TT>u_sprintf</TT> will
0933  * interpret the variable arguments received and format the data.
0934  * @param ap The argument list to use.
0935  * @return The number of Unicode characters that would have been written to
0936  * <TT>f</TT> had count been sufficiently large.
0937  * @see u_sprintf_u
0938  * @stable ICU 3.0
0939  */
0940 U_CAPI int32_t U_EXPORT2
0941 u_vsnprintf_u(UChar *buffer,
0942         int32_t         count,
0943         const UChar     *patternSpecification,
0944         va_list         ap);
0945 
0946 /* Input string functions */
0947 
0948 /**
0949  * Read formatted data from a Unicode string.
0950  *
0951  * @param buffer The Unicode string from which to read.
0952  * @param patternSpecification A pattern specifying how <TT>u_sscanf</TT> will
0953  * interpret the variable arguments received and parse the data.
0954  * @return The number of items successfully converted and assigned, or EOF
0955  * if an error occurred.
0956  * @stable ICU 3.0
0957  */
0958 U_CAPI int32_t U_EXPORT2
0959 u_sscanf(const UChar   *buffer,
0960         const char     *patternSpecification,
0961         ... );
0962 
0963 /**
0964  * Read formatted data from a Unicode string.
0965  * This is identical to <TT>u_sscanf</TT>, except that it will
0966  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
0967  *
0968  * @param buffer The Unicode string from which to read.
0969  * @param patternSpecification A pattern specifying how <TT>u_sscanf</TT> will
0970  * interpret the variable arguments received and parse the data.
0971  * @param ap The argument list to use.
0972  * @return The number of items successfully converted and assigned, or EOF
0973  * if an error occurred.
0974  * @see u_sscanf
0975  * @stable ICU 3.0
0976  */
0977 U_CAPI int32_t U_EXPORT2
0978 u_vsscanf(const UChar  *buffer,
0979         const char     *patternSpecification,
0980         va_list        ap);
0981 
0982 /**
0983  * Read formatted data from a Unicode string.
0984  *
0985  * @param buffer The Unicode string from which to read.
0986  * @param patternSpecification A pattern specifying how <TT>u_sscanf</TT> will
0987  * interpret the variable arguments received and parse the data.
0988  * @return The number of items successfully converted and assigned, or EOF
0989  * if an error occurred.
0990  * @stable ICU 3.0
0991  */
0992 U_CAPI int32_t U_EXPORT2
0993 u_sscanf_u(const UChar  *buffer,
0994         const UChar     *patternSpecification,
0995         ... );
0996 
0997 /**
0998  * Read formatted data from a Unicode string.
0999  * This is identical to <TT>u_sscanf_u</TT>, except that it will
1000  * <EM>not</EM> call <TT>va_start</TT> and <TT>va_end</TT>.
1001  *
1002  * @param buffer The Unicode string from which to read.
1003  * @param patternSpecification A pattern specifying how <TT>u_sscanf</TT> will
1004  * interpret the variable arguments received and parse the data.
1005  * @param ap The argument list to use.
1006  * @return The number of items successfully converted and assigned, or EOF
1007  * if an error occurred.
1008  * @see u_sscanf_u
1009  * @stable ICU 3.0
1010  */
1011 U_CAPI int32_t U_EXPORT2
1012 u_vsscanf_u(const UChar *buffer,
1013         const UChar     *patternSpecification,
1014         va_list         ap);
1015 
1016 
1017 #endif
1018 #endif
1019 #endif
1020 
1021