ucnv_u32.cpp 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 2002-2015, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. * file name: ucnv_u32.c
  9. * encoding: UTF-8
  10. * tab size: 8 (not used)
  11. * indentation:4
  12. *
  13. * created on: 2002jul01
  14. * created by: Markus W. Scherer
  15. *
  16. * UTF-32 converter implementation. Used to be in ucnv_utf.c.
  17. */
  18. #include "unicode/utypes.h"
  19. #if !UCONFIG_NO_CONVERSION && !UCONFIG_ONLY_HTML_CONVERSION
  20. #include "unicode/ucnv.h"
  21. #include "unicode/utf.h"
  22. #include "ucnv_bld.h"
  23. #include "ucnv_cnv.h"
  24. #include "cmemory.h"
  25. #define MAXIMUM_UCS2 0x0000FFFF
  26. #define MAXIMUM_UTF 0x0010FFFF
  27. #define HALF_SHIFT 10
  28. #define HALF_BASE 0x0010000
  29. #define HALF_MASK 0x3FF
  30. #define SURROGATE_HIGH_START 0xD800
  31. #define SURROGATE_LOW_START 0xDC00
  32. /* -SURROGATE_LOW_START + HALF_BASE */
  33. #define SURROGATE_LOW_BASE 9216
  34. enum {
  35. UCNV_NEED_TO_WRITE_BOM=1
  36. };
  37. /* UTF-32BE ----------------------------------------------------------------- */
  38. U_CDECL_BEGIN
  39. static void U_CALLCONV
  40. T_UConverter_toUnicode_UTF32_BE(UConverterToUnicodeArgs * args,
  41. UErrorCode * err)
  42. {
  43. const unsigned char *mySource = (unsigned char *) args->source;
  44. char16_t *myTarget = args->target;
  45. const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit;
  46. const char16_t *targetLimit = args->targetLimit;
  47. unsigned char *toUBytes = args->converter->toUBytes;
  48. uint32_t ch, i;
  49. /* Restore state of current sequence */
  50. if (args->converter->toULength > 0 && myTarget < targetLimit) {
  51. i = args->converter->toULength; /* restore # of bytes consumed */
  52. args->converter->toULength = 0;
  53. ch = args->converter->toUnicodeStatus - 1;/*Stores the previously calculated ch from a previous call*/
  54. args->converter->toUnicodeStatus = 0;
  55. goto morebytes;
  56. }
  57. while (mySource < sourceLimit && myTarget < targetLimit) {
  58. i = 0;
  59. ch = 0;
  60. morebytes:
  61. while (i < sizeof(uint32_t)) {
  62. if (mySource < sourceLimit) {
  63. ch = (ch << 8) | (uint8_t)(*mySource);
  64. toUBytes[i++] = (char) *(mySource++);
  65. }
  66. else {
  67. /* stores a partially calculated target*/
  68. /* + 1 to make 0 a valid character */
  69. args->converter->toUnicodeStatus = ch + 1;
  70. args->converter->toULength = (int8_t) i;
  71. goto donefornow;
  72. }
  73. }
  74. if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch)) {
  75. /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
  76. if (ch <= MAXIMUM_UCS2)
  77. {
  78. /* fits in 16 bits */
  79. *(myTarget++) = (char16_t) ch;
  80. }
  81. else {
  82. /* write out the surrogates */
  83. *(myTarget++) = U16_LEAD(ch);
  84. ch = U16_TRAIL(ch);
  85. if (myTarget < targetLimit) {
  86. *(myTarget++) = (char16_t)ch;
  87. }
  88. else {
  89. /* Put in overflow buffer (not handled here) */
  90. args->converter->UCharErrorBuffer[0] = (char16_t) ch;
  91. args->converter->UCharErrorBufferLength = 1;
  92. *err = U_BUFFER_OVERFLOW_ERROR;
  93. break;
  94. }
  95. }
  96. }
  97. else {
  98. args->converter->toULength = (int8_t)i;
  99. *err = U_ILLEGAL_CHAR_FOUND;
  100. break;
  101. }
  102. }
  103. donefornow:
  104. if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err)) {
  105. /* End of target buffer */
  106. *err = U_BUFFER_OVERFLOW_ERROR;
  107. }
  108. args->target = myTarget;
  109. args->source = (const char *) mySource;
  110. }
  111. static void U_CALLCONV
  112. T_UConverter_toUnicode_UTF32_BE_OFFSET_LOGIC(UConverterToUnicodeArgs * args,
  113. UErrorCode * err)
  114. {
  115. const unsigned char *mySource = (unsigned char *) args->source;
  116. char16_t *myTarget = args->target;
  117. int32_t *myOffsets = args->offsets;
  118. const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit;
  119. const char16_t *targetLimit = args->targetLimit;
  120. unsigned char *toUBytes = args->converter->toUBytes;
  121. uint32_t ch, i;
  122. int32_t offsetNum = 0;
  123. /* Restore state of current sequence */
  124. if (args->converter->toULength > 0 && myTarget < targetLimit) {
  125. i = args->converter->toULength; /* restore # of bytes consumed */
  126. args->converter->toULength = 0;
  127. ch = args->converter->toUnicodeStatus - 1;/*Stores the previously calculated ch from a previous call*/
  128. args->converter->toUnicodeStatus = 0;
  129. goto morebytes;
  130. }
  131. while (mySource < sourceLimit && myTarget < targetLimit) {
  132. i = 0;
  133. ch = 0;
  134. morebytes:
  135. while (i < sizeof(uint32_t)) {
  136. if (mySource < sourceLimit) {
  137. ch = (ch << 8) | (uint8_t)(*mySource);
  138. toUBytes[i++] = (char) *(mySource++);
  139. }
  140. else {
  141. /* stores a partially calculated target*/
  142. /* + 1 to make 0 a valid character */
  143. args->converter->toUnicodeStatus = ch + 1;
  144. args->converter->toULength = (int8_t) i;
  145. goto donefornow;
  146. }
  147. }
  148. if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch)) {
  149. /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
  150. if (ch <= MAXIMUM_UCS2) {
  151. /* fits in 16 bits */
  152. *(myTarget++) = (char16_t) ch;
  153. *(myOffsets++) = offsetNum;
  154. }
  155. else {
  156. /* write out the surrogates */
  157. *(myTarget++) = U16_LEAD(ch);
  158. *myOffsets++ = offsetNum;
  159. ch = U16_TRAIL(ch);
  160. if (myTarget < targetLimit)
  161. {
  162. *(myTarget++) = (char16_t)ch;
  163. *(myOffsets++) = offsetNum;
  164. }
  165. else {
  166. /* Put in overflow buffer (not handled here) */
  167. args->converter->UCharErrorBuffer[0] = (char16_t) ch;
  168. args->converter->UCharErrorBufferLength = 1;
  169. *err = U_BUFFER_OVERFLOW_ERROR;
  170. break;
  171. }
  172. }
  173. }
  174. else {
  175. args->converter->toULength = (int8_t)i;
  176. *err = U_ILLEGAL_CHAR_FOUND;
  177. break;
  178. }
  179. offsetNum += i;
  180. }
  181. donefornow:
  182. if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
  183. {
  184. /* End of target buffer */
  185. *err = U_BUFFER_OVERFLOW_ERROR;
  186. }
  187. args->target = myTarget;
  188. args->source = (const char *) mySource;
  189. args->offsets = myOffsets;
  190. }
  191. static void U_CALLCONV
  192. T_UConverter_fromUnicode_UTF32_BE(UConverterFromUnicodeArgs * args,
  193. UErrorCode * err)
  194. {
  195. const char16_t *mySource = args->source;
  196. unsigned char *myTarget;
  197. const char16_t *sourceLimit = args->sourceLimit;
  198. const unsigned char *targetLimit = (unsigned char *) args->targetLimit;
  199. UChar32 ch, ch2;
  200. unsigned int indexToWrite;
  201. unsigned char temp[sizeof(uint32_t)];
  202. if(mySource >= sourceLimit) {
  203. /* no input, nothing to do */
  204. return;
  205. }
  206. /* write the BOM if necessary */
  207. if(args->converter->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
  208. static const char bom[]={ 0, 0, (char)0xfeu, (char)0xffu };
  209. ucnv_fromUWriteBytes(args->converter,
  210. bom, 4,
  211. &args->target, args->targetLimit,
  212. &args->offsets, -1,
  213. err);
  214. args->converter->fromUnicodeStatus=0;
  215. }
  216. myTarget = (unsigned char *) args->target;
  217. temp[0] = 0;
  218. if (args->converter->fromUChar32) {
  219. ch = args->converter->fromUChar32;
  220. args->converter->fromUChar32 = 0;
  221. goto lowsurogate;
  222. }
  223. while (mySource < sourceLimit && myTarget < targetLimit) {
  224. ch = *(mySource++);
  225. if (U_IS_SURROGATE(ch)) {
  226. if (U_IS_LEAD(ch)) {
  227. lowsurogate:
  228. if (mySource < sourceLimit) {
  229. ch2 = *mySource;
  230. if (U_IS_TRAIL(ch2)) {
  231. ch = ((ch - SURROGATE_HIGH_START) << HALF_SHIFT) + ch2 + SURROGATE_LOW_BASE;
  232. mySource++;
  233. }
  234. else {
  235. /* this is an unmatched trail code unit (2nd surrogate) */
  236. /* callback(illegal) */
  237. args->converter->fromUChar32 = ch;
  238. *err = U_ILLEGAL_CHAR_FOUND;
  239. break;
  240. }
  241. }
  242. else {
  243. /* ran out of source */
  244. args->converter->fromUChar32 = ch;
  245. if (args->flush) {
  246. /* this is an unmatched trail code unit (2nd surrogate) */
  247. /* callback(illegal) */
  248. *err = U_ILLEGAL_CHAR_FOUND;
  249. }
  250. break;
  251. }
  252. }
  253. else {
  254. /* this is an unmatched trail code unit (2nd surrogate) */
  255. /* callback(illegal) */
  256. args->converter->fromUChar32 = ch;
  257. *err = U_ILLEGAL_CHAR_FOUND;
  258. break;
  259. }
  260. }
  261. /* We cannot get any larger than 10FFFF because we are coming from UTF-16 */
  262. temp[1] = (uint8_t) (ch >> 16 & 0x1F);
  263. temp[2] = (uint8_t) (ch >> 8); /* unsigned cast implicitly does (ch & FF) */
  264. temp[3] = (uint8_t) (ch); /* unsigned cast implicitly does (ch & FF) */
  265. for (indexToWrite = 0; indexToWrite <= sizeof(uint32_t) - 1; indexToWrite++) {
  266. if (myTarget < targetLimit) {
  267. *(myTarget++) = temp[indexToWrite];
  268. }
  269. else {
  270. args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = temp[indexToWrite];
  271. *err = U_BUFFER_OVERFLOW_ERROR;
  272. }
  273. }
  274. }
  275. if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err)) {
  276. *err = U_BUFFER_OVERFLOW_ERROR;
  277. }
  278. args->target = (char *) myTarget;
  279. args->source = mySource;
  280. }
  281. static void U_CALLCONV
  282. T_UConverter_fromUnicode_UTF32_BE_OFFSET_LOGIC(UConverterFromUnicodeArgs * args,
  283. UErrorCode * err)
  284. {
  285. const char16_t *mySource = args->source;
  286. unsigned char *myTarget;
  287. int32_t *myOffsets;
  288. const char16_t *sourceLimit = args->sourceLimit;
  289. const unsigned char *targetLimit = (unsigned char *) args->targetLimit;
  290. UChar32 ch, ch2;
  291. int32_t offsetNum = 0;
  292. unsigned int indexToWrite;
  293. unsigned char temp[sizeof(uint32_t)];
  294. if(mySource >= sourceLimit) {
  295. /* no input, nothing to do */
  296. return;
  297. }
  298. /* write the BOM if necessary */
  299. if(args->converter->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
  300. static const char bom[]={ 0, 0, (char)0xfeu, (char)0xffu };
  301. ucnv_fromUWriteBytes(args->converter,
  302. bom, 4,
  303. &args->target, args->targetLimit,
  304. &args->offsets, -1,
  305. err);
  306. args->converter->fromUnicodeStatus=0;
  307. }
  308. myTarget = (unsigned char *) args->target;
  309. myOffsets = args->offsets;
  310. temp[0] = 0;
  311. if (args->converter->fromUChar32) {
  312. ch = args->converter->fromUChar32;
  313. args->converter->fromUChar32 = 0;
  314. goto lowsurogate;
  315. }
  316. while (mySource < sourceLimit && myTarget < targetLimit) {
  317. ch = *(mySource++);
  318. if (U_IS_SURROGATE(ch)) {
  319. if (U_IS_LEAD(ch)) {
  320. lowsurogate:
  321. if (mySource < sourceLimit) {
  322. ch2 = *mySource;
  323. if (U_IS_TRAIL(ch2)) {
  324. ch = ((ch - SURROGATE_HIGH_START) << HALF_SHIFT) + ch2 + SURROGATE_LOW_BASE;
  325. mySource++;
  326. }
  327. else {
  328. /* this is an unmatched trail code unit (2nd surrogate) */
  329. /* callback(illegal) */
  330. args->converter->fromUChar32 = ch;
  331. *err = U_ILLEGAL_CHAR_FOUND;
  332. break;
  333. }
  334. }
  335. else {
  336. /* ran out of source */
  337. args->converter->fromUChar32 = ch;
  338. if (args->flush) {
  339. /* this is an unmatched trail code unit (2nd surrogate) */
  340. /* callback(illegal) */
  341. *err = U_ILLEGAL_CHAR_FOUND;
  342. }
  343. break;
  344. }
  345. }
  346. else {
  347. /* this is an unmatched trail code unit (2nd surrogate) */
  348. /* callback(illegal) */
  349. args->converter->fromUChar32 = ch;
  350. *err = U_ILLEGAL_CHAR_FOUND;
  351. break;
  352. }
  353. }
  354. /* We cannot get any larger than 10FFFF because we are coming from UTF-16 */
  355. temp[1] = (uint8_t) (ch >> 16 & 0x1F);
  356. temp[2] = (uint8_t) (ch >> 8); /* unsigned cast implicitly does (ch & FF) */
  357. temp[3] = (uint8_t) (ch); /* unsigned cast implicitly does (ch & FF) */
  358. for (indexToWrite = 0; indexToWrite <= sizeof(uint32_t) - 1; indexToWrite++) {
  359. if (myTarget < targetLimit) {
  360. *(myTarget++) = temp[indexToWrite];
  361. *(myOffsets++) = offsetNum;
  362. }
  363. else {
  364. args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = temp[indexToWrite];
  365. *err = U_BUFFER_OVERFLOW_ERROR;
  366. }
  367. }
  368. offsetNum = offsetNum + 1 + (temp[1] != 0);
  369. }
  370. if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err)) {
  371. *err = U_BUFFER_OVERFLOW_ERROR;
  372. }
  373. args->target = (char *) myTarget;
  374. args->source = mySource;
  375. args->offsets = myOffsets;
  376. }
  377. static UChar32 U_CALLCONV
  378. T_UConverter_getNextUChar_UTF32_BE(UConverterToUnicodeArgs* args,
  379. UErrorCode* err)
  380. {
  381. const uint8_t *mySource;
  382. UChar32 myUChar;
  383. int32_t length;
  384. mySource = (const uint8_t *)args->source;
  385. if (mySource >= (const uint8_t *)args->sourceLimit)
  386. {
  387. /* no input */
  388. *err = U_INDEX_OUTOFBOUNDS_ERROR;
  389. return 0xffff;
  390. }
  391. length = (int32_t)((const uint8_t *)args->sourceLimit - mySource);
  392. if (length < 4)
  393. {
  394. /* got a partial character */
  395. uprv_memcpy(args->converter->toUBytes, mySource, length);
  396. args->converter->toULength = (int8_t)length;
  397. args->source = (const char *)(mySource + length);
  398. *err = U_TRUNCATED_CHAR_FOUND;
  399. return 0xffff;
  400. }
  401. /* Don't even try to do a direct cast because the value may be on an odd address. */
  402. myUChar = ((UChar32)mySource[0] << 24)
  403. | ((UChar32)mySource[1] << 16)
  404. | ((UChar32)mySource[2] << 8)
  405. | ((UChar32)mySource[3]);
  406. args->source = (const char *)(mySource + 4);
  407. if ((uint32_t)myUChar <= MAXIMUM_UTF && !U_IS_SURROGATE(myUChar)) {
  408. return myUChar;
  409. }
  410. uprv_memcpy(args->converter->toUBytes, mySource, 4);
  411. args->converter->toULength = 4;
  412. *err = U_ILLEGAL_CHAR_FOUND;
  413. return 0xffff;
  414. }
  415. U_CDECL_END
  416. static const UConverterImpl _UTF32BEImpl = {
  417. UCNV_UTF32_BigEndian,
  418. nullptr,
  419. nullptr,
  420. nullptr,
  421. nullptr,
  422. nullptr,
  423. T_UConverter_toUnicode_UTF32_BE,
  424. T_UConverter_toUnicode_UTF32_BE_OFFSET_LOGIC,
  425. T_UConverter_fromUnicode_UTF32_BE,
  426. T_UConverter_fromUnicode_UTF32_BE_OFFSET_LOGIC,
  427. T_UConverter_getNextUChar_UTF32_BE,
  428. nullptr,
  429. nullptr,
  430. nullptr,
  431. nullptr,
  432. ucnv_getNonSurrogateUnicodeSet,
  433. nullptr,
  434. nullptr
  435. };
  436. /* The 1232 CCSID refers to any version of Unicode with any endianness of UTF-32 */
  437. static const UConverterStaticData _UTF32BEStaticData = {
  438. sizeof(UConverterStaticData),
  439. "UTF-32BE",
  440. 1232,
  441. UCNV_IBM, UCNV_UTF32_BigEndian, 4, 4,
  442. { 0, 0, 0xff, 0xfd }, 4, false, false,
  443. 0,
  444. 0,
  445. { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
  446. };
  447. const UConverterSharedData _UTF32BEData =
  448. UCNV_IMMUTABLE_SHARED_DATA_INITIALIZER(&_UTF32BEStaticData, &_UTF32BEImpl);
  449. /* UTF-32LE ---------------------------------------------------------- */
  450. U_CDECL_BEGIN
  451. static void U_CALLCONV
  452. T_UConverter_toUnicode_UTF32_LE(UConverterToUnicodeArgs * args,
  453. UErrorCode * err)
  454. {
  455. const unsigned char *mySource = (unsigned char *) args->source;
  456. char16_t *myTarget = args->target;
  457. const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit;
  458. const char16_t *targetLimit = args->targetLimit;
  459. unsigned char *toUBytes = args->converter->toUBytes;
  460. uint32_t ch, i;
  461. /* Restore state of current sequence */
  462. if (args->converter->toULength > 0 && myTarget < targetLimit)
  463. {
  464. i = args->converter->toULength; /* restore # of bytes consumed */
  465. args->converter->toULength = 0;
  466. /* Stores the previously calculated ch from a previous call*/
  467. ch = args->converter->toUnicodeStatus - 1;
  468. args->converter->toUnicodeStatus = 0;
  469. goto morebytes;
  470. }
  471. while (mySource < sourceLimit && myTarget < targetLimit)
  472. {
  473. i = 0;
  474. ch = 0;
  475. morebytes:
  476. while (i < sizeof(uint32_t))
  477. {
  478. if (mySource < sourceLimit)
  479. {
  480. ch |= ((uint8_t)(*mySource)) << (i * 8);
  481. toUBytes[i++] = (char) *(mySource++);
  482. }
  483. else
  484. {
  485. /* stores a partially calculated target*/
  486. /* + 1 to make 0 a valid character */
  487. args->converter->toUnicodeStatus = ch + 1;
  488. args->converter->toULength = (int8_t) i;
  489. goto donefornow;
  490. }
  491. }
  492. if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch)) {
  493. /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
  494. if (ch <= MAXIMUM_UCS2) {
  495. /* fits in 16 bits */
  496. *(myTarget++) = (char16_t) ch;
  497. }
  498. else {
  499. /* write out the surrogates */
  500. *(myTarget++) = U16_LEAD(ch);
  501. ch = U16_TRAIL(ch);
  502. if (myTarget < targetLimit) {
  503. *(myTarget++) = (char16_t)ch;
  504. }
  505. else {
  506. /* Put in overflow buffer (not handled here) */
  507. args->converter->UCharErrorBuffer[0] = (char16_t) ch;
  508. args->converter->UCharErrorBufferLength = 1;
  509. *err = U_BUFFER_OVERFLOW_ERROR;
  510. break;
  511. }
  512. }
  513. }
  514. else {
  515. args->converter->toULength = (int8_t)i;
  516. *err = U_ILLEGAL_CHAR_FOUND;
  517. break;
  518. }
  519. }
  520. donefornow:
  521. if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
  522. {
  523. /* End of target buffer */
  524. *err = U_BUFFER_OVERFLOW_ERROR;
  525. }
  526. args->target = myTarget;
  527. args->source = (const char *) mySource;
  528. }
  529. static void U_CALLCONV
  530. T_UConverter_toUnicode_UTF32_LE_OFFSET_LOGIC(UConverterToUnicodeArgs * args,
  531. UErrorCode * err)
  532. {
  533. const unsigned char *mySource = (unsigned char *) args->source;
  534. char16_t *myTarget = args->target;
  535. int32_t *myOffsets = args->offsets;
  536. const unsigned char *sourceLimit = (unsigned char *) args->sourceLimit;
  537. const char16_t *targetLimit = args->targetLimit;
  538. unsigned char *toUBytes = args->converter->toUBytes;
  539. uint32_t ch, i;
  540. int32_t offsetNum = 0;
  541. /* Restore state of current sequence */
  542. if (args->converter->toULength > 0 && myTarget < targetLimit)
  543. {
  544. i = args->converter->toULength; /* restore # of bytes consumed */
  545. args->converter->toULength = 0;
  546. /* Stores the previously calculated ch from a previous call*/
  547. ch = args->converter->toUnicodeStatus - 1;
  548. args->converter->toUnicodeStatus = 0;
  549. goto morebytes;
  550. }
  551. while (mySource < sourceLimit && myTarget < targetLimit)
  552. {
  553. i = 0;
  554. ch = 0;
  555. morebytes:
  556. while (i < sizeof(uint32_t))
  557. {
  558. if (mySource < sourceLimit)
  559. {
  560. ch |= ((uint8_t)(*mySource)) << (i * 8);
  561. toUBytes[i++] = (char) *(mySource++);
  562. }
  563. else
  564. {
  565. /* stores a partially calculated target*/
  566. /* + 1 to make 0 a valid character */
  567. args->converter->toUnicodeStatus = ch + 1;
  568. args->converter->toULength = (int8_t) i;
  569. goto donefornow;
  570. }
  571. }
  572. if (ch <= MAXIMUM_UTF && !U_IS_SURROGATE(ch))
  573. {
  574. /* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
  575. if (ch <= MAXIMUM_UCS2)
  576. {
  577. /* fits in 16 bits */
  578. *(myTarget++) = (char16_t) ch;
  579. *(myOffsets++) = offsetNum;
  580. }
  581. else {
  582. /* write out the surrogates */
  583. *(myTarget++) = U16_LEAD(ch);
  584. *(myOffsets++) = offsetNum;
  585. ch = U16_TRAIL(ch);
  586. if (myTarget < targetLimit)
  587. {
  588. *(myTarget++) = (char16_t)ch;
  589. *(myOffsets++) = offsetNum;
  590. }
  591. else
  592. {
  593. /* Put in overflow buffer (not handled here) */
  594. args->converter->UCharErrorBuffer[0] = (char16_t) ch;
  595. args->converter->UCharErrorBufferLength = 1;
  596. *err = U_BUFFER_OVERFLOW_ERROR;
  597. break;
  598. }
  599. }
  600. }
  601. else
  602. {
  603. args->converter->toULength = (int8_t)i;
  604. *err = U_ILLEGAL_CHAR_FOUND;
  605. break;
  606. }
  607. offsetNum += i;
  608. }
  609. donefornow:
  610. if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
  611. {
  612. /* End of target buffer */
  613. *err = U_BUFFER_OVERFLOW_ERROR;
  614. }
  615. args->target = myTarget;
  616. args->source = (const char *) mySource;
  617. args->offsets = myOffsets;
  618. }
  619. static void U_CALLCONV
  620. T_UConverter_fromUnicode_UTF32_LE(UConverterFromUnicodeArgs * args,
  621. UErrorCode * err)
  622. {
  623. const char16_t *mySource = args->source;
  624. unsigned char *myTarget;
  625. const char16_t *sourceLimit = args->sourceLimit;
  626. const unsigned char *targetLimit = (unsigned char *) args->targetLimit;
  627. UChar32 ch, ch2;
  628. unsigned int indexToWrite;
  629. unsigned char temp[sizeof(uint32_t)];
  630. if(mySource >= sourceLimit) {
  631. /* no input, nothing to do */
  632. return;
  633. }
  634. /* write the BOM if necessary */
  635. if(args->converter->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
  636. static const char bom[]={ (char)0xffu, (char)0xfeu, 0, 0 };
  637. ucnv_fromUWriteBytes(args->converter,
  638. bom, 4,
  639. &args->target, args->targetLimit,
  640. &args->offsets, -1,
  641. err);
  642. args->converter->fromUnicodeStatus=0;
  643. }
  644. myTarget = (unsigned char *) args->target;
  645. temp[3] = 0;
  646. if (args->converter->fromUChar32)
  647. {
  648. ch = args->converter->fromUChar32;
  649. args->converter->fromUChar32 = 0;
  650. goto lowsurogate;
  651. }
  652. while (mySource < sourceLimit && myTarget < targetLimit)
  653. {
  654. ch = *(mySource++);
  655. if (U16_IS_SURROGATE(ch)) {
  656. if (U16_IS_LEAD(ch))
  657. {
  658. lowsurogate:
  659. if (mySource < sourceLimit)
  660. {
  661. ch2 = *mySource;
  662. if (U16_IS_TRAIL(ch2)) {
  663. ch = ((ch - SURROGATE_HIGH_START) << HALF_SHIFT) + ch2 + SURROGATE_LOW_BASE;
  664. mySource++;
  665. }
  666. else {
  667. /* this is an unmatched trail code unit (2nd surrogate) */
  668. /* callback(illegal) */
  669. args->converter->fromUChar32 = ch;
  670. *err = U_ILLEGAL_CHAR_FOUND;
  671. break;
  672. }
  673. }
  674. else {
  675. /* ran out of source */
  676. args->converter->fromUChar32 = ch;
  677. if (args->flush) {
  678. /* this is an unmatched trail code unit (2nd surrogate) */
  679. /* callback(illegal) */
  680. *err = U_ILLEGAL_CHAR_FOUND;
  681. }
  682. break;
  683. }
  684. }
  685. else {
  686. /* this is an unmatched trail code unit (2nd surrogate) */
  687. /* callback(illegal) */
  688. args->converter->fromUChar32 = ch;
  689. *err = U_ILLEGAL_CHAR_FOUND;
  690. break;
  691. }
  692. }
  693. /* We cannot get any larger than 10FFFF because we are coming from UTF-16 */
  694. temp[2] = (uint8_t) (ch >> 16 & 0x1F);
  695. temp[1] = (uint8_t) (ch >> 8); /* unsigned cast implicitly does (ch & FF) */
  696. temp[0] = (uint8_t) (ch); /* unsigned cast implicitly does (ch & FF) */
  697. for (indexToWrite = 0; indexToWrite <= sizeof(uint32_t) - 1; indexToWrite++)
  698. {
  699. if (myTarget < targetLimit)
  700. {
  701. *(myTarget++) = temp[indexToWrite];
  702. }
  703. else
  704. {
  705. args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = temp[indexToWrite];
  706. *err = U_BUFFER_OVERFLOW_ERROR;
  707. }
  708. }
  709. }
  710. if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
  711. {
  712. *err = U_BUFFER_OVERFLOW_ERROR;
  713. }
  714. args->target = (char *) myTarget;
  715. args->source = mySource;
  716. }
  717. static void U_CALLCONV
  718. T_UConverter_fromUnicode_UTF32_LE_OFFSET_LOGIC(UConverterFromUnicodeArgs * args,
  719. UErrorCode * err)
  720. {
  721. const char16_t *mySource = args->source;
  722. unsigned char *myTarget;
  723. int32_t *myOffsets;
  724. const char16_t *sourceLimit = args->sourceLimit;
  725. const unsigned char *targetLimit = (unsigned char *) args->targetLimit;
  726. UChar32 ch, ch2;
  727. unsigned int indexToWrite;
  728. unsigned char temp[sizeof(uint32_t)];
  729. int32_t offsetNum = 0;
  730. if(mySource >= sourceLimit) {
  731. /* no input, nothing to do */
  732. return;
  733. }
  734. /* write the BOM if necessary */
  735. if(args->converter->fromUnicodeStatus==UCNV_NEED_TO_WRITE_BOM) {
  736. static const char bom[]={ (char)0xffu, (char)0xfeu, 0, 0 };
  737. ucnv_fromUWriteBytes(args->converter,
  738. bom, 4,
  739. &args->target, args->targetLimit,
  740. &args->offsets, -1,
  741. err);
  742. args->converter->fromUnicodeStatus=0;
  743. }
  744. myTarget = (unsigned char *) args->target;
  745. myOffsets = args->offsets;
  746. temp[3] = 0;
  747. if (args->converter->fromUChar32)
  748. {
  749. ch = args->converter->fromUChar32;
  750. args->converter->fromUChar32 = 0;
  751. goto lowsurogate;
  752. }
  753. while (mySource < sourceLimit && myTarget < targetLimit)
  754. {
  755. ch = *(mySource++);
  756. if (U16_IS_SURROGATE(ch)) {
  757. if (U16_IS_LEAD(ch))
  758. {
  759. lowsurogate:
  760. if (mySource < sourceLimit)
  761. {
  762. ch2 = *mySource;
  763. if (U16_IS_TRAIL(ch2))
  764. {
  765. ch = ((ch - SURROGATE_HIGH_START) << HALF_SHIFT) + ch2 + SURROGATE_LOW_BASE;
  766. mySource++;
  767. }
  768. else {
  769. /* this is an unmatched trail code unit (2nd surrogate) */
  770. /* callback(illegal) */
  771. args->converter->fromUChar32 = ch;
  772. *err = U_ILLEGAL_CHAR_FOUND;
  773. break;
  774. }
  775. }
  776. else {
  777. /* ran out of source */
  778. args->converter->fromUChar32 = ch;
  779. if (args->flush) {
  780. /* this is an unmatched trail code unit (2nd surrogate) */
  781. /* callback(illegal) */
  782. *err = U_ILLEGAL_CHAR_FOUND;
  783. }
  784. break;
  785. }
  786. }
  787. else {
  788. /* this is an unmatched trail code unit (2nd surrogate) */
  789. /* callback(illegal) */
  790. args->converter->fromUChar32 = ch;
  791. *err = U_ILLEGAL_CHAR_FOUND;
  792. break;
  793. }
  794. }
  795. /* We cannot get any larger than 10FFFF because we are coming from UTF-16 */
  796. temp[2] = (uint8_t) (ch >> 16 & 0x1F);
  797. temp[1] = (uint8_t) (ch >> 8); /* unsigned cast implicitly does (ch & FF) */
  798. temp[0] = (uint8_t) (ch); /* unsigned cast implicitly does (ch & FF) */
  799. for (indexToWrite = 0; indexToWrite <= sizeof(uint32_t) - 1; indexToWrite++)
  800. {
  801. if (myTarget < targetLimit)
  802. {
  803. *(myTarget++) = temp[indexToWrite];
  804. *(myOffsets++) = offsetNum;
  805. }
  806. else
  807. {
  808. args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = temp[indexToWrite];
  809. *err = U_BUFFER_OVERFLOW_ERROR;
  810. }
  811. }
  812. offsetNum = offsetNum + 1 + (temp[2] != 0);
  813. }
  814. if (mySource < sourceLimit && myTarget >= targetLimit && U_SUCCESS(*err))
  815. {
  816. *err = U_BUFFER_OVERFLOW_ERROR;
  817. }
  818. args->target = (char *) myTarget;
  819. args->source = mySource;
  820. args->offsets = myOffsets;
  821. }
  822. static UChar32 U_CALLCONV
  823. T_UConverter_getNextUChar_UTF32_LE(UConverterToUnicodeArgs* args,
  824. UErrorCode* err)
  825. {
  826. const uint8_t *mySource;
  827. UChar32 myUChar;
  828. int32_t length;
  829. mySource = (const uint8_t *)args->source;
  830. if (mySource >= (const uint8_t *)args->sourceLimit)
  831. {
  832. /* no input */
  833. *err = U_INDEX_OUTOFBOUNDS_ERROR;
  834. return 0xffff;
  835. }
  836. length = (int32_t)((const uint8_t *)args->sourceLimit - mySource);
  837. if (length < 4)
  838. {
  839. /* got a partial character */
  840. uprv_memcpy(args->converter->toUBytes, mySource, length);
  841. args->converter->toULength = (int8_t)length;
  842. args->source = (const char *)(mySource + length);
  843. *err = U_TRUNCATED_CHAR_FOUND;
  844. return 0xffff;
  845. }
  846. /* Don't even try to do a direct cast because the value may be on an odd address. */
  847. myUChar = ((UChar32)mySource[3] << 24)
  848. | ((UChar32)mySource[2] << 16)
  849. | ((UChar32)mySource[1] << 8)
  850. | ((UChar32)mySource[0]);
  851. args->source = (const char *)(mySource + 4);
  852. if ((uint32_t)myUChar <= MAXIMUM_UTF && !U_IS_SURROGATE(myUChar)) {
  853. return myUChar;
  854. }
  855. uprv_memcpy(args->converter->toUBytes, mySource, 4);
  856. args->converter->toULength = 4;
  857. *err = U_ILLEGAL_CHAR_FOUND;
  858. return 0xffff;
  859. }
  860. U_CDECL_END
  861. static const UConverterImpl _UTF32LEImpl = {
  862. UCNV_UTF32_LittleEndian,
  863. nullptr,
  864. nullptr,
  865. nullptr,
  866. nullptr,
  867. nullptr,
  868. T_UConverter_toUnicode_UTF32_LE,
  869. T_UConverter_toUnicode_UTF32_LE_OFFSET_LOGIC,
  870. T_UConverter_fromUnicode_UTF32_LE,
  871. T_UConverter_fromUnicode_UTF32_LE_OFFSET_LOGIC,
  872. T_UConverter_getNextUChar_UTF32_LE,
  873. nullptr,
  874. nullptr,
  875. nullptr,
  876. nullptr,
  877. ucnv_getNonSurrogateUnicodeSet,
  878. nullptr,
  879. nullptr
  880. };
  881. /* The 1232 CCSID refers to any version of Unicode with any endianness of UTF-32 */
  882. static const UConverterStaticData _UTF32LEStaticData = {
  883. sizeof(UConverterStaticData),
  884. "UTF-32LE",
  885. 1234,
  886. UCNV_IBM, UCNV_UTF32_LittleEndian, 4, 4,
  887. { 0xfd, 0xff, 0, 0 }, 4, false, false,
  888. 0,
  889. 0,
  890. { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
  891. };
  892. const UConverterSharedData _UTF32LEData =
  893. UCNV_IMMUTABLE_SHARED_DATA_INITIALIZER(&_UTF32LEStaticData, &_UTF32LEImpl);
  894. /* UTF-32 (Detect BOM) ------------------------------------------------------ */
  895. /*
  896. * Detect a BOM at the beginning of the stream and select UTF-32BE or UTF-32LE
  897. * accordingly.
  898. *
  899. * State values:
  900. * 0 initial state
  901. * 1 saw 00
  902. * 2 saw 00 00
  903. * 3 saw 00 00 FE
  904. * 4 -
  905. * 5 saw FF
  906. * 6 saw FF FE
  907. * 7 saw FF FE 00
  908. * 8 UTF-32BE mode
  909. * 9 UTF-32LE mode
  910. *
  911. * During detection: state&3==number of matching bytes so far.
  912. *
  913. * On output, emit U+FEFF as the first code point.
  914. */
  915. U_CDECL_BEGIN
  916. static void U_CALLCONV
  917. _UTF32Reset(UConverter *cnv, UConverterResetChoice choice) {
  918. if(choice<=UCNV_RESET_TO_UNICODE) {
  919. /* reset toUnicode: state=0 */
  920. cnv->mode=0;
  921. }
  922. if(choice!=UCNV_RESET_TO_UNICODE) {
  923. /* reset fromUnicode: prepare to output the UTF-32PE BOM */
  924. cnv->fromUnicodeStatus=UCNV_NEED_TO_WRITE_BOM;
  925. }
  926. }
  927. static void U_CALLCONV
  928. _UTF32Open(UConverter *cnv,
  929. UConverterLoadArgs *pArgs,
  930. UErrorCode *pErrorCode) {
  931. (void)pArgs;
  932. (void)pErrorCode;
  933. _UTF32Reset(cnv, UCNV_RESET_BOTH);
  934. }
  935. static const char utf32BOM[8]={ 0, 0, (char)0xfeu, (char)0xffu, (char)0xffu, (char)0xfeu, 0, 0 };
  936. static void U_CALLCONV
  937. _UTF32ToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
  938. UErrorCode *pErrorCode) {
  939. UConverter *cnv=pArgs->converter;
  940. const char *source=pArgs->source;
  941. const char *sourceLimit=pArgs->sourceLimit;
  942. int32_t *offsets=pArgs->offsets;
  943. int32_t state, offsetDelta;
  944. char b;
  945. state=cnv->mode;
  946. /*
  947. * If we detect a BOM in this buffer, then we must add the BOM size to the
  948. * offsets because the actual converter function will not see and count the BOM.
  949. * offsetDelta will have the number of the BOM bytes that are in the current buffer.
  950. */
  951. offsetDelta=0;
  952. while(source<sourceLimit && U_SUCCESS(*pErrorCode)) {
  953. switch(state) {
  954. case 0:
  955. b=*source;
  956. if(b==0) {
  957. state=1; /* could be 00 00 FE FF */
  958. } else if(b==(char)0xffu) {
  959. state=5; /* could be FF FE 00 00 */
  960. } else {
  961. state=8; /* default to UTF-32BE */
  962. continue;
  963. }
  964. ++source;
  965. break;
  966. case 1:
  967. case 2:
  968. case 3:
  969. case 5:
  970. case 6:
  971. case 7:
  972. if(*source==utf32BOM[state]) {
  973. ++state;
  974. ++source;
  975. if(state==4) {
  976. state=8; /* detect UTF-32BE */
  977. offsetDelta=(int32_t)(source-pArgs->source);
  978. } else if(state==8) {
  979. state=9; /* detect UTF-32LE */
  980. offsetDelta=(int32_t)(source-pArgs->source);
  981. }
  982. } else {
  983. /* switch to UTF-32BE and pass the previous bytes */
  984. int32_t count=(int32_t)(source-pArgs->source); /* number of bytes from this buffer */
  985. /* reset the source */
  986. source=pArgs->source;
  987. if(count==(state&3)) {
  988. /* simple: all in the same buffer, just reset source */
  989. } else {
  990. UBool oldFlush=pArgs->flush;
  991. /* some of the bytes are from a previous buffer, replay those first */
  992. pArgs->source=utf32BOM+(state&4); /* select the correct BOM */
  993. pArgs->sourceLimit=pArgs->source+((state&3)-count); /* replay previous bytes */
  994. pArgs->flush=false; /* this sourceLimit is not the real source stream limit */
  995. /* no offsets: bytes from previous buffer, and not enough for output */
  996. T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
  997. /* restore real pointers; pArgs->source will be set in case 8/9 */
  998. pArgs->sourceLimit=sourceLimit;
  999. pArgs->flush=oldFlush;
  1000. }
  1001. state=8;
  1002. continue;
  1003. }
  1004. break;
  1005. case 8:
  1006. /* call UTF-32BE */
  1007. pArgs->source=source;
  1008. if(offsets==nullptr) {
  1009. T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
  1010. } else {
  1011. T_UConverter_toUnicode_UTF32_BE_OFFSET_LOGIC(pArgs, pErrorCode);
  1012. }
  1013. source=pArgs->source;
  1014. break;
  1015. case 9:
  1016. /* call UTF-32LE */
  1017. pArgs->source=source;
  1018. if(offsets==nullptr) {
  1019. T_UConverter_toUnicode_UTF32_LE(pArgs, pErrorCode);
  1020. } else {
  1021. T_UConverter_toUnicode_UTF32_LE_OFFSET_LOGIC(pArgs, pErrorCode);
  1022. }
  1023. source=pArgs->source;
  1024. break;
  1025. default:
  1026. break; /* does not occur */
  1027. }
  1028. }
  1029. /* add BOM size to offsets - see comment at offsetDelta declaration */
  1030. if(offsets!=nullptr && offsetDelta!=0) {
  1031. int32_t *offsetsLimit=pArgs->offsets;
  1032. while(offsets<offsetsLimit) {
  1033. *offsets++ += offsetDelta;
  1034. }
  1035. }
  1036. pArgs->source=source;
  1037. if(source==sourceLimit && pArgs->flush) {
  1038. /* handle truncated input */
  1039. switch(state) {
  1040. case 0:
  1041. break; /* no input at all, nothing to do */
  1042. case 8:
  1043. T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
  1044. break;
  1045. case 9:
  1046. T_UConverter_toUnicode_UTF32_LE(pArgs, pErrorCode);
  1047. break;
  1048. default:
  1049. /* handle 0<state<8: call UTF-32BE with too-short input */
  1050. pArgs->source=utf32BOM+(state&4); /* select the correct BOM */
  1051. pArgs->sourceLimit=pArgs->source+(state&3); /* replay bytes */
  1052. /* no offsets: not enough for output */
  1053. T_UConverter_toUnicode_UTF32_BE(pArgs, pErrorCode);
  1054. pArgs->source=source;
  1055. pArgs->sourceLimit=sourceLimit;
  1056. state=8;
  1057. break;
  1058. }
  1059. }
  1060. cnv->mode=state;
  1061. }
  1062. static UChar32 U_CALLCONV
  1063. _UTF32GetNextUChar(UConverterToUnicodeArgs *pArgs,
  1064. UErrorCode *pErrorCode) {
  1065. switch(pArgs->converter->mode) {
  1066. case 8:
  1067. return T_UConverter_getNextUChar_UTF32_BE(pArgs, pErrorCode);
  1068. case 9:
  1069. return T_UConverter_getNextUChar_UTF32_LE(pArgs, pErrorCode);
  1070. default:
  1071. return UCNV_GET_NEXT_UCHAR_USE_TO_U;
  1072. }
  1073. }
  1074. U_CDECL_END
  1075. static const UConverterImpl _UTF32Impl = {
  1076. UCNV_UTF32,
  1077. nullptr,
  1078. nullptr,
  1079. _UTF32Open,
  1080. nullptr,
  1081. _UTF32Reset,
  1082. _UTF32ToUnicodeWithOffsets,
  1083. _UTF32ToUnicodeWithOffsets,
  1084. #if U_IS_BIG_ENDIAN
  1085. T_UConverter_fromUnicode_UTF32_BE,
  1086. T_UConverter_fromUnicode_UTF32_BE_OFFSET_LOGIC,
  1087. #else
  1088. T_UConverter_fromUnicode_UTF32_LE,
  1089. T_UConverter_fromUnicode_UTF32_LE_OFFSET_LOGIC,
  1090. #endif
  1091. _UTF32GetNextUChar,
  1092. nullptr, /* ### TODO implement getStarters for all Unicode encodings?! */
  1093. nullptr,
  1094. nullptr,
  1095. nullptr,
  1096. ucnv_getNonSurrogateUnicodeSet,
  1097. nullptr,
  1098. nullptr
  1099. };
  1100. /* The 1236 CCSID refers to any version of Unicode with a BOM sensitive endianness of UTF-32 */
  1101. static const UConverterStaticData _UTF32StaticData = {
  1102. sizeof(UConverterStaticData),
  1103. "UTF-32",
  1104. 1236,
  1105. UCNV_IBM, UCNV_UTF32, 4, 4,
  1106. #if U_IS_BIG_ENDIAN
  1107. { 0, 0, 0xff, 0xfd }, 4,
  1108. #else
  1109. { 0xfd, 0xff, 0, 0 }, 4,
  1110. #endif
  1111. false, false,
  1112. 0,
  1113. 0,
  1114. { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } /* reserved */
  1115. };
  1116. const UConverterSharedData _UTF32Data =
  1117. UCNV_IMMUTABLE_SHARED_DATA_INITIALIZER(&_UTF32StaticData, &_UTF32Impl);
  1118. #endif