ucnv.h 83 KB

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