ucnvsel.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. *
  6. * Copyright (C) 2008-2011, International Business Machines
  7. * Corporation, Google and others. All Rights Reserved.
  8. *
  9. *******************************************************************************
  10. */
  11. /*
  12. * Author : eldawy@google.com (Mohamed Eldawy)
  13. * ucnvsel.h
  14. *
  15. * Purpose: To generate a list of encodings capable of handling
  16. * a given Unicode text
  17. *
  18. * Started 09-April-2008
  19. */
  20. #ifndef __ICU_UCNV_SEL_H__
  21. #define __ICU_UCNV_SEL_H__
  22. #include "unicode/utypes.h"
  23. #if !UCONFIG_NO_CONVERSION
  24. #include "unicode/uset.h"
  25. #include "unicode/utf16.h"
  26. #include "unicode/uenum.h"
  27. #include "unicode/ucnv.h"
  28. #if U_SHOW_CPLUSPLUS_API
  29. #include "unicode/localpointer.h"
  30. #endif // U_SHOW_CPLUSPLUS_API
  31. /**
  32. * \file
  33. * \brief C API: Encoding/charset encoding selector
  34. *
  35. * A converter selector is built with a set of encoding/charset names
  36. * and given an input string returns the set of names of the
  37. * corresponding converters which can convert the string.
  38. *
  39. * A converter selector can be serialized into a buffer and reopened
  40. * from the serialized form.
  41. */
  42. struct UConverterSelector;
  43. /**
  44. * @{
  45. * Typedef for selector data structure.
  46. */
  47. typedef struct UConverterSelector UConverterSelector;
  48. /** @} */
  49. /**
  50. * Open a selector.
  51. * If converterListSize is 0, build for all available converters.
  52. * If excludedCodePoints is NULL, don't exclude any code points.
  53. *
  54. * @param converterList a pointer to encoding names needed to be involved.
  55. * Can be NULL if converterListSize==0.
  56. * The list and the names will be cloned, and the caller
  57. * retains ownership of the original.
  58. * @param converterListSize number of encodings in above list.
  59. * If 0, builds a selector for all available converters.
  60. * @param excludedCodePoints a set of code points to be excluded from consideration.
  61. * That is, excluded code points in a string do not change
  62. * the selection result. (They might be handled by a callback.)
  63. * Use NULL to exclude nothing.
  64. * @param whichSet what converter set to use? Use this to determine whether
  65. * to consider only roundtrip mappings or also fallbacks.
  66. * @param status an in/out ICU UErrorCode
  67. * @return the new selector
  68. *
  69. * @stable ICU 4.2
  70. */
  71. U_CAPI UConverterSelector* U_EXPORT2
  72. ucnvsel_open(const char* const* converterList, int32_t converterListSize,
  73. const USet* excludedCodePoints,
  74. const UConverterUnicodeSet whichSet, UErrorCode* status);
  75. /**
  76. * Closes a selector.
  77. * If any Enumerations were returned by ucnv_select*, they become invalid.
  78. * They can be closed before or after calling ucnv_closeSelector,
  79. * but should never be used after the selector is closed.
  80. *
  81. * @see ucnv_selectForString
  82. * @see ucnv_selectForUTF8
  83. *
  84. * @param sel selector to close
  85. *
  86. * @stable ICU 4.2
  87. */
  88. U_CAPI void U_EXPORT2
  89. ucnvsel_close(UConverterSelector *sel);
  90. #if U_SHOW_CPLUSPLUS_API
  91. U_NAMESPACE_BEGIN
  92. /**
  93. * \class LocalUConverterSelectorPointer
  94. * "Smart pointer" class, closes a UConverterSelector via ucnvsel_close().
  95. * For most methods see the LocalPointerBase base class.
  96. *
  97. * @see LocalPointerBase
  98. * @see LocalPointer
  99. * @stable ICU 4.4
  100. */
  101. U_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterSelectorPointer, UConverterSelector, ucnvsel_close);
  102. U_NAMESPACE_END
  103. #endif
  104. /**
  105. * Open a selector from its serialized form.
  106. * The buffer must remain valid and unchanged for the lifetime of the selector.
  107. * This is much faster than creating a selector from scratch.
  108. * Using a serialized form from a different machine (endianness/charset) is supported.
  109. *
  110. * @param buffer pointer to the serialized form of a converter selector;
  111. * must be 32-bit-aligned
  112. * @param length the capacity of this buffer (can be equal to or larger than
  113. * the actual data length)
  114. * @param status an in/out ICU UErrorCode
  115. * @return the new selector
  116. *
  117. * @stable ICU 4.2
  118. */
  119. U_CAPI UConverterSelector* U_EXPORT2
  120. ucnvsel_openFromSerialized(const void* buffer, int32_t length, UErrorCode* status);
  121. /**
  122. * Serialize a selector into a linear buffer.
  123. * The serialized form is portable to different machines.
  124. *
  125. * @param sel selector to consider
  126. * @param buffer pointer to 32-bit-aligned memory to be filled with the
  127. * serialized form of this converter selector
  128. * @param bufferCapacity the capacity of this buffer
  129. * @param status an in/out ICU UErrorCode
  130. * @return the required buffer capacity to hold serialize data (even if the call fails
  131. * with a U_BUFFER_OVERFLOW_ERROR, it will return the required capacity)
  132. *
  133. * @stable ICU 4.2
  134. */
  135. U_CAPI int32_t U_EXPORT2
  136. ucnvsel_serialize(const UConverterSelector* sel,
  137. void* buffer, int32_t bufferCapacity, UErrorCode* status);
  138. /**
  139. * Select converters that can map all characters in a UTF-16 string,
  140. * ignoring the excluded code points.
  141. *
  142. * @param sel a selector
  143. * @param s UTF-16 string
  144. * @param length length of the string, or -1 if NUL-terminated
  145. * @param status an in/out ICU UErrorCode
  146. * @return an enumeration containing encoding names.
  147. * The returned encoding names and their order will be the same as
  148. * supplied when building the selector.
  149. *
  150. * @stable ICU 4.2
  151. */
  152. U_CAPI UEnumeration * U_EXPORT2
  153. ucnvsel_selectForString(const UConverterSelector* sel,
  154. const UChar *s, int32_t length, UErrorCode *status);
  155. /**
  156. * Select converters that can map all characters in a UTF-8 string,
  157. * ignoring the excluded code points.
  158. *
  159. * @param sel a selector
  160. * @param s UTF-8 string
  161. * @param length length of the string, or -1 if NUL-terminated
  162. * @param status an in/out ICU UErrorCode
  163. * @return an enumeration containing encoding names.
  164. * The returned encoding names and their order will be the same as
  165. * supplied when building the selector.
  166. *
  167. * @stable ICU 4.2
  168. */
  169. U_CAPI UEnumeration * U_EXPORT2
  170. ucnvsel_selectForUTF8(const UConverterSelector* sel,
  171. const char *s, int32_t length, UErrorCode *status);
  172. #endif /* !UCONFIG_NO_CONVERSION */
  173. #endif /* __ICU_UCNV_SEL_H__ */