1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru********************************************************************** 385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho* Copyright (C) 1999-2009, International Business Machines 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Corporation and others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru********************************************************************** 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* ucnv_imp.h: 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Contains all internal and external data structure definitions 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Created & Maitained by Bertrand A. Damiba 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* ATTENTION: 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* --------- 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Although the data structures in this file are open and stack allocatable 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* we reserve the right to hide them in further releases. 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef UCNV_IMP_H 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_IMP_H 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_CONVERSION 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uloc.h" 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ucnv_bld.h" 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 3085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/* 3185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Fast check for whether a charset name is "UTF-8". 3285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * This does not recognize all of the variations that ucnv_open() 3385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * and other functions recognize, but it covers most cases. 3485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * @param name const char * charset name 3585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * @return 3685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */ 3785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define UCNV_FAST_IS_UTF8(name) \ 3885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho (((name[0]=='U' ? \ 3985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ( name[1]=='T' && name[2]=='F') : \ 4085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho (name[0]=='u' && name[1]=='t' && name[2]=='f'))) \ 4185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho && (name[3]=='-' ? \ 4285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho (name[4]=='8' && name[5]==0) : \ 4385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho (name[3]=='8' && name[4]==0))) 4485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 4585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hotypedef struct { 4685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char cnvName[UCNV_MAX_CONVERTER_NAME_LENGTH]; 4785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char locale[ULOC_FULLNAME_CAPACITY]; 4885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uint32_t options; 4985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} UConverterNamePieces; 5085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 5185bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoU_CFUNC UBool 5285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Houcnv_canCreateConverter(const char *converterName, UErrorCode *err); 5385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* figures out if we need to go to file to read in the data tables. 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param converterName The name of the converter 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param err The error code 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return the newly created converter 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUConverter *ucnv_createConverter (UConverter *myUConverter, const char *converterName, UErrorCode * err); 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Open a purely algorithmic converter, specified by a type constant. 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param myUConverter NULL, or pre-allocated UConverter structure to avoid 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * a memory allocation 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param type requested converter type 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param locale locale parameter, or "" 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param options converter options bit set (default 0) 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param err ICU error code, not tested for U_FAILURE on input 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * because this is an internal function 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @internal 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC UConverter * 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruucnv_createAlgorithmicConverter(UConverter *myUConverter, 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UConverterType type, 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *locale, uint32_t options, 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode *err); 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 7885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/* 7985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Creates a converter from shared data. 8085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Adopts mySharedConverterData: No matter what happens, the caller must not 8185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * unload mySharedConverterData, except via ucnv_close(return value) 8285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * if this function is successful. 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUConverter* 8585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Houcnv_createConverterFromSharedData(UConverter *myUConverter, 8685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UConverterSharedData *mySharedConverterData, 8785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UConverterLoadArgs *pArgs, 8885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode *err); 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUConverter* ucnv_createConverterFromPackage(const char *packageName, const char *converterName, 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode *err); 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Load a converter but do not create a UConverter object. 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Simply return the UConverterSharedData. 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Performs alias lookup etc. 9785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * The UConverterNamePieces need not be initialized 9885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * before calling this function. 9985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * The UConverterLoadArgs must be initialized 10085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * before calling this function. 10185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * If the args are passed in, then the pieces must be passed in too. 10285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * In other words, the following combinations are allowed: 10385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * - pieces==NULL && args==NULL 10485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * - pieces!=NULL && args==NULL 10585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * - pieces!=NULL && args!=NULL 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @internal 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUConverterSharedData * 10985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Houcnv_loadSharedData(const char *converterName, 11085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UConverterNamePieces *pieces, 11185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UConverterLoadArgs *pArgs, 11285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode * err); 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This may unload the shared data in a thread safe manner. 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This will only unload the data if no other converters are sharing it. 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData); 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This is a thread safe way to increment the reference count. 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruucnv_incrementRefCount(UConverterSharedData *sharedData); 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 12785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/** 12885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * These are the default error handling callbacks for the charset conversion framework. 12985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * For performance reasons, they are only called to handle an error (not normally called for a reset or close). 13085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */ 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_TO_U_DEFAULT_CALLBACK ((UConverterToUCallback) UCNV_TO_U_CALLBACK_SUBSTITUTE) 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UCNV_FROM_U_DEFAULT_CALLBACK ((UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE) 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* _UCNV_IMP */ 137