+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
-* Copyright (C) 1999-2004, International Business Machines
+* Copyright (C) 1999-2015 International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*
#include "unicode/ucnv.h"
#include "unicode/ucnv_err.h"
+#include "unicode/utf16.h"
#include "ucnv_cnv.h"
#include "ucnvmbcs.h"
#include "ucnv_ext.h"
#define UCNV_OPTION_VERSION 0xf
#define UCNV_OPTION_SWAP_LFNL 0x10
+#define UCNV_GET_VERSION(cnv) ((cnv)->options&UCNV_OPTION_VERSION)
U_CDECL_BEGIN /* We must declare the following as 'extern "C"' so that if ucnv
itself is compiled under C++, the linkage of the funcptrs will
*/
struct UConverterSharedData {
uint32_t structSize; /* Size of this structure */
- uint32_t referenceCounter; /* used to count number of clients, 0xffffffff for static SharedData */
+ uint32_t referenceCounter; /* used to count number of clients, unused for static/immutable SharedData */
const void *dataMemory; /* from udata_openChoice() - for cleanup */
- void *table; /* Unused. This used to be a UConverterTable - Pointer to conversion data - see mbcs below */
const UConverterStaticData *staticData; /* pointer to the static (non changing) data. */
UBool sharedDataCached; /* TRUE: shared data is in cache, don't destroy on ucnv_close() if 0 ref. FALSE: shared data isn't in the cache, do attempt to clean it up if the ref is 0 */
- /*UBool staticDataOwned; TRUE if static data owned by shared data & should be freed with it, NEVER true for udata() loaded statics. This ignored variable was removed to make space for sharedDataCached. */
+ /** If FALSE, then referenceCounter is not used. Must not change after initialization. */
+ UBool isReferenceCounted;
const UConverterImpl *impl; /* vtable-style struct of mostly function pointers */
* which always has a UConverterMBCSTable
*
* To eliminate one allocation, I am making the UConverterMBCSTable
- * a member of the shared data. It is the last member so that static
- * definitions of UConverterSharedData work as before.
- * The table field above also remains to avoid updating all static
- * definitions, but is now unused.
+ * a member of the shared data.
*
* markus 2003-nov-07
*/
UConverterMBCSTable mbcs;
};
+/** UConverterSharedData initializer for static, non-reference-counted converters. */
+#define UCNV_IMMUTABLE_SHARED_DATA_INITIALIZER(pStaticData, pImpl) \
+ { \
+ sizeof(UConverterSharedData), ~((uint32_t)0), \
+ NULL, pStaticData, FALSE, FALSE, pImpl, \
+ 0, UCNV_MBCS_TABLE_INITIALIZER \
+ }
+
/* Defines a UConverter, the lightweight mutable part the user sees */
struct UConverter {
const void *fromUContext;
const void *toUContext;
+ /*
+ * Pointer to charset bytes for substitution string if subCharLen>0,
+ * or pointer to Unicode string (UChar *) if subCharLen<0.
+ * subCharLen==0 is equivalent to using a skip callback.
+ * If the pointer is !=subUChars then it is allocated with
+ * UCNV_ERROR_BUFFER_LENGTH * U_SIZEOF_UCHAR bytes.
+ * The subUChars field is declared as UChar[] not uint8_t[] to
+ * guarantee alignment for UChars.
+ */
+ uint8_t *subChars;
+
UConverterSharedData *sharedData; /* Pointer to the shared immutable part of the converter object */
uint32_t options; /* options flags from UConverterOpen, may contain additional bits */
uint8_t subChar1; /* single-byte substitution character if different from subChar */
UBool useSubChar1;
- uint8_t subChar[UCNV_MAX_SUBCHAR_LEN]; /* codepage specific character sequence */
char invalidCharBuffer[UCNV_MAX_CHAR_LEN]; /* bytes from last error/callback situation */
uint8_t charErrorBuffer[UCNV_ERROR_BUFFER_LENGTH]; /* codepage output from Error functions */
+ UChar subUChars[UCNV_MAX_SUBCHAR_LEN/U_SIZEOF_UCHAR]; /* see subChars documentation */
UChar invalidUCharBuffer[U16_MAX_LENGTH]; /* UChars from last error/callback situation */
UChar UCharErrorBuffer[UCNV_ERROR_BUFFER_LENGTH]; /* unicode output from Error functions */
char preToU[UCNV_EXT_MAX_BYTES];
int8_t preFromULength, preToULength; /* negative: replay */
int8_t preToUFirstLength; /* length of first character */
+
+ /* new fields for ICU 4.0 */
+ UConverterCallbackReason toUCallbackReason; /* (*fromCharErrorBehaviour) reason, set when error is detected */
};
U_CDECL_END /* end of UConverter */
#define CONVERTER_FILE_EXTENSION ".cnv"
+
+/**
+ * Return the number of all converter names.
+ * @param pErrorCode The error code
+ * @return the number of all converter names
+ */
+U_CFUNC uint16_t
+ucnv_bld_countAvailableConverters(UErrorCode *pErrorCode);
+
+/**
+ * Return the (n)th converter name in mixed case, or NULL
+ * if there is none (typically, if the data cannot be loaded).
+ * 0<=index<ucnv_io_countAvailableConverters().
+ * @param n The number specifies which converter name to get
+ * @param pErrorCode The error code
+ * @return the (n)th converter name in mixed case, or NULL if there is none.
+ */
+U_CFUNC const char *
+ucnv_bld_getAvailableConverter(uint16_t n, UErrorCode *pErrorCode);
+
/**
* Load a non-algorithmic converter.
* If pkg==NULL, then this function must be called inside umtx_lock(&cnvCacheMutex).
*/
-UConverterSharedData *
+U_CAPI UConverterSharedData *
ucnv_load(UConverterLoadArgs *pArgs, UErrorCode *err);
/**
* Unload a non-algorithmic converter.
- * It must be sharedData->referenceCounter != ~0
+ * It must be sharedData->isReferenceCounted
* and this function must be called inside umtx_lock(&cnvCacheMutex).
*/
-void
+U_CAPI void
ucnv_unload(UConverterSharedData *sharedData);
/**
const void *inData, int32_t length, void *outData,
UErrorCode *pErrorCode);
+U_CAPI void U_EXPORT2
+ucnv_enableCleanup();
+
#endif
#endif /* _UCNV_BLD */