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