aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/io/ufile.h
blob: 88fa40911e499f49e681b48309650ee5668dad38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
 *******************************************************************************
 *
 *   Copyright (C) 1998-2014, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *
 * File ufile.h
 *
 * Modification History:
 *
 *   Date        Name        Description
 *   12/01/98    stephen        Creation.
 *   03/12/99    stephen     Modified for new C API.
 *******************************************************************************
 */

#ifndef UFILE_H
#define UFILE_H

#include "unicode/utypes.h"

#if !UCONFIG_NO_CONVERSION

#include <stdio.h>

#include "unicode/ucnv.h"
#include "unicode/utrans.h"
#include "locbund.h"

/* The buffer size for fromUnicode calls */
#define UFILE_CHARBUFFER_SIZE 1024

/* The buffer size for toUnicode calls */
#define UFILE_UCHARBUFFER_SIZE 1024

/* A UFILE */

#if !UCONFIG_NO_TRANSLITERATION

typedef struct {
    UChar  *buffer;             /* Beginning of buffer */
    int32_t capacity;           /* Capacity of buffer */
    int32_t pos;                /* Beginning of untranslitted data */
    int32_t length;             /* Length *from beginning of buffer* of untranslitted data */
    UTransliterator *translit;
} UFILETranslitBuffer;

#endif

typedef struct u_localized_string {
    UChar       *fPos;          /* current pos in fUCBuffer */
    const UChar *fLimit;        /* data limit in fUCBuffer */
    UChar       *fBuffer;       /* Place to write the string */

#if !UCONFIG_NO_FORMATTING
    ULocaleBundle  fBundle; /* formatters */
#endif
} u_localized_string;

struct UFILE {
#if !UCONFIG_NO_TRANSLITERATION
    UFILETranslitBuffer *fTranslit;
#endif

    FILE        *fFile;         /* the actual filesystem interface */

    UConverter  *fConverter;    /* for codeset conversion */

    u_localized_string str;     /* struct to handle strings for number formatting */

    UChar       fUCBuffer[UFILE_UCHARBUFFER_SIZE];/* buffer used for toUnicode */

    UBool       fOwnFile;       /* true if fFile should be closed */

    int32_t     fFileno;        /* File number. Useful to determine if it's stdin. */
};

/**
 * Like u_file_write but takes a flush parameter
 */
U_CFUNC int32_t U_EXPORT2
u_file_write_flush( const UChar     *chars, 
        int32_t     count, 
        UFILE       *f,
        UBool       flushIO,
        UBool       flushTranslit);

/**
 * Fill a UFILE's buffer with converted codepage data.
 * @param f The UFILE containing the buffer to fill.
 */
void
ufile_fill_uchar_buffer(UFILE *f);

/**
 * Get one code unit and detect whether the end of file has been reached.
 * @param f The UFILE containing the characters.
 * @param ch The read in character
 * @return true if the character is valid, or false when EOF has been detected
 */
U_CFUNC UBool U_EXPORT2
ufile_getch(UFILE *f, UChar *ch);

/**
 * Get one character and detect whether the end of file has been reached.
 * @param f The UFILE containing the characters.
 * @param ch The read in character
 * @return true if the character is valid, or false when EOF has been detected
 */
U_CFUNC UBool U_EXPORT2
ufile_getch32(UFILE *f, UChar32 *ch);

/**
 * Close out the transliterator and flush any data therein.
 * @param f flu
 */
void 
ufile_close_translit(UFILE *f);

/**
 * Flush the buffer in the transliterator 
 * @param f UFile to flush
 */
void 
ufile_flush_translit(UFILE *f);

/**
 * Flush the IO buffer
 * @param f UFile to flush
 */
void 
ufile_flush_io(UFILE *f);


#endif
#endif