1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 4 ****************************************************************************** 6 * Copyright (C) 1998-2015, International Business Machines 7 * Corporation and others. All Rights Reserved. 9 ****************************************************************************** 13 * Modification History: 15 * Date Name Description 16 * 10/16/98 stephen Creation. 17 * 11/06/98 stephen Modified per code review. 18 * 03/12/99 stephen Modified for new C API. 19 * 07/19/99 stephen Minor doc update. 20 * 02/01/01 george Added sprintf & sscanf with all of its variants 21 ****************************************************************************** 35 #if U_SHOW_CPLUSPLUS_API 37 #endif// U_SHOW_CPLUSPLUS_API 39 #if !UCONFIG_NO_CONVERSION 43 The following is a small list as to what is currently wrong/suggestions for 46 * Make sure that * in the scanf format specification works for all formats. 47 * Each UFILE takes up at least 2KB. 48 Look into adding setvbuf() for configurable buffers. 49 * This library does buffering. The OS should do this for us already. Check on 50 this, and remove it from this library, if this is the case. Double buffering 51 wastes a lot of time and space. 52 * Test stdin and stdout with the u_f* functions 53 * Testing should be done for reading and writing multi-byte encodings, 54 and make sure that a character that is contained across buffer boundaries 55 works even for incomplete characters. 56 * Make sure that the last character is flushed when the file/string is closed. 57 * snprintf should follow the C99 standard for the return value, which is 58 return the number of characters (excluding the trailing '\0') 59 which would have been written to the destination string regardless 60 of available space. This is like pre-flighting. 61 * Everything that uses %s should do what operator>> does for UnicodeString. 62 It should convert one byte at a time, and once a character is 63 converted then check to see if it's whitespace or in the scanset. 64 If it's whitespace or in the scanset, put all the bytes back (do nothing 66 * If bad string data is encountered, make sure that the function fails 67 without memory leaks and the unconvertable characters are valid 68 substitution or are escaped characters. 69 * u_fungetc() can't unget a character when it's at the beginning of the 70 internal conversion buffer. For example, read the buffer size # of 71 characters, and then ungetc to get the previous character that was 72 at the end of the last buffer. 73 * u_fflush() and u_fclose should return an int32_t like C99 functions. 74 0 is returned if the operation was successful and EOF otherwise. 75 * u_fsettransliterator does not support U_READ side of transliteration. 76 * The format specifier should limit the size of a format or honor it in 77 order to prevent buffer overruns. (e.g. %256.256d). 78 * u_fread and u_fwrite don't exist. They're needed for reading and writing 79 data structures without any conversion. 80 * u_file_read and u_file_write are used for writing strings. u_fgets and 81 u_fputs or u_fread and u_fwrite should be used to do this. 82 * The width parameter for all scanf formats, including scanset, needs 83 better testing. This prevents buffer overflows. 84 * Figure out what is suppose to happen when a codepage is changed midstream. 85 Maybe a flush or a rewind are good enough. 86 * Make sure that a UFile opened with "rw" can be used after using 87 u_fflush with a u_frewind. 88 * scanf(%i) should detect what type of number to use. 89 * Add more testing of the alternate format, %# 90 * Look at newline handling of fputs/puts 91 * Think more about codeunit/codepoint error handling/support in %S,%s,%C,%c,%[] 92 * Complete the file documentation with proper doxygen formatting. 93 See http://oss.software.ibm.com/pipermail/icu/2003-July/005647.html 225 U_READWRITE =3
/* == (U_READ | U_WRITE) */ 249 constchar *codepage);
272 constchar *codepage);
293 constchar *codepage);
314 constchar *codepage);
344 #if U_SHOW_CPLUSPLUS_API 404 #if !UCONFIG_NO_FORMATTING 414 U_CAPIconstchar* U_EXPORT2
440 U_CAPIconstchar* U_EXPORT2
471 #if !UCONFIG_NO_FORMATTING 480 /* Output functions */ 503 constchar *patternSpecification,
520 constchar *patternSpecification,
552 constUChar *patternSpecification,
569 constUChar *patternSpecification,
614 /* Input functions */ 615 #if !UCONFIG_NO_FORMATTING 628 constchar *patternSpecification,
646 constchar *patternSpecification,
660 constUChar *patternSpecification,
678 constUChar *patternSpecification,
754 #if !UCONFIG_NO_TRANSLITERATION 780 /* Output string functions */ 781 #if !UCONFIG_NO_FORMATTING 796 constchar *patternSpecification,
819 constchar *patternSpecification,
837 constchar *patternSpecification,
863 constchar *patternSpecification,
877 constUChar *patternSpecification,
899 constUChar *patternSpecification,
917 constUChar *patternSpecification,
943 constUChar *patternSpecification,
946 /* Input string functions */ 960 constchar *patternSpecification,
979 constchar *patternSpecification,
994 constUChar *patternSpecification,
1013 constUChar *patternSpecification,
"Smart pointer" class, closes a UFILE via u_fclose().
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
C API: Character conversion.
struct UConverter UConverter
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
int8_t UBool
The ICU boolean type, a signed-byte integer.
#define U_CAPI
This is used to declare a function as a public ICU C API.
char16_t UChar
The base type for UTF-16 code units and pointers.
C API: Compatibility APIs for number formatting.
void * UNumberFormat
A number formatter.
U_CAPI int32_t u_vfprintf_u(UFILE *f, const UChar *patternSpecification, va_list ap)
Write formatted data to a UFILE.
U_CAPI UFILE * u_fopen_u(const UChar *filename, const char *perm, const char *locale, const char *codepage)
Open a UFILE with a UChar* filename A UFILE is a wrapper around a FILE* that is locale and codepage a...
U_CAPI UBool u_feof(UFILE *f)
Tests if the UFILE is at the end of the file stream.
U_CAPI int32_t u_fscanf_u(UFILE *f, const UChar *patternSpecification,...)
Read formatted data from a UFILE.
U_CAPI int32_t u_vfprintf(UFILE *f, const char *patternSpecification, va_list ap)
Write formatted data to a UFILE.
U_CAPI UChar u_fgetc(UFILE *f)
Read a UChar from a UFILE.
U_CAPI const char * u_fgetcodepage(UFILE *file)
Get the codepage in which data is written to and read from the UFILE.
U_CAPI int32_t u_file_write(const UChar *ustring, int32_t count, UFILE *f)
Write Unicode to a UFILE.
U_CAPI void u_fflush(UFILE *file)
Flush output of a UFILE.
U_CAPI int32_t u_vfscanf_u(UFILE *f, const UChar *patternSpecification, va_list ap)
Read formatted data from a UFILE.
U_CAPI UFILE * u_fopen(const char *filename, const char *perm, const char *locale, const char *codepage)
Open a UFILE.
U_CAPI int32_t u_vsnprintf_u(UChar *buffer, int32_t count, const UChar *patternSpecification, va_list ap)
Write formatted data to a Unicode string.
U_CAPI const UNumberFormat * u_fgetNumberFormat(UFILE *f)
Returns an alias to the number formatter being used for this file.
U_CAPI int32_t u_fprintf_u(UFILE *f, const UChar *patternSpecification,...)
Write formatted data to a UFILE.
U_CAPI void u_frewind(UFILE *file)
Rewind the file pointer to the beginning of the file.
U_CAPI FILE * u_fgetfile(UFILE *f)
Get the FILE* associated with a UFILE.
U_CAPI void u_fclose(UFILE *file)
Close a UFILE.
U_CAPI UConverter * u_fgetConverter(UFILE *f)
Returns an alias to the converter being used for this file.
U_CAPI int32_t u_fsetcodepage(const char *codepage, UFILE *file)
Set the codepage in which data will be written to and read from the UFILE.
U_CAPI UTransliterator * u_fsettransliterator(UFILE *file, UFileDirection direction, UTransliterator *adopt, UErrorCode *status)
Set a transliterator on the UFILE.
U_CAPI int32_t u_fsetlocale(UFILE *file, const char *locale)
Set the locale whose conventions will be used to format and parse output.
U_CAPI int32_t u_printf_u(const UChar *patternSpecification,...)
Write formatted data to stdout.
U_CAPI int32_t u_printf(const char *patternSpecification,...)
Write formatted data to stdout.
U_CAPI int32_t u_sprintf(UChar *buffer, const char *patternSpecification,...)
Write formatted data to a Unicode string.
U_CAPI int32_t u_fscanf(UFILE *f, const char *patternSpecification,...)
Read formatted data from a UFILE.
U_CAPI const char * u_fgetlocale(UFILE *file)
Get the locale whose conventions are used to format and parse output.
U_CAPI int32_t u_sscanf(const UChar *buffer, const char *patternSpecification,...)
Read formatted data from a Unicode string.
U_CAPI UFILE * u_finit(FILE *f, const char *locale, const char *codepage)
Open a UFILE on top of an existing FILE* stream.
U_CAPI UFILE * u_fstropen(UChar *stringBuf, int32_t capacity, const char *locale)
Create a UFILE that can be used for localized formatting or parsing.
U_CAPI int32_t u_fputs(const UChar *s, UFILE *f)
Write a Unicode to a UFILE.
U_CAPI int32_t u_file_read(UChar *chars, int32_t count, UFILE *f)
Read Unicode from a UFILE.
U_CAPI UFILE * u_fadopt(FILE *f, const char *locale, const char *codepage)
Open a UFILE on top of an existing FILE* stream.
U_CAPI int32_t u_vsprintf_u(UChar *buffer, const UChar *patternSpecification, va_list ap)
Write formatted data to a Unicode string.
U_CAPI int32_t u_snprintf_u(UChar *buffer, int32_t count, const UChar *patternSpecification,...)
Write formatted data to a Unicode string.
U_CAPI UChar32 u_fungetc(UChar32 c, UFILE *f)
Unget a UChar from a UFILE.
UFileDirection
Enum for which direction of stream a transliterator applies to.
U_CAPI int32_t u_vsscanf(const UChar *buffer, const char *patternSpecification, va_list ap)
Read formatted data from a Unicode string.
U_CAPI UChar32 u_fputc(UChar32 uc, UFILE *f)
Write a UChar to a UFILE.
U_CAPI int32_t u_snprintf(UChar *buffer, int32_t count, const char *patternSpecification,...)
Write formatted data to a Unicode string.
U_CAPI UChar * u_fgets(UChar *s, int32_t n, UFILE *f)
Read one line of text into a UChar* string from a UFILE.
U_CAPI int32_t u_sscanf_u(const UChar *buffer, const UChar *patternSpecification,...)
Read formatted data from a Unicode string.
U_CAPI UFILE * u_get_stdout(void)
Get a UFILE for stdout.
U_CAPI int32_t u_sprintf_u(UChar *buffer, const UChar *patternSpecification,...)
Write formatted data to a Unicode string.
U_CAPI int32_t u_fprintf(UFILE *f, const char *patternSpecification,...)
Write formatted data to a UFILE.
U_CAPI UChar32 u_fgetcx(UFILE *f)
Read a UChar32 from a UFILE.
U_CAPI int32_t u_vsnprintf(UChar *buffer, int32_t count, const char *patternSpecification, va_list ap)
Write formatted data to a Unicode string.
struct UFILE UFILE
Forward declaration of a Unicode-aware file.
U_CAPI int32_t u_vsprintf(UChar *buffer, const char *patternSpecification, va_list ap)
Write formatted data to a Unicode string.
U_CAPI int32_t u_vsscanf_u(const UChar *buffer, const UChar *patternSpecification, va_list ap)
Read formatted data from a Unicode string.
U_CAPI int32_t u_vfscanf(UFILE *f, const char *patternSpecification, va_list ap)
Read formatted data from a UFILE.
void * UTransliterator
An opaque transliterator for use in C.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.