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