1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 1998-2014, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
13 * Modification History:
15 * Date Name Description
16 * 12/01/98 stephen Creation.
17 * 03/12/99 stephen Modified for new C API.
18 *******************************************************************************
24 #include "unicode/utypes.h"
26 #if !UCONFIG_NO_CONVERSION
28 #include "unicode/ucnv.h"
29 #include "unicode/utrans.h"
32 /* The buffer size for fromUnicode calls */
33 #define UFILE_CHARBUFFER_SIZE 1024
35 /* The buffer size for toUnicode calls */
36 #define UFILE_UCHARBUFFER_SIZE 1024
40 #if !UCONFIG_NO_TRANSLITERATION
43 UChar *buffer; /* Beginning of buffer */
44 int32_t capacity; /* Capacity of buffer */
45 int32_t pos; /* Beginning of untranslitted data */
46 int32_t length; /* Length *from beginning of buffer* of untranslitted data */
47 UTransliterator *translit;
48 } UFILETranslitBuffer;
52 typedef struct u_localized_string {
53 UChar *fPos; /* current pos in fUCBuffer */
54 const UChar *fLimit; /* data limit in fUCBuffer */
55 UChar *fBuffer; /* Place to write the string */
57 #if !UCONFIG_NO_FORMATTING
58 ULocaleBundle fBundle; /* formatters */
63 #if !UCONFIG_NO_TRANSLITERATION
64 UFILETranslitBuffer *fTranslit;
67 FILE *fFile; /* the actual filesystem interface */
69 UConverter *fConverter; /* for codeset conversion */
71 u_localized_string str; /* struct to handle strings for number formatting */
73 UChar fUCBuffer[UFILE_UCHARBUFFER_SIZE];/* buffer used for toUnicode */
75 UBool fOwnFile; /* TRUE if fFile should be closed */
77 int32_t fFileno; /* File number. Useful to determine if it's stdin. */
81 * Like u_file_write but takes a flush parameter
83 U_CFUNC int32_t U_EXPORT2
84 u_file_write_flush( const UChar *chars,
91 * Fill a UFILE's buffer with converted codepage data.
92 * @param f The UFILE containing the buffer to fill.
95 ufile_fill_uchar_buffer(UFILE *f);
98 * Get one code unit and detect whether the end of file has been reached.
99 * @param f The UFILE containing the characters.
100 * @param ch The read in character
101 * @return TRUE if the character is valid, or FALSE when EOF has been detected
103 U_CFUNC UBool U_EXPORT2
104 ufile_getch(UFILE *f, UChar *ch);
107 * Get one character and detect whether the end of file has been reached.
108 * @param f The UFILE containing the characters.
109 * @param ch The read in character
110 * @return TRUE if the character is valid, or FALSE when EOF has been detected
112 U_CFUNC UBool U_EXPORT2
113 ufile_getch32(UFILE *f, UChar32 *ch);
116 * Close out the transliterator and flush any data therein.
120 ufile_close_translit(UFILE *f);
123 * Flush the buffer in the transliterator
124 * @param f UFile to flush
127 ufile_flush_translit(UFILE *f);
130 * Flush the IO buffer
131 * @param f UFile to flush
134 ufile_flush_io(UFILE *f);