ucnv.h 83 KB

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