Imported Upstream version 58.1
[platform/upstream/icu.git] / source / io / ufile.h
1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4  *******************************************************************************
5  *
6  *   Copyright (C) 1998-2014, International Business Machines
7  *   Corporation and others.  All Rights Reserved.
8  *
9  *******************************************************************************
10  *
11  * File ufile.h
12  *
13  * Modification History:
14  *
15  *   Date        Name        Description
16  *   12/01/98    stephen        Creation.
17  *   03/12/99    stephen     Modified for new C API.
18  *******************************************************************************
19  */
20
21 #ifndef UFILE_H
22 #define UFILE_H
23
24 #include "unicode/utypes.h"
25
26 #if !UCONFIG_NO_CONVERSION
27
28 #include "unicode/ucnv.h"
29 #include "unicode/utrans.h"
30 #include "locbund.h"
31
32 /* The buffer size for fromUnicode calls */
33 #define UFILE_CHARBUFFER_SIZE 1024
34
35 /* The buffer size for toUnicode calls */
36 #define UFILE_UCHARBUFFER_SIZE 1024
37
38 /* A UFILE */
39
40 #if !UCONFIG_NO_TRANSLITERATION
41
42 typedef struct {
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;
49
50 #endif
51
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 */
56
57 #if !UCONFIG_NO_FORMATTING
58     ULocaleBundle  fBundle; /* formatters */
59 #endif
60 } u_localized_string;
61
62 struct UFILE {
63 #if !UCONFIG_NO_TRANSLITERATION
64     UFILETranslitBuffer *fTranslit;
65 #endif
66
67     FILE        *fFile;         /* the actual filesystem interface */
68
69     UConverter  *fConverter;    /* for codeset conversion */
70
71     u_localized_string str;     /* struct to handle strings for number formatting */
72
73     UChar       fUCBuffer[UFILE_UCHARBUFFER_SIZE];/* buffer used for toUnicode */
74
75     UBool       fOwnFile;       /* TRUE if fFile should be closed */
76
77     int32_t     fFileno;        /* File number. Useful to determine if it's stdin. */
78 };
79
80 /**
81  * Like u_file_write but takes a flush parameter
82  */
83 U_CFUNC int32_t U_EXPORT2
84 u_file_write_flush( const UChar     *chars, 
85         int32_t     count, 
86         UFILE       *f,
87         UBool       flushIO,
88         UBool       flushTranslit);
89
90 /**
91  * Fill a UFILE's buffer with converted codepage data.
92  * @param f The UFILE containing the buffer to fill.
93  */
94 void
95 ufile_fill_uchar_buffer(UFILE *f);
96
97 /**
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
102  */
103 U_CFUNC UBool U_EXPORT2
104 ufile_getch(UFILE *f, UChar *ch);
105
106 /**
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
111  */
112 U_CFUNC UBool U_EXPORT2
113 ufile_getch32(UFILE *f, UChar32 *ch);
114
115 /**
116  * Close out the transliterator and flush any data therein.
117  * @param f flu
118  */
119 void 
120 ufile_close_translit(UFILE *f);
121
122 /**
123  * Flush the buffer in the transliterator 
124  * @param f UFile to flush
125  */
126 void 
127 ufile_flush_translit(UFILE *f);
128
129 /**
130  * Flush the IO buffer
131  * @param f UFile to flush
132  */
133 void 
134 ufile_flush_io(UFILE *f);
135
136
137 #endif
138 #endif