ucnv_u32.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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