ucnv.h 83 KB

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