jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * jpayne@69: * Copyright (C) 2008-2011, International Business Machines jpayne@69: * Corporation, Google and others. All Rights Reserved. jpayne@69: * jpayne@69: ******************************************************************************* jpayne@69: */ jpayne@69: /* jpayne@69: * Author : eldawy@google.com (Mohamed Eldawy) jpayne@69: * ucnvsel.h jpayne@69: * jpayne@69: * Purpose: To generate a list of encodings capable of handling jpayne@69: * a given Unicode text jpayne@69: * jpayne@69: * Started 09-April-2008 jpayne@69: */ jpayne@69: jpayne@69: #ifndef __ICU_UCNV_SEL_H__ jpayne@69: #define __ICU_UCNV_SEL_H__ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if !UCONFIG_NO_CONVERSION jpayne@69: jpayne@69: #include "unicode/uset.h" jpayne@69: #include "unicode/utf16.h" jpayne@69: #include "unicode/uenum.h" jpayne@69: #include "unicode/ucnv.h" jpayne@69: #include "unicode/localpointer.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * jpayne@69: * A converter selector is built with a set of encoding/charset names jpayne@69: * and given an input string returns the set of names of the jpayne@69: * corresponding converters which can convert the string. jpayne@69: * jpayne@69: * A converter selector can be serialized into a buffer and reopened jpayne@69: * from the serialized form. jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * @{ jpayne@69: * The selector data structure jpayne@69: */ jpayne@69: struct UConverterSelector; jpayne@69: typedef struct UConverterSelector UConverterSelector; jpayne@69: /** @} */ jpayne@69: jpayne@69: /** jpayne@69: * Open a selector. jpayne@69: * If converterListSize is 0, build for all available converters. jpayne@69: * If excludedCodePoints is NULL, don't exclude any code points. jpayne@69: * jpayne@69: * @param converterList a pointer to encoding names needed to be involved. jpayne@69: * Can be NULL if converterListSize==0. jpayne@69: * The list and the names will be cloned, and the caller jpayne@69: * retains ownership of the original. jpayne@69: * @param converterListSize number of encodings in above list. jpayne@69: * If 0, builds a selector for all available converters. jpayne@69: * @param excludedCodePoints a set of code points to be excluded from consideration. jpayne@69: * That is, excluded code points in a string do not change jpayne@69: * the selection result. (They might be handled by a callback.) jpayne@69: * Use NULL to exclude nothing. jpayne@69: * @param whichSet what converter set to use? Use this to determine whether jpayne@69: * to consider only roundtrip mappings or also fallbacks. jpayne@69: * @param status an in/out ICU UErrorCode jpayne@69: * @return the new selector jpayne@69: * jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: U_STABLE UConverterSelector* U_EXPORT2 jpayne@69: ucnvsel_open(const char* const* converterList, int32_t converterListSize, jpayne@69: const USet* excludedCodePoints, jpayne@69: const UConverterUnicodeSet whichSet, UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Closes a selector. jpayne@69: * If any Enumerations were returned by ucnv_select*, they become invalid. jpayne@69: * They can be closed before or after calling ucnv_closeSelector, jpayne@69: * but should never be used after the selector is closed. jpayne@69: * jpayne@69: * @see ucnv_selectForString jpayne@69: * @see ucnv_selectForUTF8 jpayne@69: * jpayne@69: * @param sel selector to close jpayne@69: * jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnvsel_close(UConverterSelector *sel); jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \class LocalUConverterSelectorPointer jpayne@69: * "Smart pointer" class, closes a UConverterSelector via ucnvsel_close(). jpayne@69: * For most methods see the LocalPointerBase base class. jpayne@69: * jpayne@69: * @see LocalPointerBase jpayne@69: * @see LocalPointer jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: U_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterSelectorPointer, UConverterSelector, ucnvsel_close); jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Open a selector from its serialized form. jpayne@69: * The buffer must remain valid and unchanged for the lifetime of the selector. jpayne@69: * This is much faster than creating a selector from scratch. jpayne@69: * Using a serialized form from a different machine (endianness/charset) is supported. jpayne@69: * jpayne@69: * @param buffer pointer to the serialized form of a converter selector; jpayne@69: * must be 32-bit-aligned jpayne@69: * @param length the capacity of this buffer (can be equal to or larger than jpayne@69: * the actual data length) jpayne@69: * @param status an in/out ICU UErrorCode jpayne@69: * @return the new selector jpayne@69: * jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: U_STABLE UConverterSelector* U_EXPORT2 jpayne@69: ucnvsel_openFromSerialized(const void* buffer, int32_t length, UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Serialize a selector into a linear buffer. jpayne@69: * The serialized form is portable to different machines. jpayne@69: * jpayne@69: * @param sel selector to consider jpayne@69: * @param buffer pointer to 32-bit-aligned memory to be filled with the jpayne@69: * serialized form of this converter selector jpayne@69: * @param bufferCapacity the capacity of this buffer jpayne@69: * @param status an in/out ICU UErrorCode jpayne@69: * @return the required buffer capacity to hold serialize data (even if the call fails jpayne@69: * with a U_BUFFER_OVERFLOW_ERROR, it will return the required capacity) jpayne@69: * jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucnvsel_serialize(const UConverterSelector* sel, jpayne@69: void* buffer, int32_t bufferCapacity, UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Select converters that can map all characters in a UTF-16 string, jpayne@69: * ignoring the excluded code points. jpayne@69: * jpayne@69: * @param sel a selector jpayne@69: * @param s UTF-16 string jpayne@69: * @param length length of the string, or -1 if NUL-terminated jpayne@69: * @param status an in/out ICU UErrorCode jpayne@69: * @return an enumeration containing encoding names. jpayne@69: * The returned encoding names and their order will be the same as jpayne@69: * supplied when building the selector. jpayne@69: * jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: U_STABLE UEnumeration * U_EXPORT2 jpayne@69: ucnvsel_selectForString(const UConverterSelector* sel, jpayne@69: const UChar *s, int32_t length, UErrorCode *status); jpayne@69: jpayne@69: /** jpayne@69: * Select converters that can map all characters in a UTF-8 string, jpayne@69: * ignoring the excluded code points. jpayne@69: * jpayne@69: * @param sel a selector jpayne@69: * @param s UTF-8 string jpayne@69: * @param length length of the string, or -1 if NUL-terminated jpayne@69: * @param status an in/out ICU UErrorCode jpayne@69: * @return an enumeration containing encoding names. jpayne@69: * The returned encoding names and their order will be the same as jpayne@69: * supplied when building the selector. jpayne@69: * jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: U_STABLE UEnumeration * U_EXPORT2 jpayne@69: ucnvsel_selectForUTF8(const UConverterSelector* sel, jpayne@69: const char *s, int32_t length, UErrorCode *status); jpayne@69: jpayne@69: #endif /* !UCONFIG_NO_CONVERSION */ jpayne@69: jpayne@69: #endif /* __ICU_UCNV_SEL_H__ */