ucnv.h 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043
  1. // Copyright (C) 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 1999-2014, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. * ucnv.h:
  9. * External APIs for the ICU's codeset conversion library
  10. * Bertrand A. Damiba
  11. *
  12. * Modification History:
  13. *
  14. * Date Name Description
  15. * 04/04/99 helena Fixed internal header inclusion.
  16. * 05/11/00 helena Added setFallback and usesFallback APIs.
  17. * 06/29/2000 helena Major rewrite of the callback APIs.
  18. * 12/07/2000 srl Update of documentation
  19. */
  20. /**
  21. * \file
  22. * \brief C API: Character conversion
  23. *
  24. * <h2>Character Conversion C API</h2>
  25. *
  26. * <p>This API is used to convert codepage or character encoded data to and
  27. * from UTF-16. You can open a converter with {@link ucnv_open() }. With that
  28. * converter, you can get its properties, set options, convert your data and
  29. * close the converter.</p>
  30. *
  31. * <p>Since many software programs recogize different converter names for
  32. * different types of converters, there are other functions in this API to
  33. * iterate over the converter aliases. The functions {@link ucnv_getAvailableName() },
  34. * {@link ucnv_getAlias() } and {@link ucnv_getStandardName() } are some of the
  35. * more frequently used alias functions to get this information.</p>
  36. *
  37. * <p>When a converter encounters an illegal, irregular, invalid or unmappable character
  38. * its default behavior is to use a substitution character to replace the
  39. * bad byte sequence. This behavior can be changed by using {@link ucnv_setFromUCallBack() }
  40. * or {@link ucnv_setToUCallBack() } on the converter. The header ucnv_err.h defines
  41. * many other callback actions that can be used instead of a character substitution.</p>
  42. *
  43. * <p>More information about this API can be found in our
  44. * <a href="http://icu-project.org/userguide/conversion.html">User's
  45. * Guide</a>.</p>
  46. */
  47. #ifndef UCNV_H
  48. #define UCNV_H
  49. #include "unicode/ucnv_err.h"
  50. #include "unicode/uenum.h"
  51. #include "unicode/localpointer.h"
  52. #ifndef __USET_H__
  53. /**
  54. * USet is the C API type for Unicode sets.
  55. * It is forward-declared here to avoid including the header file if related
  56. * conversion APIs are not used.
  57. * See unicode/uset.h
  58. *
  59. * @see ucnv_getUnicodeSet
  60. * @stable ICU 2.6
  61. */
  62. struct USet;
  63. /** @stable ICU 2.6 */
  64. typedef struct USet USet;
  65. #endif
  66. #if !UCONFIG_NO_CONVERSION
  67. U_CDECL_BEGIN
  68. /** Maximum length of a converter name including the terminating NULL @stable ICU 2.0 */
  69. #define UCNV_MAX_CONVERTER_NAME_LENGTH 60
  70. /** Maximum length of a converter name including path and terminating NULL @stable ICU 2.0 */
  71. #define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH)
  72. /** Shift in for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */
  73. #define UCNV_SI 0x0F
  74. /** Shift out for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */
  75. #define UCNV_SO 0x0E
  76. /**
  77. * Enum for specifying basic types of converters
  78. * @see ucnv_getType
  79. * @stable ICU 2.0
  80. */
  81. typedef enum {
  82. /** @stable ICU 2.0 */
  83. UCNV_UNSUPPORTED_CONVERTER = -1,
  84. /** @stable ICU 2.0 */
  85. UCNV_SBCS = 0,
  86. /** @stable ICU 2.0 */
  87. UCNV_DBCS = 1,
  88. /** @stable ICU 2.0 */
  89. UCNV_MBCS = 2,
  90. /** @stable ICU 2.0 */
  91. UCNV_LATIN_1 = 3,
  92. /** @stable ICU 2.0 */
  93. UCNV_UTF8 = 4,
  94. /** @stable ICU 2.0 */
  95. UCNV_UTF16_BigEndian = 5,
  96. /** @stable ICU 2.0 */
  97. UCNV_UTF16_LittleEndian = 6,
  98. /** @stable ICU 2.0 */
  99. UCNV_UTF32_BigEndian = 7,
  100. /** @stable ICU 2.0 */
  101. UCNV_UTF32_LittleEndian = 8,
  102. /** @stable ICU 2.0 */
  103. UCNV_EBCDIC_STATEFUL = 9,
  104. /** @stable ICU 2.0 */
  105. UCNV_ISO_2022 = 10,
  106. /** @stable ICU 2.0 */
  107. UCNV_LMBCS_1 = 11,
  108. /** @stable ICU 2.0 */
  109. UCNV_LMBCS_2,
  110. /** @stable ICU 2.0 */
  111. UCNV_LMBCS_3,
  112. /** @stable ICU 2.0 */
  113. UCNV_LMBCS_4,
  114. /** @stable ICU 2.0 */
  115. UCNV_LMBCS_5,
  116. /** @stable ICU 2.0 */
  117. UCNV_LMBCS_6,
  118. /** @stable ICU 2.0 */
  119. UCNV_LMBCS_8,
  120. /** @stable ICU 2.0 */
  121. UCNV_LMBCS_11,
  122. /** @stable ICU 2.0 */
  123. UCNV_LMBCS_16,
  124. /** @stable ICU 2.0 */
  125. UCNV_LMBCS_17,
  126. /** @stable ICU 2.0 */
  127. UCNV_LMBCS_18,
  128. /** @stable ICU 2.0 */
  129. UCNV_LMBCS_19,
  130. /** @stable ICU 2.0 */
  131. UCNV_LMBCS_LAST = UCNV_LMBCS_19,
  132. /** @stable ICU 2.0 */
  133. UCNV_HZ,
  134. /** @stable ICU 2.0 */
  135. UCNV_SCSU,
  136. /** @stable ICU 2.0 */
  137. UCNV_ISCII,
  138. /** @stable ICU 2.0 */
  139. UCNV_US_ASCII,
  140. /** @stable ICU 2.0 */
  141. UCNV_UTF7,
  142. /** @stable ICU 2.2 */
  143. UCNV_BOCU1,
  144. /** @stable ICU 2.2 */
  145. UCNV_UTF16,
  146. /** @stable ICU 2.2 */
  147. UCNV_UTF32,
  148. /** @stable ICU 2.2 */
  149. UCNV_CESU8,
  150. /** @stable ICU 2.4 */
  151. UCNV_IMAP_MAILBOX,
  152. /** @stable ICU 4.8 */
  153. UCNV_COMPOUND_TEXT,
  154. /* Number of converter types for which we have conversion routines. */
  155. UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES
  156. } UConverterType;
  157. /**
  158. * Enum for specifying which platform a converter ID refers to.
  159. * The use of platform/CCSID is not recommended. See ucnv_openCCSID().
  160. *
  161. * @see ucnv_getPlatform
  162. * @see ucnv_openCCSID
  163. * @see ucnv_getCCSID
  164. * @stable ICU 2.0
  165. */
  166. typedef enum {
  167. UCNV_UNKNOWN = -1,
  168. UCNV_IBM = 0
  169. } UConverterPlatform;
  170. /**
  171. * Function pointer for error callback in the codepage to unicode direction.
  172. * Called when an error has occured in conversion to unicode, or on open/close of the callback (see reason).
  173. * @param context Pointer to the callback's private data
  174. * @param args Information about the conversion in progress
  175. * @param codeUnits Points to 'length' bytes of the concerned codepage sequence
  176. * @param length Size (in bytes) of the concerned codepage sequence
  177. * @param reason Defines the reason the callback was invoked
  178. * @param pErrorCode ICU error code in/out parameter.
  179. * For converter callback functions, set to a conversion error
  180. * before the call, and the callback may reset it to U_ZERO_ERROR.
  181. * @see ucnv_setToUCallBack
  182. * @see UConverterToUnicodeArgs
  183. * @stable ICU 2.0
  184. */
  185. typedef void (U_EXPORT2 *UConverterToUCallback) (
  186. const void* context,
  187. UConverterToUnicodeArgs *args,
  188. const char *codeUnits,
  189. int32_t length,
  190. UConverterCallbackReason reason,
  191. UErrorCode *pErrorCode);
  192. /**
  193. * Function pointer for error callback in the unicode to codepage direction.
  194. * Called when an error has occured in conversion from unicode, or on open/close of the callback (see reason).
  195. * @param context Pointer to the callback's private data
  196. * @param args Information about the conversion in progress
  197. * @param codeUnits Points to 'length' UChars of the concerned Unicode sequence
  198. * @param length Size (in bytes) of the concerned codepage sequence
  199. * @param codePoint Single UChar32 (UTF-32) containing the concerend Unicode codepoint.
  200. * @param reason Defines the reason the callback was invoked
  201. * @param pErrorCode ICU error code in/out parameter.
  202. * For converter callback functions, set to a conversion error
  203. * before the call, and the callback may reset it to U_ZERO_ERROR.
  204. * @see ucnv_setFromUCallBack
  205. * @stable ICU 2.0
  206. */
  207. typedef void (U_EXPORT2 *UConverterFromUCallback) (
  208. const void* context,
  209. UConverterFromUnicodeArgs *args,
  210. const UChar* codeUnits,
  211. int32_t length,
  212. UChar32 codePoint,
  213. UConverterCallbackReason reason,
  214. UErrorCode *pErrorCode);
  215. U_CDECL_END
  216. /**
  217. * Character that separates converter names from options and options from each other.
  218. * @see ucnv_open
  219. * @stable ICU 2.0
  220. */
  221. #define UCNV_OPTION_SEP_CHAR ','
  222. /**
  223. * String version of UCNV_OPTION_SEP_CHAR.
  224. * @see ucnv_open
  225. * @stable ICU 2.0
  226. */
  227. #define UCNV_OPTION_SEP_STRING ","
  228. /**
  229. * Character that separates a converter option from its value.
  230. * @see ucnv_open
  231. * @stable ICU 2.0
  232. */
  233. #define UCNV_VALUE_SEP_CHAR '='
  234. /**
  235. * String version of UCNV_VALUE_SEP_CHAR.
  236. * @see ucnv_open
  237. * @stable ICU 2.0
  238. */
  239. #define UCNV_VALUE_SEP_STRING "="
  240. /**
  241. * Converter option for specifying a locale.
  242. * For example, ucnv_open("SCSU,locale=ja", &errorCode);
  243. * See convrtrs.txt.
  244. *
  245. * @see ucnv_open
  246. * @stable ICU 2.0
  247. */
  248. #define UCNV_LOCALE_OPTION_STRING ",locale="
  249. /**
  250. * Converter option for specifying a version selector (0..9) for some converters.
  251. * For example,
  252. * \code
  253. * ucnv_open("UTF-7,version=1", &errorCode);
  254. * \endcode
  255. * See convrtrs.txt.
  256. *
  257. * @see ucnv_open
  258. * @stable ICU 2.4
  259. */
  260. #define UCNV_VERSION_OPTION_STRING ",version="
  261. /**
  262. * Converter option for EBCDIC SBCS or mixed-SBCS/DBCS (stateful) codepages.
  263. * Swaps Unicode mappings for EBCDIC LF and NL codes, as used on
  264. * S/390 (z/OS) Unix System Services (Open Edition).
  265. * For example, ucnv_open("ibm-1047,swaplfnl", &errorCode);
  266. * See convrtrs.txt.
  267. *
  268. * @see ucnv_open
  269. * @stable ICU 2.4
  270. */
  271. #define UCNV_SWAP_LFNL_OPTION_STRING ",swaplfnl"
  272. /**
  273. * Do a fuzzy compare of two converter/alias names.
  274. * The comparison is case-insensitive, ignores leading zeroes if they are not
  275. * followed by further digits, and ignores all but letters and digits.
  276. * Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent.
  277. * See section 1.4, Charset Alias Matching in Unicode Technical Standard #22
  278. * at http://www.unicode.org/reports/tr22/
  279. *
  280. * @param name1 a converter name or alias, zero-terminated
  281. * @param name2 a converter name or alias, zero-terminated
  282. * @return 0 if the names match, or a negative value if the name1
  283. * lexically precedes name2, or a positive value if the name1
  284. * lexically follows name2.
  285. * @stable ICU 2.0
  286. */
  287. U_STABLE int U_EXPORT2
  288. ucnv_compareNames(const char *name1, const char *name2);
  289. /**
  290. * Creates a UConverter object with the name of a coded character set specified as a C string.
  291. * The actual name will be resolved with the alias file
  292. * using a case-insensitive string comparison that ignores
  293. * leading zeroes and all non-alphanumeric characters.
  294. * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent.
  295. * (See also ucnv_compareNames().)
  296. * If <code>NULL</code> is passed for the converter name, it will create one with the
  297. * getDefaultName return value.
  298. *
  299. * <p>A converter name for ICU 1.5 and above may contain options
  300. * like a locale specification to control the specific behavior of
  301. * the newly instantiated converter.
  302. * The meaning of the options depends on the particular converter.
  303. * If an option is not defined for or recognized by a given converter, then it is ignored.</p>
  304. *
  305. * <p>Options are appended to the converter name string, with a
  306. * <code>UCNV_OPTION_SEP_CHAR</code> between the name and the first option and
  307. * also between adjacent options.</p>
  308. *
  309. * <p>If the alias is ambiguous, then the preferred converter is used
  310. * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.</p>
  311. *
  312. * <p>The conversion behavior and names can vary between platforms. ICU may
  313. * convert some characters differently from other platforms. Details on this topic
  314. * are in the <a href="http://icu-project.org/userguide/conversion.html">User's
  315. * Guide</a>. Aliases starting with a "cp" prefix have no specific meaning
  316. * other than its an alias starting with the letters "cp". Please do not
  317. * associate any meaning to these aliases.</p>
  318. *
  319. * \snippet samples/ucnv/convsamp.cpp ucnv_open
  320. *
  321. * @param converterName Name of the coded character set table.
  322. * This may have options appended to the string.
  323. * IANA alias character set names, IBM CCSIDs starting with "ibm-",
  324. * Windows codepage numbers starting with "windows-" are frequently
  325. * used for this parameter. See ucnv_getAvailableName and
  326. * ucnv_getAlias for a complete list that is available.
  327. * If this parameter is NULL, the default converter will be used.
  328. * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
  329. * @return the created Unicode converter object, or <TT>NULL</TT> if an error occured
  330. * @see ucnv_openU
  331. * @see ucnv_openCCSID
  332. * @see ucnv_getAvailableName
  333. * @see ucnv_getAlias
  334. * @see ucnv_getDefaultName
  335. * @see ucnv_close
  336. * @see ucnv_compareNames
  337. * @stable ICU 2.0
  338. */
  339. U_STABLE UConverter* U_EXPORT2
  340. ucnv_open(const char *converterName, UErrorCode *err);
  341. /**
  342. * Creates a Unicode converter with the names specified as unicode string.
  343. * The name should be limited to the ASCII-7 alphanumerics range.
  344. * The actual name will be resolved with the alias file
  345. * using a case-insensitive string comparison that ignores
  346. * leading zeroes and all non-alphanumeric characters.
  347. * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent.
  348. * (See also ucnv_compareNames().)
  349. * If <TT>NULL</TT> is passed for the converter name, it will create
  350. * one with the ucnv_getDefaultName() return value.
  351. * If the alias is ambiguous, then the preferred converter is used
  352. * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
  353. *
  354. * <p>See ucnv_open for the complete details</p>
  355. * @param name Name of the UConverter table in a zero terminated
  356. * Unicode string
  357. * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR,
  358. * U_FILE_ACCESS_ERROR</TT>
  359. * @return the created Unicode converter object, or <TT>NULL</TT> if an
  360. * error occured
  361. * @see ucnv_open
  362. * @see ucnv_openCCSID
  363. * @see ucnv_close
  364. * @see ucnv_compareNames
  365. * @stable ICU 2.0
  366. */
  367. U_STABLE UConverter* U_EXPORT2
  368. ucnv_openU(const UChar *name,
  369. UErrorCode *err);
  370. /**
  371. * Creates a UConverter object from a CCSID number and platform pair.
  372. * Note that the usefulness of this function is limited to platforms with numeric
  373. * encoding IDs. Only IBM and Microsoft platforms use numeric (16-bit) identifiers for
  374. * encodings.
  375. *
  376. * In addition, IBM CCSIDs and Unicode conversion tables are not 1:1 related.
  377. * For many IBM CCSIDs there are multiple (up to six) Unicode conversion tables, and
  378. * for some Unicode conversion tables there are multiple CCSIDs.
  379. * Some "alternate" Unicode conversion tables are provided by the
  380. * IBM CDRA conversion table registry.
  381. * The most prominent example of a systematic modification of conversion tables that is
  382. * not provided in the form of conversion table files in the repository is
  383. * that S/390 Unix System Services swaps the codes for Line Feed and New Line in all
  384. * EBCDIC codepages, which requires such a swap in the Unicode conversion tables as well.
  385. *
  386. * Only IBM default conversion tables are accessible with ucnv_openCCSID().
  387. * ucnv_getCCSID() will return the same CCSID for all conversion tables that are associated
  388. * with that CCSID.
  389. *
  390. * Currently, the only "platform" supported in the ICU converter API is UCNV_IBM.
  391. *
  392. * In summary, the use of CCSIDs and the associated API functions is not recommended.
  393. *
  394. * In order to open a converter with the default IBM CDRA Unicode conversion table,
  395. * you can use this function or use the prefix "ibm-":
  396. * \code
  397. * char name[20];
  398. * sprintf(name, "ibm-%hu", ccsid);
  399. * cnv=ucnv_open(name, &errorCode);
  400. * \endcode
  401. *
  402. * In order to open a converter with the IBM S/390 Unix System Services variant
  403. * of a Unicode/EBCDIC conversion table,
  404. * you can use the prefix "ibm-" together with the option string UCNV_SWAP_LFNL_OPTION_STRING:
  405. * \code
  406. * char name[20];
  407. * sprintf(name, "ibm-%hu" UCNV_SWAP_LFNL_OPTION_STRING, ccsid);
  408. * cnv=ucnv_open(name, &errorCode);
  409. * \endcode
  410. *
  411. * In order to open a converter from a Microsoft codepage number, use the prefix "cp":
  412. * \code
  413. * char name[20];
  414. * sprintf(name, "cp%hu", codepageID);
  415. * cnv=ucnv_open(name, &errorCode);
  416. * \endcode
  417. *
  418. * If the alias is ambiguous, then the preferred converter is used
  419. * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
  420. *
  421. * @param codepage codepage number to create
  422. * @param platform the platform in which the codepage number exists
  423. * @param err error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
  424. * @return the created Unicode converter object, or <TT>NULL</TT> if an error
  425. * occured.
  426. * @see ucnv_open
  427. * @see ucnv_openU
  428. * @see ucnv_close
  429. * @see ucnv_getCCSID
  430. * @see ucnv_getPlatform
  431. * @see UConverterPlatform
  432. * @stable ICU 2.0
  433. */
  434. U_STABLE UConverter* U_EXPORT2
  435. ucnv_openCCSID(int32_t codepage,
  436. UConverterPlatform platform,
  437. UErrorCode * err);
  438. /**
  439. * <p>Creates a UConverter object specified from a packageName and a converterName.</p>
  440. *
  441. * <p>The packageName and converterName must point to an ICU udata object, as defined by
  442. * <code> udata_open( packageName, "cnv", converterName, err) </code> or equivalent.
  443. * Typically, packageName will refer to a (.dat) file, or to a package registered with
  444. * udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.</p>
  445. *
  446. * <p>The name will NOT be looked up in the alias mechanism, nor will the converter be
  447. * stored in the converter cache or the alias table. The only way to open further converters
  448. * is call this function multiple times, or use the ucnv_safeClone() function to clone a
  449. * 'master' converter.</p>
  450. *
  451. * <p>A future version of ICU may add alias table lookups and/or caching
  452. * to this function.</p>
  453. *
  454. * <p>Example Use:
  455. * <code>cnv = ucnv_openPackage("myapp", "myconverter", &err);</code>
  456. * </p>
  457. *
  458. * @param packageName name of the package (equivalent to 'path' in udata_open() call)
  459. * @param converterName name of the data item to be used, without suffix.
  460. * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
  461. * @return the created Unicode converter object, or <TT>NULL</TT> if an error occured
  462. * @see udata_open
  463. * @see ucnv_open
  464. * @see ucnv_safeClone
  465. * @see ucnv_close
  466. * @stable ICU 2.2
  467. */
  468. U_STABLE UConverter* U_EXPORT2
  469. ucnv_openPackage(const char *packageName, const char *converterName, UErrorCode *err);
  470. /**
  471. * Thread safe converter cloning operation.
  472. * For most efficient operation, pass in a stackBuffer (and a *pBufferSize)
  473. * with at least U_CNV_SAFECLONE_BUFFERSIZE bytes of space.
  474. * If the buffer size is sufficient, then the clone will use the stack buffer;
  475. * otherwise, it will be allocated, and *pBufferSize will indicate
  476. * the actual size. (This should not occur with U_CNV_SAFECLONE_BUFFERSIZE.)
  477. *
  478. * You must ucnv_close() the clone in any case.
  479. *
  480. * If *pBufferSize==0, (regardless of whether stackBuffer==NULL or not)
  481. * then *pBufferSize will be changed to a sufficient size
  482. * for cloning this converter,
  483. * without actually cloning the converter ("pure pre-flighting").
  484. *
  485. * If *pBufferSize is greater than zero but not large enough for a stack-based
  486. * clone, then the converter is cloned using newly allocated memory
  487. * and *pBufferSize is changed to the necessary size.
  488. *
  489. * If the converter clone fits into the stack buffer but the stack buffer is not
  490. * sufficiently aligned for the clone, then the clone will use an
  491. * adjusted pointer and use an accordingly smaller buffer size.
  492. *
  493. * @param cnv converter to be cloned
  494. * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br>
  495. * user allocated space for the new clone. If NULL new memory will be allocated.
  496. * If buffer is not large enough, new memory will be allocated.
  497. * Clients can use the U_CNV_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations.
  498. * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br>
  499. * pointer to size of allocated space.
  500. * @param status to indicate whether the operation went on smoothly or there were errors
  501. * An informational status value, U_SAFECLONE_ALLOCATED_WARNING,
  502. * is used if any allocations were necessary.
  503. * However, it is better to check if *pBufferSize grew for checking for
  504. * allocations because warning codes can be overridden by subsequent
  505. * function calls.
  506. * @return pointer to the new clone
  507. * @stable ICU 2.0
  508. */
  509. U_STABLE UConverter * U_EXPORT2
  510. ucnv_safeClone(const UConverter *cnv,
  511. void *stackBuffer,
  512. int32_t *pBufferSize,
  513. UErrorCode *status);
  514. #ifndef U_HIDE_DEPRECATED_API
  515. /**
  516. * \def U_CNV_SAFECLONE_BUFFERSIZE
  517. * Definition of a buffer size that is designed to be large enough for
  518. * converters to be cloned with ucnv_safeClone().
  519. * @deprecated ICU 52. Do not rely on ucnv_safeClone() cloning into any provided buffer.
  520. */
  521. #define U_CNV_SAFECLONE_BUFFERSIZE 1024
  522. #endif /* U_HIDE_DEPRECATED_API */
  523. /**
  524. * Deletes the unicode converter and releases resources associated
  525. * with just this instance.
  526. * Does not free up shared converter tables.
  527. *
  528. * @param converter the converter object to be deleted
  529. * @see ucnv_open
  530. * @see ucnv_openU
  531. * @see ucnv_openCCSID
  532. * @stable ICU 2.0
  533. */
  534. U_STABLE void U_EXPORT2
  535. ucnv_close(UConverter * converter);
  536. #if U_SHOW_CPLUSPLUS_API
  537. U_NAMESPACE_BEGIN
  538. /**
  539. * \class LocalUConverterPointer
  540. * "Smart pointer" class, closes a UConverter via ucnv_close().
  541. * For most methods see the LocalPointerBase base class.
  542. *
  543. * @see LocalPointerBase
  544. * @see LocalPointer
  545. * @stable ICU 4.4
  546. */
  547. U_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterPointer, UConverter, ucnv_close);
  548. U_NAMESPACE_END
  549. #endif
  550. /**
  551. * Fills in the output parameter, subChars, with the substitution characters
  552. * as multiple bytes.
  553. * If ucnv_setSubstString() set a Unicode string because the converter is
  554. * stateful, then subChars will be an empty string.
  555. *
  556. * @param converter the Unicode converter
  557. * @param subChars the subsitution characters
  558. * @param len on input the capacity of subChars, on output the number
  559. * of bytes copied to it
  560. * @param err the outgoing error status code.
  561. * If the substitution character array is too small, an
  562. * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
  563. * @see ucnv_setSubstString
  564. * @see ucnv_setSubstChars
  565. * @stable ICU 2.0
  566. */
  567. U_STABLE void U_EXPORT2
  568. ucnv_getSubstChars(const UConverter *converter,
  569. char *subChars,
  570. int8_t *len,
  571. UErrorCode *err);
  572. /**
  573. * Sets the substitution chars when converting from unicode to a codepage. The
  574. * substitution is specified as a string of 1-4 bytes, and may contain
  575. * <TT>NULL</TT> bytes.
  576. * The subChars must represent a single character. The caller needs to know the
  577. * byte sequence of a valid character in the converter's charset.
  578. * For some converters, for example some ISO 2022 variants, only single-byte
  579. * substitution characters may be supported.
  580. * The newer ucnv_setSubstString() function relaxes these limitations.
  581. *
  582. * @param converter the Unicode converter
  583. * @param subChars the substitution character byte sequence we want set
  584. * @param len the number of bytes in subChars
  585. * @param err the error status code. <TT>U_INDEX_OUTOFBOUNDS_ERROR </TT> if
  586. * len is bigger than the maximum number of bytes allowed in subchars
  587. * @see ucnv_setSubstString
  588. * @see ucnv_getSubstChars
  589. * @stable ICU 2.0
  590. */
  591. U_STABLE void U_EXPORT2
  592. ucnv_setSubstChars(UConverter *converter,
  593. const char *subChars,
  594. int8_t len,
  595. UErrorCode *err);
  596. /**
  597. * Set a substitution string for converting from Unicode to a charset.
  598. * The caller need not know the charset byte sequence for each charset.
  599. *
  600. * Unlike ucnv_setSubstChars() which is designed to set a charset byte sequence
  601. * for a single character, this function takes a Unicode string with
  602. * zero, one or more characters, and immediately verifies that the string can be
  603. * converted to the charset.
  604. * If not, or if the result is too long (more than 32 bytes as of ICU 3.6),
  605. * then the function returns with an error accordingly.
  606. *
  607. * Also unlike ucnv_setSubstChars(), this function works for stateful charsets
  608. * by converting on the fly at the point of substitution rather than setting
  609. * a fixed byte sequence.
  610. *
  611. * @param cnv The UConverter object.
  612. * @param s The Unicode string.
  613. * @param length The number of UChars in s, or -1 for a NUL-terminated string.
  614. * @param err Pointer to a standard ICU error code. Its input value must
  615. * pass the U_SUCCESS() test, or else the function returns
  616. * immediately. Check for U_FAILURE() on output or use with
  617. * function chaining. (See User Guide for details.)
  618. *
  619. * @see ucnv_setSubstChars
  620. * @see ucnv_getSubstChars
  621. * @stable ICU 3.6
  622. */
  623. U_STABLE void U_EXPORT2
  624. ucnv_setSubstString(UConverter *cnv,
  625. const UChar *s,
  626. int32_t length,
  627. UErrorCode *err);
  628. /**
  629. * Fills in the output parameter, errBytes, with the error characters from the
  630. * last failing conversion.
  631. *
  632. * @param converter the Unicode converter
  633. * @param errBytes the codepage bytes which were in error
  634. * @param len on input the capacity of errBytes, on output the number of
  635. * bytes which were copied to it
  636. * @param err the error status code.
  637. * If the substitution character array is too small, an
  638. * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
  639. * @stable ICU 2.0
  640. */
  641. U_STABLE void U_EXPORT2
  642. ucnv_getInvalidChars(const UConverter *converter,
  643. char *errBytes,
  644. int8_t *len,
  645. UErrorCode *err);
  646. /**
  647. * Fills in the output parameter, errChars, with the error characters from the
  648. * last failing conversion.
  649. *
  650. * @param converter the Unicode converter
  651. * @param errUChars the UChars which were in error
  652. * @param len on input the capacity of errUChars, on output the number of
  653. * UChars which were copied to it
  654. * @param err the error status code.
  655. * If the substitution character array is too small, an
  656. * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
  657. * @stable ICU 2.0
  658. */
  659. U_STABLE void U_EXPORT2
  660. ucnv_getInvalidUChars(const UConverter *converter,
  661. UChar *errUChars,
  662. int8_t *len,
  663. UErrorCode *err);
  664. /**
  665. * Resets the state of a converter to the default state. This is used
  666. * in the case of an error, to restart a conversion from a known default state.
  667. * It will also empty the internal output buffers.
  668. * @param converter the Unicode converter
  669. * @stable ICU 2.0
  670. */
  671. U_STABLE void U_EXPORT2
  672. ucnv_reset(UConverter *converter);
  673. /**
  674. * Resets the to-Unicode part of a converter state to the default state.
  675. * This is used in the case of an error to restart a conversion to
  676. * Unicode to a known default state. It will also empty the internal
  677. * output buffers used for the conversion to Unicode codepoints.
  678. * @param converter the Unicode converter
  679. * @stable ICU 2.0
  680. */
  681. U_STABLE void U_EXPORT2
  682. ucnv_resetToUnicode(UConverter *converter);
  683. /**
  684. * Resets the from-Unicode part of a converter state to the default state.
  685. * This is used in the case of an error to restart a conversion from
  686. * Unicode to a known default state. It will also empty the internal output
  687. * buffers used for the conversion from Unicode codepoints.
  688. * @param converter the Unicode converter
  689. * @stable ICU 2.0
  690. */
  691. U_STABLE void U_EXPORT2
  692. ucnv_resetFromUnicode(UConverter *converter);
  693. /**
  694. * Returns the maximum number of bytes that are output per UChar in conversion
  695. * from Unicode using this converter.
  696. * The returned number can be used with UCNV_GET_MAX_BYTES_FOR_STRING
  697. * to calculate the size of a target buffer for conversion from Unicode.
  698. *
  699. * Note: Before ICU 2.8, this function did not return reliable numbers for
  700. * some stateful converters (EBCDIC_STATEFUL, ISO-2022) and LMBCS.
  701. *
  702. * This number may not be the same as the maximum number of bytes per
  703. * "conversion unit". In other words, it may not be the intuitively expected
  704. * number of bytes per character that would be published for a charset,
  705. * and may not fulfill any other purpose than the allocation of an output
  706. * buffer of guaranteed sufficient size for a given input length and converter.
  707. *
  708. * Examples for special cases that are taken into account:
  709. * - Supplementary code points may convert to more bytes than BMP code points.
  710. * This function returns bytes per UChar (UTF-16 code unit), not per
  711. * Unicode code point, for efficient buffer allocation.
  712. * - State-shifting output (SI/SO, escapes, etc.) from stateful converters.
  713. * - When m input UChars are converted to n output bytes, then the maximum m/n
  714. * is taken into account.
  715. *
  716. * The number returned here does not take into account
  717. * (see UCNV_GET_MAX_BYTES_FOR_STRING):
  718. * - callbacks which output more than one charset character sequence per call,
  719. * like escape callbacks
  720. * - initial and final non-character bytes that are output by some converters
  721. * (automatic BOMs, initial escape sequence, final SI, etc.)
  722. *
  723. * Examples for returned values:
  724. * - SBCS charsets: 1
  725. * - Shift-JIS: 2
  726. * - UTF-16: 2 (2 per BMP, 4 per surrogate _pair_, BOM not counted)
  727. * - UTF-8: 3 (3 per BMP, 4 per surrogate _pair_)
  728. * - EBCDIC_STATEFUL (EBCDIC mixed SBCS/DBCS): 3 (SO + DBCS)
  729. * - ISO-2022: 3 (always outputs UTF-8)
  730. * - ISO-2022-JP: 6 (4-byte escape sequences + DBCS)
  731. * - ISO-2022-CN: 8 (4-byte designator sequences + 2-byte SS2/SS3 + DBCS)
  732. *
  733. * @param converter The Unicode converter.
  734. * @return The maximum number of bytes per UChar (16 bit code unit)
  735. * that are output by ucnv_fromUnicode(),
  736. * to be used together with UCNV_GET_MAX_BYTES_FOR_STRING
  737. * for buffer allocation.
  738. *
  739. * @see UCNV_GET_MAX_BYTES_FOR_STRING
  740. * @see ucnv_getMinCharSize
  741. * @stable ICU 2.0
  742. */
  743. U_STABLE int8_t U_EXPORT2
  744. ucnv_getMaxCharSize(const UConverter *converter);
  745. /**
  746. * Calculates the size of a buffer for conversion from Unicode to a charset.
  747. * The calculated size is guaranteed to be sufficient for this conversion.
  748. *
  749. * It takes into account initial and final non-character bytes that are output
  750. * by some converters.
  751. * It does not take into account callbacks which output more than one charset
  752. * character sequence per call, like escape callbacks.
  753. * The default (substitution) callback only outputs one charset character sequence.
  754. *
  755. * @param length Number of UChars to be converted.
  756. * @param maxCharSize Return value from ucnv_getMaxCharSize() for the converter
  757. * that will be used.
  758. * @return Size of a buffer that will be large enough to hold the output bytes of
  759. * converting length UChars with the converter that returned the maxCharSize.
  760. *
  761. * @see ucnv_getMaxCharSize
  762. * @stable ICU 2.8
  763. */
  764. #define UCNV_GET_MAX_BYTES_FOR_STRING(length, maxCharSize) \
  765. (((int32_t)(length)+10)*(int32_t)(maxCharSize))
  766. /**
  767. * Returns the minimum byte length (per codepoint) for characters in this codepage.
  768. * This is usually either 1 or 2.
  769. * @param converter the Unicode converter
  770. * @return the minimum number of bytes per codepoint allowed by this particular converter
  771. * @see ucnv_getMaxCharSize
  772. * @stable ICU 2.0
  773. */
  774. U_STABLE int8_t U_EXPORT2
  775. ucnv_getMinCharSize(const UConverter *converter);
  776. /**
  777. * Returns the display name of the converter passed in based on the Locale
  778. * passed in. If the locale contains no display name, the internal ASCII
  779. * name will be filled in.
  780. *
  781. * @param converter the Unicode converter.
  782. * @param displayLocale is the specific Locale we want to localised for
  783. * @param displayName user provided buffer to be filled in
  784. * @param displayNameCapacity size of displayName Buffer
  785. * @param err error status code
  786. * @return displayNameLength number of UChar needed in displayName
  787. * @see ucnv_getName
  788. * @stable ICU 2.0
  789. */
  790. U_STABLE int32_t U_EXPORT2
  791. ucnv_getDisplayName(const UConverter *converter,
  792. const char *displayLocale,
  793. UChar *displayName,
  794. int32_t displayNameCapacity,
  795. UErrorCode *err);
  796. /**
  797. * Gets the internal, canonical name of the converter (zero-terminated).
  798. * The lifetime of the returned string will be that of the converter
  799. * passed to this function.
  800. * @param converter the Unicode converter
  801. * @param err UErrorCode status
  802. * @return the internal name of the converter
  803. * @see ucnv_getDisplayName
  804. * @stable ICU 2.0
  805. */
  806. U_STABLE const char * U_EXPORT2
  807. ucnv_getName(const UConverter *converter, UErrorCode *err);
  808. /**
  809. * Gets a codepage number associated with the converter. This is not guaranteed
  810. * to be the one used to create the converter. Some converters do not represent
  811. * platform registered codepages and return zero for the codepage number.
  812. * The error code fill-in parameter indicates if the codepage number
  813. * is available.
  814. * Does not check if the converter is <TT>NULL</TT> or if converter's data
  815. * table is <TT>NULL</TT>.
  816. *
  817. * Important: The use of CCSIDs is not recommended because it is limited
  818. * to only two platforms in principle and only one (UCNV_IBM) in the current
  819. * ICU converter API.
  820. * Also, CCSIDs are insufficient to identify IBM Unicode conversion tables precisely.
  821. * For more details see ucnv_openCCSID().
  822. *
  823. * @param converter the Unicode converter
  824. * @param err the error status code.
  825. * @return If any error occurrs, -1 will be returned otherwise, the codepage number
  826. * will be returned
  827. * @see ucnv_openCCSID
  828. * @see ucnv_getPlatform
  829. * @stable ICU 2.0
  830. */
  831. U_STABLE int32_t U_EXPORT2
  832. ucnv_getCCSID(const UConverter *converter,
  833. UErrorCode *err);
  834. /**
  835. * Gets a codepage platform associated with the converter. Currently,
  836. * only <TT>UCNV_IBM</TT> will be returned.
  837. * Does not test if the converter is <TT>NULL</TT> or if converter's data
  838. * table is <TT>NULL</TT>.
  839. * @param converter the Unicode converter
  840. * @param err the error status code.
  841. * @return The codepage platform
  842. * @stable ICU 2.0
  843. */
  844. U_STABLE UConverterPlatform U_EXPORT2
  845. ucnv_getPlatform(const UConverter *converter,
  846. UErrorCode *err);
  847. /**
  848. * Gets the type of the converter
  849. * e.g. SBCS, MBCS, DBCS, UTF8, UTF16_BE, UTF16_LE, ISO_2022,
  850. * EBCDIC_STATEFUL, LATIN_1
  851. * @param converter a valid, opened converter
  852. * @return the type of the converter
  853. * @stable ICU 2.0
  854. */
  855. U_STABLE UConverterType U_EXPORT2
  856. ucnv_getType(const UConverter * converter);
  857. /**
  858. * Gets the "starter" (lead) bytes for converters of type MBCS.
  859. * Will fill in an <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if converter passed in
  860. * is not MBCS. Fills in an array of type UBool, with the value of the byte
  861. * as offset to the array. For example, if (starters[0x20] == TRUE) at return,
  862. * it means that the byte 0x20 is a starter byte in this converter.
  863. * Context pointers are always owned by the caller.
  864. *
  865. * @param converter a valid, opened converter of type MBCS
  866. * @param starters an array of size 256 to be filled in
  867. * @param err error status, <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if the
  868. * converter is not a type which can return starters.
  869. * @see ucnv_getType
  870. * @stable ICU 2.0
  871. */
  872. U_STABLE void U_EXPORT2
  873. ucnv_getStarters(const UConverter* converter,
  874. UBool starters[256],
  875. UErrorCode* err);
  876. /**
  877. * Selectors for Unicode sets that can be returned by ucnv_getUnicodeSet().
  878. * @see ucnv_getUnicodeSet
  879. * @stable ICU 2.6
  880. */
  881. typedef enum UConverterUnicodeSet {
  882. /** Select the set of roundtrippable Unicode code points. @stable ICU 2.6 */
  883. UCNV_ROUNDTRIP_SET,
  884. /** Select the set of Unicode code points with roundtrip or fallback mappings. @stable ICU 4.0 */
  885. UCNV_ROUNDTRIP_AND_FALLBACK_SET,
  886. #ifndef U_HIDE_DEPRECATED_API
  887. /**
  888. * Number of UConverterUnicodeSet selectors.
  889. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  890. */
  891. UCNV_SET_COUNT
  892. #endif // U_HIDE_DEPRECATED_API
  893. } UConverterUnicodeSet;
  894. /**
  895. * Returns the set of Unicode code points that can be converted by an ICU converter.
  896. *
  897. * Returns one of several kinds of set:
  898. *
  899. * 1. UCNV_ROUNDTRIP_SET
  900. *
  901. * The set of all Unicode code points that can be roundtrip-converted
  902. * (converted without any data loss) with the converter (ucnv_fromUnicode()).
  903. * This set will not include code points that have fallback mappings
  904. * or are only the result of reverse fallback mappings.
  905. * This set will also not include PUA code points with fallbacks, although
  906. * ucnv_fromUnicode() will always uses those mappings despite ucnv_setFallback().
  907. * See UTR #22 "Character Mapping Markup Language"
  908. * at http://www.unicode.org/reports/tr22/
  909. *
  910. * This is useful for example for
  911. * - checking that a string or document can be roundtrip-converted with a converter,
  912. * without/before actually performing the conversion
  913. * - testing if a converter can be used for text for typical text for a certain locale,
  914. * by comparing its roundtrip set with the set of ExemplarCharacters from
  915. * ICU's locale data or other sources
  916. *
  917. * 2. UCNV_ROUNDTRIP_AND_FALLBACK_SET
  918. *
  919. * The set of all Unicode code points that can be converted with the converter (ucnv_fromUnicode())
  920. * when fallbacks are turned on (see ucnv_setFallback()).
  921. * This set includes all code points with roundtrips and fallbacks (but not reverse fallbacks).
  922. *
  923. * In the future, there may be more UConverterUnicodeSet choices to select
  924. * sets with different properties.
  925. *
  926. * @param cnv The converter for which a set is requested.
  927. * @param setFillIn A valid USet *. It will be cleared by this function before
  928. * the converter's specific set is filled into the USet.
  929. * @param whichSet A UConverterUnicodeSet selector;
  930. * currently UCNV_ROUNDTRIP_SET is the only supported value.
  931. * @param pErrorCode ICU error code in/out parameter.
  932. * Must fulfill U_SUCCESS before the function call.
  933. *
  934. * @see UConverterUnicodeSet
  935. * @see uset_open
  936. * @see uset_close
  937. * @stable ICU 2.6
  938. */
  939. U_STABLE void U_EXPORT2
  940. ucnv_getUnicodeSet(const UConverter *cnv,
  941. USet *setFillIn,
  942. UConverterUnicodeSet whichSet,
  943. UErrorCode *pErrorCode);
  944. /**
  945. * Gets the current calback function used by the converter when an illegal
  946. * or invalid codepage sequence is found.
  947. * Context pointers are always owned by the caller.
  948. *
  949. * @param converter the unicode converter
  950. * @param action fillin: returns the callback function pointer
  951. * @param context fillin: returns the callback's private void* context
  952. * @see ucnv_setToUCallBack
  953. * @stable ICU 2.0
  954. */
  955. U_STABLE void U_EXPORT2
  956. ucnv_getToUCallBack (const UConverter * converter,
  957. UConverterToUCallback *action,
  958. const void **context);
  959. /**
  960. * Gets the current callback function used by the converter when illegal
  961. * or invalid Unicode sequence is found.
  962. * Context pointers are always owned by the caller.
  963. *
  964. * @param converter the unicode converter
  965. * @param action fillin: returns the callback function pointer
  966. * @param context fillin: returns the callback's private void* context
  967. * @see ucnv_setFromUCallBack
  968. * @stable ICU 2.0
  969. */
  970. U_STABLE void U_EXPORT2
  971. ucnv_getFromUCallBack (const UConverter * converter,
  972. UConverterFromUCallback *action,
  973. const void **context);
  974. /**
  975. * Changes the callback function used by the converter when
  976. * an illegal or invalid sequence is found.
  977. * Context pointers are always owned by the caller.
  978. * Predefined actions and contexts can be found in the ucnv_err.h header.
  979. *
  980. * @param converter the unicode converter
  981. * @param newAction the new callback function
  982. * @param newContext the new toUnicode callback context pointer. This can be NULL.
  983. * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
  984. * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
  985. * @param err The error code status
  986. * @see ucnv_getToUCallBack
  987. * @stable ICU 2.0
  988. */
  989. U_STABLE void U_EXPORT2
  990. ucnv_setToUCallBack (UConverter * converter,
  991. UConverterToUCallback newAction,
  992. const void* newContext,
  993. UConverterToUCallback *oldAction,
  994. const void** oldContext,
  995. UErrorCode * err);
  996. /**
  997. * Changes the current callback function used by the converter when
  998. * an illegal or invalid sequence is found.
  999. * Context pointers are always owned by the caller.
  1000. * Predefined actions and contexts can be found in the ucnv_err.h header.
  1001. *
  1002. * @param converter the unicode converter
  1003. * @param newAction the new callback function
  1004. * @param newContext the new fromUnicode callback context pointer. This can be NULL.
  1005. * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
  1006. * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
  1007. * @param err The error code status
  1008. * @see ucnv_getFromUCallBack
  1009. * @stable ICU 2.0
  1010. */
  1011. U_STABLE void U_EXPORT2
  1012. ucnv_setFromUCallBack (UConverter * converter,
  1013. UConverterFromUCallback newAction,
  1014. const void *newContext,
  1015. UConverterFromUCallback *oldAction,
  1016. const void **oldContext,
  1017. UErrorCode * err);
  1018. /**
  1019. * Converts an array of unicode characters to an array of codepage
  1020. * characters. This function is optimized for converting a continuous
  1021. * stream of data in buffer-sized chunks, where the entire source and
  1022. * target does not fit in available buffers.
  1023. *
  1024. * The source pointer is an in/out parameter. It starts out pointing where the
  1025. * conversion is to begin, and ends up pointing after the last UChar consumed.
  1026. *
  1027. * Target similarly starts out pointer at the first available byte in the output
  1028. * buffer, and ends up pointing after the last byte written to the output.
  1029. *
  1030. * The converter always attempts to consume the entire source buffer, unless
  1031. * (1.) the target buffer is full, or (2.) a failing error is returned from the
  1032. * current callback function. When a successful error status has been
  1033. * returned, it means that all of the source buffer has been
  1034. * consumed. At that point, the caller should reset the source and
  1035. * sourceLimit pointers to point to the next chunk.
  1036. *
  1037. * At the end of the stream (flush==TRUE), the input is completely consumed
  1038. * when *source==sourceLimit and no error code is set.
  1039. * The converter object is then automatically reset by this function.
  1040. * (This means that a converter need not be reset explicitly between data
  1041. * streams if it finishes the previous stream without errors.)
  1042. *
  1043. * This is a <I>stateful</I> conversion. Additionally, even when all source data has
  1044. * been consumed, some data may be in the converters' internal state.
  1045. * Call this function repeatedly, updating the target pointers with
  1046. * the next empty chunk of target in case of a
  1047. * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers
  1048. * with the next chunk of source when a successful error status is
  1049. * returned, until there are no more chunks of source data.
  1050. * @param converter the Unicode converter
  1051. * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
  1052. * codepage characters to. Output : points to after the last codepage character copied
  1053. * to <TT>target</TT>.
  1054. * @param targetLimit the pointer just after last of the <TT>target</TT> buffer
  1055. * @param source I/O parameter, pointer to pointer to the source Unicode character buffer.
  1056. * @param sourceLimit the pointer just after the last of the source buffer
  1057. * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
  1058. * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
  1059. * e.g: <TT>offsets[3]</TT> is equal to 6, it means that the <TT>target[3]</TT> was a result of transcoding <TT>source[6]</TT>
  1060. * For output data carried across calls, and other data without a specific source character
  1061. * (such as from escape sequences or callbacks) -1 will be placed for offsets.
  1062. * @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
  1063. * chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
  1064. * this function may have to be called multiple times with flush set to <TT>TRUE</TT> until
  1065. * the source buffer is consumed.
  1066. * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
  1067. * converter is <TT>NULL</TT>.
  1068. * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
  1069. * still data to be written to the target.
  1070. * @see ucnv_fromUChars
  1071. * @see ucnv_convert
  1072. * @see ucnv_getMinCharSize
  1073. * @see ucnv_setToUCallBack
  1074. * @stable ICU 2.0
  1075. */
  1076. U_STABLE void U_EXPORT2
  1077. ucnv_fromUnicode (UConverter * converter,
  1078. char **target,
  1079. const char *targetLimit,
  1080. const UChar ** source,
  1081. const UChar * sourceLimit,
  1082. int32_t* offsets,
  1083. UBool flush,
  1084. UErrorCode * err);
  1085. /**
  1086. * Converts a buffer of codepage bytes into an array of unicode UChars
  1087. * characters. This function is optimized for converting a continuous
  1088. * stream of data in buffer-sized chunks, where the entire source and
  1089. * target does not fit in available buffers.
  1090. *
  1091. * The source pointer is an in/out parameter. It starts out pointing where the
  1092. * conversion is to begin, and ends up pointing after the last byte of source consumed.
  1093. *
  1094. * Target similarly starts out pointer at the first available UChar in the output
  1095. * buffer, and ends up pointing after the last UChar written to the output.
  1096. * It does NOT necessarily keep UChar sequences together.
  1097. *
  1098. * The converter always attempts to consume the entire source buffer, unless
  1099. * (1.) the target buffer is full, or (2.) a failing error is returned from the
  1100. * current callback function. When a successful error status has been
  1101. * returned, it means that all of the source buffer has been
  1102. * consumed. At that point, the caller should reset the source and
  1103. * sourceLimit pointers to point to the next chunk.
  1104. *
  1105. * At the end of the stream (flush==TRUE), the input is completely consumed
  1106. * when *source==sourceLimit and no error code is set
  1107. * The converter object is then automatically reset by this function.
  1108. * (This means that a converter need not be reset explicitly between data
  1109. * streams if it finishes the previous stream without errors.)
  1110. *
  1111. * This is a <I>stateful</I> conversion. Additionally, even when all source data has
  1112. * been consumed, some data may be in the converters' internal state.
  1113. * Call this function repeatedly, updating the target pointers with
  1114. * the next empty chunk of target in case of a
  1115. * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers
  1116. * with the next chunk of source when a successful error status is
  1117. * returned, until there are no more chunks of source data.
  1118. * @param converter the Unicode converter
  1119. * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
  1120. * UChars into. Output : points to after the last UChar copied.
  1121. * @param targetLimit the pointer just after the end of the <TT>target</TT> buffer
  1122. * @param source I/O parameter, pointer to pointer to the source codepage buffer.
  1123. * @param sourceLimit the pointer to the byte after the end of the source buffer
  1124. * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
  1125. * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
  1126. * e.g: <TT>offsets[3]</TT> is equal to 6, it means that the <TT>target[3]</TT> was a result of transcoding <TT>source[6]</TT>
  1127. * For output data carried across calls, and other data without a specific source character
  1128. * (such as from escape sequences or callbacks) -1 will be placed for offsets.
  1129. * @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
  1130. * chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
  1131. * this function may have to be called multiple times with flush set to <TT>TRUE</TT> until
  1132. * the source buffer is consumed.
  1133. * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
  1134. * converter is <TT>NULL</TT>.
  1135. * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
  1136. * still data to be written to the target.
  1137. * @see ucnv_fromUChars
  1138. * @see ucnv_convert
  1139. * @see ucnv_getMinCharSize
  1140. * @see ucnv_setFromUCallBack
  1141. * @see ucnv_getNextUChar
  1142. * @stable ICU 2.0
  1143. */
  1144. U_STABLE void U_EXPORT2
  1145. ucnv_toUnicode(UConverter *converter,
  1146. UChar **target,
  1147. const UChar *targetLimit,
  1148. const char **source,
  1149. const char *sourceLimit,
  1150. int32_t *offsets,
  1151. UBool flush,
  1152. UErrorCode *err);
  1153. /**
  1154. * Convert the Unicode string into a codepage string using an existing UConverter.
  1155. * The output string is NUL-terminated if possible.
  1156. *
  1157. * This function is a more convenient but less powerful version of ucnv_fromUnicode().
  1158. * It is only useful for whole strings, not for streaming conversion.
  1159. *
  1160. * The maximum output buffer capacity required (barring output from callbacks) will be
  1161. * UCNV_GET_MAX_BYTES_FOR_STRING(srcLength, ucnv_getMaxCharSize(cnv)).
  1162. *
  1163. * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called)
  1164. * @param src the input Unicode string
  1165. * @param srcLength the input string length, or -1 if NUL-terminated
  1166. * @param dest destination string buffer, can be NULL if destCapacity==0
  1167. * @param destCapacity the number of chars available at dest
  1168. * @param pErrorCode normal ICU error code;
  1169. * common error codes that may be set by this function include
  1170. * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
  1171. * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
  1172. * @return the length of the output string, not counting the terminating NUL;
  1173. * if the length is greater than destCapacity, then the string will not fit
  1174. * and a buffer of the indicated length would need to be passed in
  1175. * @see ucnv_fromUnicode
  1176. * @see ucnv_convert
  1177. * @see UCNV_GET_MAX_BYTES_FOR_STRING
  1178. * @stable ICU 2.0
  1179. */
  1180. U_STABLE int32_t U_EXPORT2
  1181. ucnv_fromUChars(UConverter *cnv,
  1182. char *dest, int32_t destCapacity,
  1183. const UChar *src, int32_t srcLength,
  1184. UErrorCode *pErrorCode);
  1185. /**
  1186. * Convert the codepage string into a Unicode string using an existing UConverter.
  1187. * The output string is NUL-terminated if possible.
  1188. *
  1189. * This function is a more convenient but less powerful version of ucnv_toUnicode().
  1190. * It is only useful for whole strings, not for streaming conversion.
  1191. *
  1192. * The maximum output buffer capacity required (barring output from callbacks) will be
  1193. * 2*srcLength (each char may be converted into a surrogate pair).
  1194. *
  1195. * @param cnv the converter object to be used (ucnv_resetToUnicode() will be called)
  1196. * @param src the input codepage string
  1197. * @param srcLength the input string length, or -1 if NUL-terminated
  1198. * @param dest destination string buffer, can be NULL if destCapacity==0
  1199. * @param destCapacity the number of UChars available at dest
  1200. * @param pErrorCode normal ICU error code;
  1201. * common error codes that may be set by this function include
  1202. * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
  1203. * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
  1204. * @return the length of the output string, not counting the terminating NUL;
  1205. * if the length is greater than destCapacity, then the string will not fit
  1206. * and a buffer of the indicated length would need to be passed in
  1207. * @see ucnv_toUnicode
  1208. * @see ucnv_convert
  1209. * @stable ICU 2.0
  1210. */
  1211. U_STABLE int32_t U_EXPORT2
  1212. ucnv_toUChars(UConverter *cnv,
  1213. UChar *dest, int32_t destCapacity,
  1214. const char *src, int32_t srcLength,
  1215. UErrorCode *pErrorCode);
  1216. /**
  1217. * Convert a codepage buffer into Unicode one character at a time.
  1218. * The input is completely consumed when the U_INDEX_OUTOFBOUNDS_ERROR is set.
  1219. *
  1220. * Advantage compared to ucnv_toUnicode() or ucnv_toUChars():
  1221. * - Faster for small amounts of data, for most converters, e.g.,
  1222. * US-ASCII, ISO-8859-1, UTF-8/16/32, and most "normal" charsets.
  1223. * (For complex converters, e.g., SCSU, UTF-7 and ISO 2022 variants,
  1224. * it uses ucnv_toUnicode() internally.)
  1225. * - Convenient.
  1226. *
  1227. * Limitations compared to ucnv_toUnicode():
  1228. * - Always assumes flush=TRUE.
  1229. * This makes ucnv_getNextUChar() unsuitable for "streaming" conversion,
  1230. * that is, for where the input is supplied in multiple buffers,
  1231. * because ucnv_getNextUChar() will assume the end of the input at the end
  1232. * of the first buffer.
  1233. * - Does not provide offset output.
  1234. *
  1235. * It is possible to "mix" ucnv_getNextUChar() and ucnv_toUnicode() because
  1236. * ucnv_getNextUChar() uses the current state of the converter
  1237. * (unlike ucnv_toUChars() which always resets first).
  1238. * However, if ucnv_getNextUChar() is called after ucnv_toUnicode()
  1239. * stopped in the middle of a character sequence (with flush=FALSE),
  1240. * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode()
  1241. * internally until the next character boundary.
  1242. * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to
  1243. * start at a character boundary.)
  1244. *
  1245. * Instead of using ucnv_getNextUChar(), it is recommended
  1246. * to convert using ucnv_toUnicode() or ucnv_toUChars()
  1247. * and then iterate over the text using U16_NEXT() or a UCharIterator (uiter.h)
  1248. * or a C++ CharacterIterator or similar.
  1249. * This allows streaming conversion and offset output, for example.
  1250. *
  1251. * <p>Handling of surrogate pairs and supplementary-plane code points:<br>
  1252. * There are two different kinds of codepages that provide mappings for surrogate characters:
  1253. * <ul>
  1254. * <li>Codepages like UTF-8, UTF-32, and GB 18030 provide direct representations for Unicode
  1255. * code points U+10000-U+10ffff as well as for single surrogates U+d800-U+dfff.
  1256. * Each valid sequence will result in exactly one returned code point.
  1257. * If a sequence results in a single surrogate, then that will be returned
  1258. * by itself, even if a neighboring sequence encodes the matching surrogate.</li>
  1259. * <li>Codepages like SCSU and LMBCS (and UTF-16) provide direct representations only for BMP code points
  1260. * including surrogates. Code points in supplementary planes are represented with
  1261. * two sequences, each encoding a surrogate.
  1262. * For these codepages, matching pairs of surrogates will be combined into single
  1263. * code points for returning from this function.
  1264. * (Note that SCSU is actually a mix of these codepage types.)</li>
  1265. * </ul></p>
  1266. *
  1267. * @param converter an open UConverter
  1268. * @param source the address of a pointer to the codepage buffer, will be
  1269. * updated to point after the bytes consumed in the conversion call.
  1270. * @param sourceLimit points to the end of the input buffer
  1271. * @param err fills in error status (see ucnv_toUnicode)
  1272. * <code>U_INDEX_OUTOFBOUNDS_ERROR</code> will be set if the input
  1273. * is empty or does not convert to any output (e.g.: pure state-change
  1274. * codes SI/SO, escape sequences for ISO 2022,
  1275. * or if the callback did not output anything, ...).
  1276. * This function will not set a <code>U_BUFFER_OVERFLOW_ERROR</code> because
  1277. * the "buffer" is the return code. However, there might be subsequent output
  1278. * stored in the converter object
  1279. * that will be returned in following calls to this function.
  1280. * @return a UChar32 resulting from the partial conversion of source
  1281. * @see ucnv_toUnicode
  1282. * @see ucnv_toUChars
  1283. * @see ucnv_convert
  1284. * @stable ICU 2.0
  1285. */
  1286. U_STABLE UChar32 U_EXPORT2
  1287. ucnv_getNextUChar(UConverter * converter,
  1288. const char **source,
  1289. const char * sourceLimit,
  1290. UErrorCode * err);
  1291. /**
  1292. * Convert from one external charset to another using two existing UConverters.
  1293. * Internally, two conversions - ucnv_toUnicode() and ucnv_fromUnicode() -
  1294. * are used, "pivoting" through 16-bit Unicode.
  1295. *
  1296. * Important: For streaming conversion (multiple function calls for successive
  1297. * parts of a text stream), the caller must provide a pivot buffer explicitly,
  1298. * and must preserve the pivot buffer and associated pointers from one
  1299. * call to another. (The buffer may be moved if its contents and the relative
  1300. * pointer positions are preserved.)
  1301. *
  1302. * There is a similar function, ucnv_convert(),
  1303. * which has the following limitations:
  1304. * - it takes charset names, not converter objects, so that
  1305. * - two converters are opened for each call
  1306. * - only single-string conversion is possible, not streaming operation
  1307. * - it does not provide enough information to find out,
  1308. * in case of failure, whether the toUnicode or
  1309. * the fromUnicode conversion failed
  1310. *
  1311. * By contrast, ucnv_convertEx()
  1312. * - takes UConverter parameters instead of charset names
  1313. * - fully exposes the pivot buffer for streaming conversion and complete error handling
  1314. *
  1315. * ucnv_convertEx() also provides further convenience:
  1316. * - an option to reset the converters at the beginning
  1317. * (if reset==TRUE, see parameters;
  1318. * also sets *pivotTarget=*pivotSource=pivotStart)
  1319. * - allow NUL-terminated input
  1320. * (only a single NUL byte, will not work for charsets with multi-byte NULs)
  1321. * (if sourceLimit==NULL, see parameters)
  1322. * - terminate with a NUL on output
  1323. * (only a single NUL byte, not useful for charsets with multi-byte NULs),
  1324. * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
  1325. * the target buffer
  1326. * - the pivot buffer can be provided internally;
  1327. * possible only for whole-string conversion, not streaming conversion;
  1328. * in this case, the caller will not be able to get details about where an
  1329. * error occurred
  1330. * (if pivotStart==NULL, see below)
  1331. *
  1332. * The function returns when one of the following is true:
  1333. * - the entire source text has been converted successfully to the target buffer
  1334. * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
  1335. * - a conversion error occurred
  1336. * (other U_FAILURE(), see description of pErrorCode)
  1337. *
  1338. * Limitation compared to the direct use of
  1339. * ucnv_fromUnicode() and ucnv_toUnicode():
  1340. * ucnv_convertEx() does not provide offset information.
  1341. *
  1342. * Limitation compared to ucnv_fromUChars() and ucnv_toUChars():
  1343. * ucnv_convertEx() does not support preflighting directly.
  1344. *
  1345. * Sample code for converting a single string from
  1346. * one external charset to UTF-8, ignoring the location of errors:
  1347. *
  1348. * \code
  1349. * int32_t
  1350. * myToUTF8(UConverter *cnv,
  1351. * const char *s, int32_t length,
  1352. * char *u8, int32_t capacity,
  1353. * UErrorCode *pErrorCode) {
  1354. * UConverter *utf8Cnv;
  1355. * char *target;
  1356. *
  1357. * if(U_FAILURE(*pErrorCode)) {
  1358. * return 0;
  1359. * }
  1360. *
  1361. * utf8Cnv=myGetCachedUTF8Converter(pErrorCode);
  1362. * if(U_FAILURE(*pErrorCode)) {
  1363. * return 0;
  1364. * }
  1365. *
  1366. * if(length<0) {
  1367. * length=strlen(s);
  1368. * }
  1369. * target=u8;
  1370. * ucnv_convertEx(utf8Cnv, cnv,
  1371. * &target, u8+capacity,
  1372. * &s, s+length,
  1373. * NULL, NULL, NULL, NULL,
  1374. * TRUE, TRUE,
  1375. * pErrorCode);
  1376. *
  1377. * myReleaseCachedUTF8Converter(utf8Cnv);
  1378. *
  1379. * // return the output string length, but without preflighting
  1380. * return (int32_t)(target-u8);
  1381. * }
  1382. * \endcode
  1383. *
  1384. * @param targetCnv Output converter, used to convert from the UTF-16 pivot
  1385. * to the target using ucnv_fromUnicode().
  1386. * @param sourceCnv Input converter, used to convert from the source to
  1387. * the UTF-16 pivot using ucnv_toUnicode().
  1388. * @param target I/O parameter, same as for ucnv_fromUChars().
  1389. * Input: *target points to the beginning of the target buffer.
  1390. * Output: *target points to the first unit after the last char written.
  1391. * @param targetLimit Pointer to the first unit after the target buffer.
  1392. * @param source I/O parameter, same as for ucnv_toUChars().
  1393. * Input: *source points to the beginning of the source buffer.
  1394. * Output: *source points to the first unit after the last char read.
  1395. * @param sourceLimit Pointer to the first unit after the source buffer.
  1396. * @param pivotStart Pointer to the UTF-16 pivot buffer. If pivotStart==NULL,
  1397. * then an internal buffer is used and the other pivot
  1398. * arguments are ignored and can be NULL as well.
  1399. * @param pivotSource I/O parameter, same as source in ucnv_fromUChars() for
  1400. * conversion from the pivot buffer to the target buffer.
  1401. * @param pivotTarget I/O parameter, same as target in ucnv_toUChars() for
  1402. * conversion from the source buffer to the pivot buffer.
  1403. * It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit
  1404. * and pivotStart<pivotLimit (unless pivotStart==NULL).
  1405. * @param pivotLimit Pointer to the first unit after the pivot buffer.
  1406. * @param reset If TRUE, then ucnv_resetToUnicode(sourceCnv) and
  1407. * ucnv_resetFromUnicode(targetCnv) are called, and the
  1408. * pivot pointers are reset (*pivotTarget=*pivotSource=pivotStart).
  1409. * @param flush If true, indicates the end of the input.
  1410. * Passed directly to ucnv_toUnicode(), and carried over to
  1411. * ucnv_fromUnicode() when the source is empty as well.
  1412. * @param pErrorCode ICU error code in/out parameter.
  1413. * Must fulfill U_SUCCESS before the function call.
  1414. * U_BUFFER_OVERFLOW_ERROR always refers to the target buffer
  1415. * because overflows into the pivot buffer are handled internally.
  1416. * Other conversion errors are from the source-to-pivot
  1417. * conversion if *pivotSource==pivotStart, otherwise from
  1418. * the pivot-to-target conversion.
  1419. *
  1420. * @see ucnv_convert
  1421. * @see ucnv_fromAlgorithmic
  1422. * @see ucnv_toAlgorithmic
  1423. * @see ucnv_fromUnicode
  1424. * @see ucnv_toUnicode
  1425. * @see ucnv_fromUChars
  1426. * @see ucnv_toUChars
  1427. * @stable ICU 2.6
  1428. */
  1429. U_STABLE void U_EXPORT2
  1430. ucnv_convertEx(UConverter *targetCnv, UConverter *sourceCnv,
  1431. char **target, const char *targetLimit,
  1432. const char **source, const char *sourceLimit,
  1433. UChar *pivotStart, UChar **pivotSource,
  1434. UChar **pivotTarget, const UChar *pivotLimit,
  1435. UBool reset, UBool flush,
  1436. UErrorCode *pErrorCode);
  1437. /**
  1438. * Convert from one external charset to another.
  1439. * Internally, two converters are opened according to the name arguments,
  1440. * then the text is converted to and from the 16-bit Unicode "pivot"
  1441. * using ucnv_convertEx(), then the converters are closed again.
  1442. *
  1443. * This is a convenience function, not an efficient way to convert a lot of text:
  1444. * ucnv_convert()
  1445. * - takes charset names, not converter objects, so that
  1446. * - two converters are opened for each call
  1447. * - only single-string conversion is possible, not streaming operation
  1448. * - does not provide enough information to find out,
  1449. * in case of failure, whether the toUnicode or
  1450. * the fromUnicode conversion failed
  1451. * - allows NUL-terminated input
  1452. * (only a single NUL byte, will not work for charsets with multi-byte NULs)
  1453. * (if sourceLength==-1, see parameters)
  1454. * - terminate with a NUL on output
  1455. * (only a single NUL byte, not useful for charsets with multi-byte NULs),
  1456. * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
  1457. * the target buffer
  1458. * - a pivot buffer is provided internally
  1459. *
  1460. * The function returns when one of the following is true:
  1461. * - the entire source text has been converted successfully to the target buffer
  1462. * and either the target buffer is terminated with a single NUL byte
  1463. * or the error code is set to U_STRING_NOT_TERMINATED_WARNING
  1464. * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
  1465. * and the full output string length is returned ("preflighting")
  1466. * - a conversion error occurred
  1467. * (other U_FAILURE(), see description of pErrorCode)
  1468. *
  1469. * @param toConverterName The name of the converter that is used to convert
  1470. * from the UTF-16 pivot buffer to the target.
  1471. * @param fromConverterName The name of the converter that is used to convert
  1472. * from the source to the UTF-16 pivot buffer.
  1473. * @param target Pointer to the output buffer.
  1474. * @param targetCapacity Capacity of the target, in bytes.
  1475. * @param source Pointer to the input buffer.
  1476. * @param sourceLength Length of the input text, in bytes, or -1 for NUL-terminated input.
  1477. * @param pErrorCode ICU error code in/out parameter.
  1478. * Must fulfill U_SUCCESS before the function call.
  1479. * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
  1480. * and a U_BUFFER_OVERFLOW_ERROR is set.
  1481. *
  1482. * @see ucnv_convertEx
  1483. * @see ucnv_fromAlgorithmic
  1484. * @see ucnv_toAlgorithmic
  1485. * @see ucnv_fromUnicode
  1486. * @see ucnv_toUnicode
  1487. * @see ucnv_fromUChars
  1488. * @see ucnv_toUChars
  1489. * @see ucnv_getNextUChar
  1490. * @stable ICU 2.0
  1491. */
  1492. U_STABLE int32_t U_EXPORT2
  1493. ucnv_convert(const char *toConverterName,
  1494. const char *fromConverterName,
  1495. char *target,
  1496. int32_t targetCapacity,
  1497. const char *source,
  1498. int32_t sourceLength,
  1499. UErrorCode *pErrorCode);
  1500. /**
  1501. * Convert from one external charset to another.
  1502. * Internally, the text is converted to and from the 16-bit Unicode "pivot"
  1503. * using ucnv_convertEx(). ucnv_toAlgorithmic() works exactly like ucnv_convert()
  1504. * except that the two converters need not be looked up and opened completely.
  1505. *
  1506. * The source-to-pivot conversion uses the cnv converter parameter.
  1507. * The pivot-to-target conversion uses a purely algorithmic converter
  1508. * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
  1509. *
  1510. * Internally, the algorithmic converter is opened and closed for each
  1511. * function call, which is more efficient than using the public ucnv_open()
  1512. * but somewhat less efficient than only resetting an existing converter
  1513. * and using ucnv_convertEx().
  1514. *
  1515. * This function is more convenient than ucnv_convertEx() for single-string
  1516. * conversions, especially when "preflighting" is desired (returning the length
  1517. * of the complete output even if it does not fit into the target buffer;
  1518. * see the User Guide Strings chapter). See ucnv_convert() for details.
  1519. *
  1520. * @param algorithmicType UConverterType constant identifying the desired target
  1521. * charset as a purely algorithmic converter.
  1522. * Those are converters for Unicode charsets like
  1523. * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
  1524. * as well as US-ASCII and ISO-8859-1.
  1525. * @param cnv The converter that is used to convert
  1526. * from the source to the UTF-16 pivot buffer.
  1527. * @param target Pointer to the output buffer.
  1528. * @param targetCapacity Capacity of the target, in bytes.
  1529. * @param source Pointer to the input buffer.
  1530. * @param sourceLength Length of the input text, in bytes
  1531. * @param pErrorCode ICU error code in/out parameter.
  1532. * Must fulfill U_SUCCESS before the function call.
  1533. * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
  1534. * and a U_BUFFER_OVERFLOW_ERROR is set.
  1535. *
  1536. * @see ucnv_fromAlgorithmic
  1537. * @see ucnv_convert
  1538. * @see ucnv_convertEx
  1539. * @see ucnv_fromUnicode
  1540. * @see ucnv_toUnicode
  1541. * @see ucnv_fromUChars
  1542. * @see ucnv_toUChars
  1543. * @stable ICU 2.6
  1544. */
  1545. U_STABLE int32_t U_EXPORT2
  1546. ucnv_toAlgorithmic(UConverterType algorithmicType,
  1547. UConverter *cnv,
  1548. char *target, int32_t targetCapacity,
  1549. const char *source, int32_t sourceLength,
  1550. UErrorCode *pErrorCode);
  1551. /**
  1552. * Convert from one external charset to another.
  1553. * Internally, the text is converted to and from the 16-bit Unicode "pivot"
  1554. * using ucnv_convertEx(). ucnv_fromAlgorithmic() works exactly like ucnv_convert()
  1555. * except that the two converters need not be looked up and opened completely.
  1556. *
  1557. * The source-to-pivot conversion uses a purely algorithmic converter
  1558. * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
  1559. * The pivot-to-target conversion uses the cnv converter parameter.
  1560. *
  1561. * Internally, the algorithmic converter is opened and closed for each
  1562. * function call, which is more efficient than using the public ucnv_open()
  1563. * but somewhat less efficient than only resetting an existing converter
  1564. * and using ucnv_convertEx().
  1565. *
  1566. * This function is more convenient than ucnv_convertEx() for single-string
  1567. * conversions, especially when "preflighting" is desired (returning the length
  1568. * of the complete output even if it does not fit into the target buffer;
  1569. * see the User Guide Strings chapter). See ucnv_convert() for details.
  1570. *
  1571. * @param cnv The converter that is used to convert
  1572. * from the UTF-16 pivot buffer to the target.
  1573. * @param algorithmicType UConverterType constant identifying the desired source
  1574. * charset as a purely algorithmic converter.
  1575. * Those are converters for Unicode charsets like
  1576. * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
  1577. * as well as US-ASCII and ISO-8859-1.
  1578. * @param target Pointer to the output buffer.
  1579. * @param targetCapacity Capacity of the target, in bytes.
  1580. * @param source Pointer to the input buffer.
  1581. * @param sourceLength Length of the input text, in bytes
  1582. * @param pErrorCode ICU error code in/out parameter.
  1583. * Must fulfill U_SUCCESS before the function call.
  1584. * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
  1585. * and a U_BUFFER_OVERFLOW_ERROR is set.
  1586. *
  1587. * @see ucnv_fromAlgorithmic
  1588. * @see ucnv_convert
  1589. * @see ucnv_convertEx
  1590. * @see ucnv_fromUnicode
  1591. * @see ucnv_toUnicode
  1592. * @see ucnv_fromUChars
  1593. * @see ucnv_toUChars
  1594. * @stable ICU 2.6
  1595. */
  1596. U_STABLE int32_t U_EXPORT2
  1597. ucnv_fromAlgorithmic(UConverter *cnv,
  1598. UConverterType algorithmicType,
  1599. char *target, int32_t targetCapacity,
  1600. const char *source, int32_t sourceLength,
  1601. UErrorCode *pErrorCode);
  1602. /**
  1603. * Frees up memory occupied by unused, cached converter shared data.
  1604. *
  1605. * @return the number of cached converters successfully deleted
  1606. * @see ucnv_close
  1607. * @stable ICU 2.0
  1608. */
  1609. U_STABLE int32_t U_EXPORT2
  1610. ucnv_flushCache(void);
  1611. /**
  1612. * Returns the number of available converters, as per the alias file.
  1613. *
  1614. * @return the number of available converters
  1615. * @see ucnv_getAvailableName
  1616. * @stable ICU 2.0
  1617. */
  1618. U_STABLE int32_t U_EXPORT2
  1619. ucnv_countAvailable(void);
  1620. /**
  1621. * Gets the canonical converter name of the specified converter from a list of
  1622. * all available converters contaied in the alias file. All converters
  1623. * in this list can be opened.
  1624. *
  1625. * @param n the index to a converter available on the system (in the range <TT>[0..ucnv_countAvaiable()]</TT>)
  1626. * @return a pointer a string (library owned), or <TT>NULL</TT> if the index is out of bounds.
  1627. * @see ucnv_countAvailable
  1628. * @stable ICU 2.0
  1629. */
  1630. U_STABLE const char* U_EXPORT2
  1631. ucnv_getAvailableName(int32_t n);
  1632. /**
  1633. * Returns a UEnumeration to enumerate all of the canonical converter
  1634. * names, as per the alias file, regardless of the ability to open each
  1635. * converter.
  1636. *
  1637. * @return A UEnumeration object for getting all the recognized canonical
  1638. * converter names.
  1639. * @see ucnv_getAvailableName
  1640. * @see uenum_close
  1641. * @see uenum_next
  1642. * @stable ICU 2.4
  1643. */
  1644. U_STABLE UEnumeration * U_EXPORT2
  1645. ucnv_openAllNames(UErrorCode *pErrorCode);
  1646. /**
  1647. * Gives the number of aliases for a given converter or alias name.
  1648. * If the alias is ambiguous, then the preferred converter is used
  1649. * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
  1650. * This method only enumerates the listed entries in the alias file.
  1651. * @param alias alias name
  1652. * @param pErrorCode error status
  1653. * @return number of names on alias list for given alias
  1654. * @stable ICU 2.0
  1655. */
  1656. U_STABLE uint16_t U_EXPORT2
  1657. ucnv_countAliases(const char *alias, UErrorCode *pErrorCode);
  1658. /**
  1659. * Gives the name of the alias at given index of alias list.
  1660. * This method only enumerates the listed entries in the alias file.
  1661. * If the alias is ambiguous, then the preferred converter is used
  1662. * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
  1663. * @param alias alias name
  1664. * @param n index in alias list
  1665. * @param pErrorCode result of operation
  1666. * @return returns the name of the alias at given index
  1667. * @see ucnv_countAliases
  1668. * @stable ICU 2.0
  1669. */
  1670. U_STABLE const char * U_EXPORT2
  1671. ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode);
  1672. /**
  1673. * Fill-up the list of alias names for the given alias.
  1674. * This method only enumerates the listed entries in the alias file.
  1675. * If the alias is ambiguous, then the preferred converter is used
  1676. * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
  1677. * @param alias alias name
  1678. * @param aliases fill-in list, aliases is a pointer to an array of
  1679. * <code>ucnv_countAliases()</code> string-pointers
  1680. * (<code>const char *</code>) that will be filled in.
  1681. * The strings themselves are owned by the library.
  1682. * @param pErrorCode result of operation
  1683. * @stable ICU 2.0
  1684. */
  1685. U_STABLE void U_EXPORT2
  1686. ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode);
  1687. /**
  1688. * Return a new UEnumeration object for enumerating all the
  1689. * alias names for a given converter that are recognized by a standard.
  1690. * This method only enumerates the listed entries in the alias file.
  1691. * The convrtrs.txt file can be modified to change the results of
  1692. * this function.
  1693. * The first result in this list is the same result given by
  1694. * <code>ucnv_getStandardName</code>, which is the default alias for
  1695. * the specified standard name. The returned object must be closed with
  1696. * <code>uenum_close</code> when you are done with the object.
  1697. *
  1698. * @param convName original converter name
  1699. * @param standard name of the standard governing the names; MIME and IANA
  1700. * are such standards
  1701. * @param pErrorCode The error code
  1702. * @return A UEnumeration object for getting all aliases that are recognized
  1703. * by a standard. If any of the parameters are invalid, NULL
  1704. * is returned.
  1705. * @see ucnv_getStandardName
  1706. * @see uenum_close
  1707. * @see uenum_next
  1708. * @stable ICU 2.2
  1709. */
  1710. U_STABLE UEnumeration * U_EXPORT2
  1711. ucnv_openStandardNames(const char *convName,
  1712. const char *standard,
  1713. UErrorCode *pErrorCode);
  1714. /**
  1715. * Gives the number of standards associated to converter names.
  1716. * @return number of standards
  1717. * @stable ICU 2.0
  1718. */
  1719. U_STABLE uint16_t U_EXPORT2
  1720. ucnv_countStandards(void);
  1721. /**
  1722. * Gives the name of the standard at given index of standard list.
  1723. * @param n index in standard list
  1724. * @param pErrorCode result of operation
  1725. * @return returns the name of the standard at given index. Owned by the library.
  1726. * @stable ICU 2.0
  1727. */
  1728. U_STABLE const char * U_EXPORT2
  1729. ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode);
  1730. /**
  1731. * Returns a standard name for a given converter name.
  1732. * <p>
  1733. * Example alias table:<br>
  1734. * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
  1735. * <p>
  1736. * Result of ucnv_getStandardName("conv", "STANDARD1") from example
  1737. * alias table:<br>
  1738. * <b>"alias2"</b>
  1739. *
  1740. * @param name original converter name
  1741. * @param standard name of the standard governing the names; MIME and IANA
  1742. * are such standards
  1743. * @param pErrorCode result of operation
  1744. * @return returns the standard converter name;
  1745. * if a standard converter name cannot be determined,
  1746. * then <code>NULL</code> is returned. Owned by the library.
  1747. * @stable ICU 2.0
  1748. */
  1749. U_STABLE const char * U_EXPORT2
  1750. ucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorCode);
  1751. /**
  1752. * This function will return the internal canonical converter name of the
  1753. * tagged alias. This is the opposite of ucnv_openStandardNames, which
  1754. * returns the tagged alias given the canonical name.
  1755. * <p>
  1756. * Example alias table:<br>
  1757. * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
  1758. * <p>
  1759. * Result of ucnv_getStandardName("alias1", "STANDARD1") from example
  1760. * alias table:<br>
  1761. * <b>"conv"</b>
  1762. *
  1763. * @return returns the canonical converter name;
  1764. * if a standard or alias name cannot be determined,
  1765. * then <code>NULL</code> is returned. The returned string is
  1766. * owned by the library.
  1767. * @see ucnv_getStandardName
  1768. * @stable ICU 2.4
  1769. */
  1770. U_STABLE const char * U_EXPORT2
  1771. ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode);
  1772. /**
  1773. * Returns the current default converter name. If you want to open
  1774. * a default converter, you do not need to use this function.
  1775. * It is faster if you pass a NULL argument to ucnv_open the
  1776. * default converter.
  1777. *
  1778. * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function
  1779. * always returns "UTF-8".
  1780. *
  1781. * @return returns the current default converter name.
  1782. * Storage owned by the library
  1783. * @see ucnv_setDefaultName
  1784. * @stable ICU 2.0
  1785. */
  1786. U_STABLE const char * U_EXPORT2
  1787. ucnv_getDefaultName(void);
  1788. #ifndef U_HIDE_SYSTEM_API
  1789. /**
  1790. * This function is not thread safe. DO NOT call this function when ANY ICU
  1791. * function is being used from more than one thread! This function sets the
  1792. * current default converter name. If this function needs to be called, it
  1793. * should be called during application initialization. Most of the time, the
  1794. * results from ucnv_getDefaultName() or ucnv_open with a NULL string argument
  1795. * is sufficient for your application.
  1796. *
  1797. * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function
  1798. * does nothing.
  1799. *
  1800. * @param name the converter name to be the default (must be known by ICU).
  1801. * @see ucnv_getDefaultName
  1802. * @system
  1803. * @stable ICU 2.0
  1804. */
  1805. U_STABLE void U_EXPORT2
  1806. ucnv_setDefaultName(const char *name);
  1807. #endif /* U_HIDE_SYSTEM_API */
  1808. /**
  1809. * Fixes the backslash character mismapping. For example, in SJIS, the backslash
  1810. * character in the ASCII portion is also used to represent the yen currency sign.
  1811. * When mapping from Unicode character 0x005C, it's unclear whether to map the
  1812. * character back to yen or backslash in SJIS. This function will take the input
  1813. * buffer and replace all the yen sign characters with backslash. This is necessary
  1814. * when the user tries to open a file with the input buffer on Windows.
  1815. * This function will test the converter to see whether such mapping is
  1816. * required. You can sometimes avoid using this function by using the correct version
  1817. * of Shift-JIS.
  1818. *
  1819. * @param cnv The converter representing the target codepage.
  1820. * @param source the input buffer to be fixed
  1821. * @param sourceLen the length of the input buffer
  1822. * @see ucnv_isAmbiguous
  1823. * @stable ICU 2.0
  1824. */
  1825. U_STABLE void U_EXPORT2
  1826. ucnv_fixFileSeparator(const UConverter *cnv, UChar *source, int32_t sourceLen);
  1827. /**
  1828. * Determines if the converter contains ambiguous mappings of the same
  1829. * character or not.
  1830. * @param cnv the converter to be tested
  1831. * @return TRUE if the converter contains ambiguous mapping of the same
  1832. * character, FALSE otherwise.
  1833. * @stable ICU 2.0
  1834. */
  1835. U_STABLE UBool U_EXPORT2
  1836. ucnv_isAmbiguous(const UConverter *cnv);
  1837. /**
  1838. * Sets the converter to use fallback mappings or not.
  1839. * Regardless of this flag, the converter will always use
  1840. * fallbacks from Unicode Private Use code points, as well as
  1841. * reverse fallbacks (to Unicode).
  1842. * For details see ".ucm File Format"
  1843. * in the Conversion Data chapter of the ICU User Guide:
  1844. * http://www.icu-project.org/userguide/conversion-data.html#ucmformat
  1845. *
  1846. * @param cnv The converter to set the fallback mapping usage on.
  1847. * @param usesFallback TRUE if the user wants the converter to take advantage of the fallback
  1848. * mapping, FALSE otherwise.
  1849. * @stable ICU 2.0
  1850. * @see ucnv_usesFallback
  1851. */
  1852. U_STABLE void U_EXPORT2
  1853. ucnv_setFallback(UConverter *cnv, UBool usesFallback);
  1854. /**
  1855. * Determines if the converter uses fallback mappings or not.
  1856. * This flag has restrictions, see ucnv_setFallback().
  1857. *
  1858. * @param cnv The converter to be tested
  1859. * @return TRUE if the converter uses fallback, FALSE otherwise.
  1860. * @stable ICU 2.0
  1861. * @see ucnv_setFallback
  1862. */
  1863. U_STABLE UBool U_EXPORT2
  1864. ucnv_usesFallback(const UConverter *cnv);
  1865. /**
  1866. * Detects Unicode signature byte sequences at the start of the byte stream
  1867. * and returns the charset name of the indicated Unicode charset.
  1868. * NULL is returned when no Unicode signature is recognized.
  1869. * The number of bytes in the signature is output as well.
  1870. *
  1871. * The caller can ucnv_open() a converter using the charset name.
  1872. * The first code unit (UChar) from the start of the stream will be U+FEFF
  1873. * (the Unicode BOM/signature character) and can usually be ignored.
  1874. *
  1875. * For most Unicode charsets it is also possible to ignore the indicated
  1876. * number of initial stream bytes and start converting after them.
  1877. * However, there are stateful Unicode charsets (UTF-7 and BOCU-1) for which
  1878. * this will not work. Therefore, it is best to ignore the first output UChar
  1879. * instead of the input signature bytes.
  1880. * <p>
  1881. * Usage:
  1882. * \snippet samples/ucnv/convsamp.cpp ucnv_detectUnicodeSignature
  1883. *
  1884. * @param source The source string in which the signature should be detected.
  1885. * @param sourceLength Length of the input string, or -1 if terminated with a NUL byte.
  1886. * @param signatureLength A pointer to int32_t to receive the number of bytes that make up the signature
  1887. * of the detected UTF. 0 if not detected.
  1888. * Can be a NULL pointer.
  1889. * @param pErrorCode ICU error code in/out parameter.
  1890. * Must fulfill U_SUCCESS before the function call.
  1891. * @return The name of the encoding detected. NULL if encoding is not detected.
  1892. * @stable ICU 2.4
  1893. */
  1894. U_STABLE const char* U_EXPORT2
  1895. ucnv_detectUnicodeSignature(const char* source,
  1896. int32_t sourceLength,
  1897. int32_t *signatureLength,
  1898. UErrorCode *pErrorCode);
  1899. /**
  1900. * Returns the number of UChars held in the converter's internal state
  1901. * because more input is needed for completing the conversion. This function is
  1902. * useful for mapping semantics of ICU's converter interface to those of iconv,
  1903. * and this information is not needed for normal conversion.
  1904. * @param cnv The converter in which the input is held
  1905. * @param status ICU error code in/out parameter.
  1906. * Must fulfill U_SUCCESS before the function call.
  1907. * @return The number of UChars in the state. -1 if an error is encountered.
  1908. * @stable ICU 3.4
  1909. */
  1910. U_STABLE int32_t U_EXPORT2
  1911. ucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status);
  1912. /**
  1913. * Returns the number of chars held in the converter's internal state
  1914. * because more input is needed for completing the conversion. This function is
  1915. * useful for mapping semantics of ICU's converter interface to those of iconv,
  1916. * and this information is not needed for normal conversion.
  1917. * @param cnv The converter in which the input is held as internal state
  1918. * @param status ICU error code in/out parameter.
  1919. * Must fulfill U_SUCCESS before the function call.
  1920. * @return The number of chars in the state. -1 if an error is encountered.
  1921. * @stable ICU 3.4
  1922. */
  1923. U_STABLE int32_t U_EXPORT2
  1924. ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status);
  1925. /**
  1926. * Returns whether or not the charset of the converter has a fixed number of bytes
  1927. * per charset character.
  1928. * An example of this are converters that are of the type UCNV_SBCS or UCNV_DBCS.
  1929. * Another example is UTF-32 which is always 4 bytes per character.
  1930. * A Unicode code point may be represented by more than one UTF-8 or UTF-16 code unit
  1931. * but a UTF-32 converter encodes each code point with 4 bytes.
  1932. * Note: This method is not intended to be used to determine whether the charset has a
  1933. * fixed ratio of bytes to Unicode codes <i>units</i> for any particular Unicode encoding form.
  1934. * FALSE is returned with the UErrorCode if error occurs or cnv is NULL.
  1935. * @param cnv The converter to be tested
  1936. * @param status ICU error code in/out paramter
  1937. * @return TRUE if the converter is fixed-width
  1938. * @stable ICU 4.8
  1939. */
  1940. U_STABLE UBool U_EXPORT2
  1941. ucnv_isFixedWidth(UConverter *cnv, UErrorCode *status);
  1942. #endif
  1943. #endif
  1944. /*_UCNV*/