xref: /aosp_15_r20/external/icu/libicu/cts_headers/ucnv_imp.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker **********************************************************************
5*0e209d39SAndroid Build Coastguard Worker *   Copyright (C) 1999-2011, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker *   Corporation and others.  All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker **********************************************************************
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker *
10*0e209d39SAndroid Build Coastguard Worker *  ucnv_imp.h:
11*0e209d39SAndroid Build Coastguard Worker *  Contains all internal and external data structure definitions
12*0e209d39SAndroid Build Coastguard Worker * Created & Maintained by Bertrand A. Damiba
13*0e209d39SAndroid Build Coastguard Worker *
14*0e209d39SAndroid Build Coastguard Worker *
15*0e209d39SAndroid Build Coastguard Worker *
16*0e209d39SAndroid Build Coastguard Worker * ATTENTION:
17*0e209d39SAndroid Build Coastguard Worker * ---------
18*0e209d39SAndroid Build Coastguard Worker * Although the data structures in this file are open and stack allocatable
19*0e209d39SAndroid Build Coastguard Worker * we reserve the right to hide them in further releases.
20*0e209d39SAndroid Build Coastguard Worker */
21*0e209d39SAndroid Build Coastguard Worker 
22*0e209d39SAndroid Build Coastguard Worker #ifndef UCNV_IMP_H
23*0e209d39SAndroid Build Coastguard Worker #define UCNV_IMP_H
24*0e209d39SAndroid Build Coastguard Worker 
25*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
26*0e209d39SAndroid Build Coastguard Worker 
27*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_CONVERSION
28*0e209d39SAndroid Build Coastguard Worker 
29*0e209d39SAndroid Build Coastguard Worker #include "unicode/uloc.h"
30*0e209d39SAndroid Build Coastguard Worker #include "ucnv_bld.h"
31*0e209d39SAndroid Build Coastguard Worker 
32*0e209d39SAndroid Build Coastguard Worker /*
33*0e209d39SAndroid Build Coastguard Worker  * Fast check for whether a charset name is "UTF-8".
34*0e209d39SAndroid Build Coastguard Worker  * This does not recognize all of the variations that ucnv_open()
35*0e209d39SAndroid Build Coastguard Worker  * and other functions recognize, but it covers most cases.
36*0e209d39SAndroid Build Coastguard Worker  * @param name const char * charset name
37*0e209d39SAndroid Build Coastguard Worker  * @return
38*0e209d39SAndroid Build Coastguard Worker  */
39*0e209d39SAndroid Build Coastguard Worker #define UCNV_FAST_IS_UTF8(name) \
40*0e209d39SAndroid Build Coastguard Worker     (((name[0]=='U' ? \
41*0e209d39SAndroid Build Coastguard Worker       (                name[1]=='T' && name[2]=='F') : \
42*0e209d39SAndroid Build Coastguard Worker       (name[0]=='u' && name[1]=='t' && name[2]=='f'))) \
43*0e209d39SAndroid Build Coastguard Worker   && (name[3]=='-' ? \
44*0e209d39SAndroid Build Coastguard Worker      (name[4]=='8' && name[5]==0) : \
45*0e209d39SAndroid Build Coastguard Worker      (name[3]=='8' && name[4]==0)))
46*0e209d39SAndroid Build Coastguard Worker 
47*0e209d39SAndroid Build Coastguard Worker typedef struct {
48*0e209d39SAndroid Build Coastguard Worker     char cnvName[UCNV_MAX_CONVERTER_NAME_LENGTH];
49*0e209d39SAndroid Build Coastguard Worker     char locale[ULOC_FULLNAME_CAPACITY];
50*0e209d39SAndroid Build Coastguard Worker     uint32_t options;
51*0e209d39SAndroid Build Coastguard Worker } UConverterNamePieces;
52*0e209d39SAndroid Build Coastguard Worker 
53*0e209d39SAndroid Build Coastguard Worker U_CFUNC UBool
54*0e209d39SAndroid Build Coastguard Worker ucnv_canCreateConverter(const char *converterName, UErrorCode *err);
55*0e209d39SAndroid Build Coastguard Worker 
56*0e209d39SAndroid Build Coastguard Worker /* figures out if we need to go to file to read in the data tables.
57*0e209d39SAndroid Build Coastguard Worker  * @param converterName The name of the converter
58*0e209d39SAndroid Build Coastguard Worker  * @param err The error code
59*0e209d39SAndroid Build Coastguard Worker  * @return the newly created converter
60*0e209d39SAndroid Build Coastguard Worker  */
61*0e209d39SAndroid Build Coastguard Worker U_CAPI UConverter *
62*0e209d39SAndroid Build Coastguard Worker ucnv_createConverter(UConverter *myUConverter, const char *converterName, UErrorCode * err);
63*0e209d39SAndroid Build Coastguard Worker 
64*0e209d39SAndroid Build Coastguard Worker /*
65*0e209d39SAndroid Build Coastguard Worker  * Open a purely algorithmic converter, specified by a type constant.
66*0e209d39SAndroid Build Coastguard Worker  * @param myUConverter  NULL, or pre-allocated UConverter structure to avoid
67*0e209d39SAndroid Build Coastguard Worker  *                      a memory allocation
68*0e209d39SAndroid Build Coastguard Worker  * @param type          requested converter type
69*0e209d39SAndroid Build Coastguard Worker  * @param locale        locale parameter, or ""
70*0e209d39SAndroid Build Coastguard Worker  * @param options       converter options bit set (default 0)
71*0e209d39SAndroid Build Coastguard Worker  * @param err           ICU error code, not tested for U_FAILURE on input
72*0e209d39SAndroid Build Coastguard Worker  *                      because this is an internal function
73*0e209d39SAndroid Build Coastguard Worker  * @internal
74*0e209d39SAndroid Build Coastguard Worker  */
75*0e209d39SAndroid Build Coastguard Worker U_CFUNC UConverter *
76*0e209d39SAndroid Build Coastguard Worker ucnv_createAlgorithmicConverter(UConverter *myUConverter,
77*0e209d39SAndroid Build Coastguard Worker                                 UConverterType type,
78*0e209d39SAndroid Build Coastguard Worker                                 const char *locale, uint32_t options,
79*0e209d39SAndroid Build Coastguard Worker                                 UErrorCode *err);
80*0e209d39SAndroid Build Coastguard Worker 
81*0e209d39SAndroid Build Coastguard Worker /*
82*0e209d39SAndroid Build Coastguard Worker  * Creates a converter from shared data.
83*0e209d39SAndroid Build Coastguard Worker  * Adopts mySharedConverterData: No matter what happens, the caller must not
84*0e209d39SAndroid Build Coastguard Worker  * unload mySharedConverterData, except via ucnv_close(return value)
85*0e209d39SAndroid Build Coastguard Worker  * if this function is successful.
86*0e209d39SAndroid Build Coastguard Worker  */
87*0e209d39SAndroid Build Coastguard Worker U_CFUNC UConverter *
88*0e209d39SAndroid Build Coastguard Worker ucnv_createConverterFromSharedData(UConverter *myUConverter,
89*0e209d39SAndroid Build Coastguard Worker                                    UConverterSharedData *mySharedConverterData,
90*0e209d39SAndroid Build Coastguard Worker                                    UConverterLoadArgs *pArgs,
91*0e209d39SAndroid Build Coastguard Worker                                    UErrorCode *err);
92*0e209d39SAndroid Build Coastguard Worker 
93*0e209d39SAndroid Build Coastguard Worker U_CFUNC UConverter *
94*0e209d39SAndroid Build Coastguard Worker ucnv_createConverterFromPackage(const char *packageName, const char *converterName, UErrorCode *err);
95*0e209d39SAndroid Build Coastguard Worker 
96*0e209d39SAndroid Build Coastguard Worker /**
97*0e209d39SAndroid Build Coastguard Worker  * Load a converter but do not create a UConverter object.
98*0e209d39SAndroid Build Coastguard Worker  * Simply return the UConverterSharedData.
99*0e209d39SAndroid Build Coastguard Worker  * Performs alias lookup etc.
100*0e209d39SAndroid Build Coastguard Worker  * The UConverterNamePieces need not be initialized
101*0e209d39SAndroid Build Coastguard Worker  * before calling this function.
102*0e209d39SAndroid Build Coastguard Worker  * The UConverterLoadArgs must be initialized
103*0e209d39SAndroid Build Coastguard Worker  * before calling this function.
104*0e209d39SAndroid Build Coastguard Worker  * If the args are passed in, then the pieces must be passed in too.
105*0e209d39SAndroid Build Coastguard Worker  * In other words, the following combinations are allowed:
106*0e209d39SAndroid Build Coastguard Worker  * - pieces==NULL && args==NULL
107*0e209d39SAndroid Build Coastguard Worker  * - pieces!=NULL && args==NULL
108*0e209d39SAndroid Build Coastguard Worker  * - pieces!=NULL && args!=NULL
109*0e209d39SAndroid Build Coastguard Worker  * @internal
110*0e209d39SAndroid Build Coastguard Worker  */
111*0e209d39SAndroid Build Coastguard Worker U_CFUNC UConverterSharedData *
112*0e209d39SAndroid Build Coastguard Worker ucnv_loadSharedData(const char *converterName,
113*0e209d39SAndroid Build Coastguard Worker                     UConverterNamePieces *pieces,
114*0e209d39SAndroid Build Coastguard Worker                     UConverterLoadArgs *pArgs,
115*0e209d39SAndroid Build Coastguard Worker                     UErrorCode * err);
116*0e209d39SAndroid Build Coastguard Worker 
117*0e209d39SAndroid Build Coastguard Worker /**
118*0e209d39SAndroid Build Coastguard Worker  * This may unload the shared data in a thread safe manner.
119*0e209d39SAndroid Build Coastguard Worker  * This will only unload the data if no other converters are sharing it.
120*0e209d39SAndroid Build Coastguard Worker  */
121*0e209d39SAndroid Build Coastguard Worker U_CFUNC void
122*0e209d39SAndroid Build Coastguard Worker ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData);
123*0e209d39SAndroid Build Coastguard Worker 
124*0e209d39SAndroid Build Coastguard Worker /**
125*0e209d39SAndroid Build Coastguard Worker  * This is a thread safe way to increment the reference count.
126*0e209d39SAndroid Build Coastguard Worker  */
127*0e209d39SAndroid Build Coastguard Worker U_CFUNC void
128*0e209d39SAndroid Build Coastguard Worker ucnv_incrementRefCount(UConverterSharedData *sharedData);
129*0e209d39SAndroid Build Coastguard Worker 
130*0e209d39SAndroid Build Coastguard Worker /**
131*0e209d39SAndroid Build Coastguard Worker  * These are the default error handling callbacks for the charset conversion framework.
132*0e209d39SAndroid Build Coastguard Worker  * For performance reasons, they are only called to handle an error (not normally called for a reset or close).
133*0e209d39SAndroid Build Coastguard Worker  */
134*0e209d39SAndroid Build Coastguard Worker #define UCNV_TO_U_DEFAULT_CALLBACK ((UConverterToUCallback) UCNV_TO_U_CALLBACK_SUBSTITUTE)
135*0e209d39SAndroid Build Coastguard Worker #define UCNV_FROM_U_DEFAULT_CALLBACK ((UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE)
136*0e209d39SAndroid Build Coastguard Worker 
137*0e209d39SAndroid Build Coastguard Worker #endif
138*0e209d39SAndroid Build Coastguard Worker 
139*0e209d39SAndroid Build Coastguard Worker #endif /* _UCNV_IMP */
140