PageRenderTime 57ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/external/icu4c/common/ucnvhz.c

https://gitlab.com/brian0218/rk3066_r-box_android4.2.2_sdk
C | 640 lines | 471 code | 61 blank | 108 comment | 85 complexity | 0de68131dc59f6cbc8469e4d82894fb3 MD5 | raw file
  1. /*
  2. **********************************************************************
  3. * Copyright (C) 2000-2009, International Business Machines
  4. * Corporation and others. All Rights Reserved.
  5. **********************************************************************
  6. * file name: ucnvhz.c
  7. * encoding: US-ASCII
  8. * tab size: 8 (not used)
  9. * indentation:4
  10. *
  11. * created on: 2000oct16
  12. * created by: Ram Viswanadha
  13. * 10/31/2000 Ram Implemented offsets logic function
  14. *
  15. */
  16. #include "unicode/utypes.h"
  17. #if !UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION
  18. #include "cmemory.h"
  19. #include "unicode/ucnv.h"
  20. #include "unicode/ucnv_cb.h"
  21. #include "unicode/uset.h"
  22. #include "ucnv_bld.h"
  23. #include "ucnv_cnv.h"
  24. #include "ucnv_imp.h"
  25. #define UCNV_TILDE 0x7E /* ~ */
  26. #define UCNV_OPEN_BRACE 0x7B /* { */
  27. #define UCNV_CLOSE_BRACE 0x7D /* } */
  28. #define SB_ESCAPE "\x7E\x7D"
  29. #define DB_ESCAPE "\x7E\x7B"
  30. #define TILDE_ESCAPE "\x7E\x7E"
  31. #define ESC_LEN 2
  32. #define CONCAT_ESCAPE_MACRO( args, targetIndex,targetLength,strToAppend, err, len,sourceIndex){ \
  33. while(len-->0){ \
  34. if(targetIndex < targetLength){ \
  35. args->target[targetIndex] = (unsigned char) *strToAppend; \
  36. if(args->offsets!=NULL){ \
  37. *(offsets++) = sourceIndex-1; \
  38. } \
  39. targetIndex++; \
  40. } \
  41. else{ \
  42. args->converter->charErrorBuffer[(int)args->converter->charErrorBufferLength++] = (unsigned char) *strToAppend; \
  43. *err =U_BUFFER_OVERFLOW_ERROR; \
  44. } \
  45. strToAppend++; \
  46. } \
  47. }
  48. typedef struct{
  49. UConverter* gbConverter;
  50. int32_t targetIndex;
  51. int32_t sourceIndex;
  52. UBool isEscapeAppended;
  53. UBool isStateDBCS;
  54. UBool isTargetUCharDBCS;
  55. UBool isEmptySegment;
  56. }UConverterDataHZ;
  57. static void
  58. _HZOpen(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *errorCode){
  59. UConverter *gbConverter;
  60. if(pArgs->onlyTestIsLoadable) {
  61. ucnv_canCreateConverter("GBK", errorCode); /* errorCode carries result */
  62. return;
  63. }
  64. gbConverter = ucnv_open("GBK", errorCode);
  65. if(U_FAILURE(*errorCode)) {
  66. return;
  67. }
  68. cnv->toUnicodeStatus = 0;
  69. cnv->fromUnicodeStatus= 0;
  70. cnv->mode=0;
  71. cnv->fromUChar32=0x0000;
  72. cnv->extraInfo = uprv_malloc(sizeof(UConverterDataHZ));
  73. if(cnv->extraInfo != NULL){
  74. uprv_memset(cnv->extraInfo, 0, sizeof(UConverterDataHZ));
  75. ((UConverterDataHZ*)cnv->extraInfo)->gbConverter = gbConverter;
  76. }
  77. else {
  78. ucnv_close(gbConverter);
  79. *errorCode = U_MEMORY_ALLOCATION_ERROR;
  80. return;
  81. }
  82. }
  83. static void
  84. _HZClose(UConverter *cnv){
  85. if(cnv->extraInfo != NULL) {
  86. ucnv_close (((UConverterDataHZ *) (cnv->extraInfo))->gbConverter);
  87. if(!cnv->isExtraLocal) {
  88. uprv_free(cnv->extraInfo);
  89. }
  90. cnv->extraInfo = NULL;
  91. }
  92. }
  93. static void
  94. _HZReset(UConverter *cnv, UConverterResetChoice choice){
  95. if(choice<=UCNV_RESET_TO_UNICODE) {
  96. cnv->toUnicodeStatus = 0;
  97. cnv->mode=0;
  98. if(cnv->extraInfo != NULL){
  99. ((UConverterDataHZ*)cnv->extraInfo)->isStateDBCS = FALSE;
  100. ((UConverterDataHZ*)cnv->extraInfo)->isEmptySegment = FALSE;
  101. }
  102. }
  103. if(choice!=UCNV_RESET_TO_UNICODE) {
  104. cnv->fromUnicodeStatus= 0;
  105. cnv->fromUChar32=0x0000;
  106. if(cnv->extraInfo != NULL){
  107. ((UConverterDataHZ*)cnv->extraInfo)->isEscapeAppended = FALSE;
  108. ((UConverterDataHZ*)cnv->extraInfo)->targetIndex = 0;
  109. ((UConverterDataHZ*)cnv->extraInfo)->sourceIndex = 0;
  110. ((UConverterDataHZ*)cnv->extraInfo)->isTargetUCharDBCS = FALSE;
  111. }
  112. }
  113. }
  114. /**************************************HZ Encoding*************************************************
  115. * Rules for HZ encoding
  116. *
  117. * In ASCII mode, a byte is interpreted as an ASCII character, unless a
  118. * '~' is encountered. The character '~' is an escape character. By
  119. * convention, it must be immediately followed ONLY by '~', '{' or '\n'
  120. * (<LF>), with the following special meaning.
  121. * 1. The escape sequence '~~' is interpreted as a '~'.
  122. * 2. The escape-to-GB sequence '~{' switches the mode from ASCII to GB.
  123. * 3. The escape sequence '~\n' is a line-continuation marker to be
  124. * consumed with no output produced.
  125. * In GB mode, characters are interpreted two bytes at a time as (pure)
  126. * GB codes until the escape-from-GB code '~}' is read. This code
  127. * switches the mode from GB back to ASCII. (Note that the escape-
  128. * from-GB code '~}' ($7E7D) is outside the defined GB range.)
  129. *
  130. * Source: RFC 1842
  131. *
  132. * Note that the formal syntax in RFC 1842 is invalid. I assume that the
  133. * intended definition of single-byte-segment is as follows (pedberg):
  134. * single-byte-segment = single-byte-seq 1*single-byte-char
  135. */
  136. static void
  137. UConverter_toUnicode_HZ_OFFSETS_LOGIC(UConverterToUnicodeArgs *args,
  138. UErrorCode* err){
  139. char tempBuf[2];
  140. const char *mySource = ( char *) args->source;
  141. UChar *myTarget = args->target;
  142. const char *mySourceLimit = args->sourceLimit;
  143. UChar32 targetUniChar = 0x0000;
  144. int32_t mySourceChar = 0x0000;
  145. UConverterDataHZ* myData=(UConverterDataHZ*)(args->converter->extraInfo);
  146. tempBuf[0]=0;
  147. tempBuf[1]=0;
  148. /* Calling code already handles this situation. */
  149. /*if ((args->converter == NULL) || (args->targetLimit < args->target) || (mySourceLimit < args->source)){
  150. *err = U_ILLEGAL_ARGUMENT_ERROR;
  151. return;
  152. }*/
  153. while(mySource< mySourceLimit){
  154. if(myTarget < args->targetLimit){
  155. mySourceChar= (unsigned char) *mySource++;
  156. if(args->converter->mode == UCNV_TILDE) {
  157. /* second byte after ~ */
  158. args->converter->mode=0;
  159. switch(mySourceChar) {
  160. case 0x0A:
  161. /* no output for ~\n (line-continuation marker) */
  162. continue;
  163. case UCNV_TILDE:
  164. if(args->offsets) {
  165. args->offsets[myTarget - args->target]=(int32_t)(mySource - args->source - 2);
  166. }
  167. *(myTarget++)=(UChar)mySourceChar;
  168. myData->isEmptySegment = FALSE;
  169. continue;
  170. case UCNV_OPEN_BRACE:
  171. case UCNV_CLOSE_BRACE:
  172. myData->isStateDBCS = (mySourceChar == UCNV_OPEN_BRACE);
  173. if (myData->isEmptySegment) {
  174. myData->isEmptySegment = FALSE; /* we are handling it, reset to avoid future spurious errors */
  175. *err = U_ILLEGAL_ESCAPE_SEQUENCE;
  176. args->converter->toUCallbackReason = UCNV_IRREGULAR;
  177. args->converter->toUBytes[0] = UCNV_TILDE;
  178. args->converter->toUBytes[1] = mySourceChar;
  179. args->converter->toULength = 2;
  180. args->target = myTarget;
  181. args->source = mySource;
  182. return;
  183. }
  184. myData->isEmptySegment = TRUE;
  185. continue;
  186. default:
  187. /* if the first byte is equal to TILDE and the trail byte
  188. * is not a valid byte then it is an error condition
  189. */
  190. /*
  191. * Ticket 5691: consistent illegal sequences:
  192. * - We include at least the first byte in the illegal sequence.
  193. * - If any of the non-initial bytes could be the start of a character,
  194. * we stop the illegal sequence before the first one of those.
  195. */
  196. myData->isEmptySegment = FALSE; /* different error here, reset this to avoid spurious future error */
  197. *err = U_ILLEGAL_ESCAPE_SEQUENCE;
  198. args->converter->toUBytes[0] = UCNV_TILDE;
  199. if( myData->isStateDBCS ?
  200. (0x21 <= mySourceChar && mySourceChar <= 0x7e) :
  201. mySourceChar <= 0x7f
  202. ) {
  203. /* The current byte could be the start of a character: Back it out. */
  204. args->converter->toULength = 1;
  205. --mySource;
  206. } else {
  207. /* Include the current byte in the illegal sequence. */
  208. args->converter->toUBytes[1] = mySourceChar;
  209. args->converter->toULength = 2;
  210. }
  211. args->target = myTarget;
  212. args->source = mySource;
  213. return;
  214. }
  215. } else if(myData->isStateDBCS) {
  216. if(args->converter->toUnicodeStatus == 0x00){
  217. /* lead byte */
  218. if(mySourceChar == UCNV_TILDE) {
  219. args->converter->mode = UCNV_TILDE;
  220. } else {
  221. /* add another bit to distinguish a 0 byte from not having seen a lead byte */
  222. args->converter->toUnicodeStatus = (uint32_t) (mySourceChar | 0x100);
  223. myData->isEmptySegment = FALSE; /* the segment has something, either valid or will produce a different error, so reset this */
  224. }
  225. continue;
  226. }
  227. else{
  228. /* trail byte */
  229. int leadIsOk, trailIsOk;
  230. uint32_t leadByte = args->converter->toUnicodeStatus & 0xff;
  231. targetUniChar = 0xffff;
  232. /*
  233. * Ticket 5691: consistent illegal sequences:
  234. * - We include at least the first byte in the illegal sequence.
  235. * - If any of the non-initial bytes could be the start of a character,
  236. * we stop the illegal sequence before the first one of those.
  237. *
  238. * In HZ DBCS, if the second byte is in the 21..7e range,
  239. * we report only the first byte as the illegal sequence.
  240. * Otherwise we convert or report the pair of bytes.
  241. */
  242. leadIsOk = (uint8_t)(leadByte - 0x21) <= (0x7d - 0x21);
  243. trailIsOk = (uint8_t)(mySourceChar - 0x21) <= (0x7e - 0x21);
  244. if (leadIsOk && trailIsOk) {
  245. tempBuf[0] = (char) (leadByte+0x80) ;
  246. tempBuf[1] = (char) (mySourceChar+0x80);
  247. targetUniChar = ucnv_MBCSSimpleGetNextUChar(myData->gbConverter->sharedData,
  248. tempBuf, 2, args->converter->useFallback);
  249. mySourceChar= (leadByte << 8) | mySourceChar;
  250. } else if (trailIsOk) {
  251. /* report a single illegal byte and continue with the following DBCS starter byte */
  252. --mySource;
  253. mySourceChar = (int32_t)leadByte;
  254. } else {
  255. /* report a pair of illegal bytes if the second byte is not a DBCS starter */
  256. /* add another bit so that the code below writes 2 bytes in case of error */
  257. mySourceChar= 0x10000 | (leadByte << 8) | mySourceChar;
  258. }
  259. args->converter->toUnicodeStatus =0x00;
  260. }
  261. }
  262. else{
  263. if(mySourceChar == UCNV_TILDE) {
  264. args->converter->mode = UCNV_TILDE;
  265. continue;
  266. } else if(mySourceChar <= 0x7f) {
  267. targetUniChar = (UChar)mySourceChar; /* ASCII */
  268. myData->isEmptySegment = FALSE; /* the segment has something valid */
  269. } else {
  270. targetUniChar = 0xffff;
  271. myData->isEmptySegment = FALSE; /* different error here, reset this to avoid spurious future error */
  272. }
  273. }
  274. if(targetUniChar < 0xfffe){
  275. if(args->offsets) {
  276. args->offsets[myTarget - args->target]=(int32_t)(mySource - args->source - 1-(myData->isStateDBCS));
  277. }
  278. *(myTarget++)=(UChar)targetUniChar;
  279. }
  280. else /* targetUniChar>=0xfffe */ {
  281. if(targetUniChar == 0xfffe){
  282. *err = U_INVALID_CHAR_FOUND;
  283. }
  284. else{
  285. *err = U_ILLEGAL_CHAR_FOUND;
  286. }
  287. if(mySourceChar > 0xff){
  288. args->converter->toUBytes[0] = (uint8_t)(mySourceChar >> 8);
  289. args->converter->toUBytes[1] = (uint8_t)mySourceChar;
  290. args->converter->toULength=2;
  291. }
  292. else{
  293. args->converter->toUBytes[0] = (uint8_t)mySourceChar;
  294. args->converter->toULength=1;
  295. }
  296. break;
  297. }
  298. }
  299. else{
  300. *err =U_BUFFER_OVERFLOW_ERROR;
  301. break;
  302. }
  303. }
  304. args->target = myTarget;
  305. args->source = mySource;
  306. }
  307. static void
  308. UConverter_fromUnicode_HZ_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args,
  309. UErrorCode * err){
  310. const UChar *mySource = args->source;
  311. char *myTarget = args->target;
  312. int32_t* offsets = args->offsets;
  313. int32_t mySourceIndex = 0;
  314. int32_t myTargetIndex = 0;
  315. int32_t targetLength = (int32_t)(args->targetLimit - myTarget);
  316. int32_t mySourceLength = (int32_t)(args->sourceLimit - args->source);
  317. int32_t length=0;
  318. uint32_t targetUniChar = 0x0000;
  319. UChar32 mySourceChar = 0x0000;
  320. UConverterDataHZ *myConverterData=(UConverterDataHZ*)args->converter->extraInfo;
  321. UBool isTargetUCharDBCS = (UBool) myConverterData->isTargetUCharDBCS;
  322. UBool oldIsTargetUCharDBCS = isTargetUCharDBCS;
  323. int len =0;
  324. const char* escSeq=NULL;
  325. /* Calling code already handles this situation. */
  326. /*if ((args->converter == NULL) || (args->targetLimit < myTarget) || (args->sourceLimit < args->source)){
  327. *err = U_ILLEGAL_ARGUMENT_ERROR;
  328. return;
  329. }*/
  330. if(args->converter->fromUChar32!=0 && myTargetIndex < targetLength) {
  331. goto getTrail;
  332. }
  333. /*writing the char to the output stream */
  334. while (mySourceIndex < mySourceLength){
  335. targetUniChar = missingCharMarker;
  336. if (myTargetIndex < targetLength){
  337. mySourceChar = (UChar) mySource[mySourceIndex++];
  338. oldIsTargetUCharDBCS = isTargetUCharDBCS;
  339. if(mySourceChar ==UCNV_TILDE){
  340. /*concatEscape(args, &myTargetIndex, &targetLength,"\x7E\x7E",err,2,&mySourceIndex);*/
  341. len = ESC_LEN;
  342. escSeq = TILDE_ESCAPE;
  343. CONCAT_ESCAPE_MACRO(args, myTargetIndex, targetLength, escSeq,err,len,mySourceIndex);
  344. continue;
  345. } else if(mySourceChar <= 0x7f) {
  346. length = 1;
  347. targetUniChar = mySourceChar;
  348. } else {
  349. length= ucnv_MBCSFromUChar32(myConverterData->gbConverter->sharedData,
  350. mySourceChar,&targetUniChar,args->converter->useFallback);
  351. /* we can only use lead bytes 21..7D and trail bytes 21..7E */
  352. if( length == 2 &&
  353. (uint16_t)(targetUniChar - 0xa1a1) <= (0xfdfe - 0xa1a1) &&
  354. (uint8_t)(targetUniChar - 0xa1) <= (0xfe - 0xa1)
  355. ) {
  356. targetUniChar -= 0x8080;
  357. } else {
  358. targetUniChar = missingCharMarker;
  359. }
  360. }
  361. if (targetUniChar != missingCharMarker){
  362. myConverterData->isTargetUCharDBCS = isTargetUCharDBCS = (UBool)(targetUniChar>0x00FF);
  363. if(oldIsTargetUCharDBCS != isTargetUCharDBCS || !myConverterData->isEscapeAppended ){
  364. /*Shifting from a double byte to single byte mode*/
  365. if(!isTargetUCharDBCS){
  366. len =ESC_LEN;
  367. escSeq = SB_ESCAPE;
  368. CONCAT_ESCAPE_MACRO(args, myTargetIndex, targetLength, escSeq,err,len,mySourceIndex);
  369. myConverterData->isEscapeAppended = TRUE;
  370. }
  371. else{ /* Shifting from a single byte to double byte mode*/
  372. len =ESC_LEN;
  373. escSeq = DB_ESCAPE;
  374. CONCAT_ESCAPE_MACRO(args, myTargetIndex, targetLength, escSeq,err,len,mySourceIndex);
  375. myConverterData->isEscapeAppended = TRUE;
  376. }
  377. }
  378. if(isTargetUCharDBCS){
  379. if( myTargetIndex <targetLength){
  380. myTarget[myTargetIndex++] =(char) (targetUniChar >> 8);
  381. if(offsets){
  382. *(offsets++) = mySourceIndex-1;
  383. }
  384. if(myTargetIndex < targetLength){
  385. myTarget[myTargetIndex++] =(char) targetUniChar;
  386. if(offsets){
  387. *(offsets++) = mySourceIndex-1;
  388. }
  389. }else{
  390. args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (char) targetUniChar;
  391. *err = U_BUFFER_OVERFLOW_ERROR;
  392. }
  393. }else{
  394. args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] =(char) (targetUniChar >> 8);
  395. args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (char) targetUniChar;
  396. *err = U_BUFFER_OVERFLOW_ERROR;
  397. }
  398. }else{
  399. if( myTargetIndex <targetLength){
  400. myTarget[myTargetIndex++] = (char) (targetUniChar );
  401. if(offsets){
  402. *(offsets++) = mySourceIndex-1;
  403. }
  404. }else{
  405. args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = (char) targetUniChar;
  406. *err = U_BUFFER_OVERFLOW_ERROR;
  407. }
  408. }
  409. }
  410. else{
  411. /* oops.. the code point is unassigned */
  412. /*Handle surrogates */
  413. /*check if the char is a First surrogate*/
  414. if(UTF_IS_SURROGATE(mySourceChar)) {
  415. if(UTF_IS_SURROGATE_FIRST(mySourceChar)) {
  416. args->converter->fromUChar32=mySourceChar;
  417. getTrail:
  418. /*look ahead to find the trail surrogate*/
  419. if(mySourceIndex < mySourceLength) {
  420. /* test the following code unit */
  421. UChar trail=(UChar) args->source[mySourceIndex];
  422. if(UTF_IS_SECOND_SURROGATE(trail)) {
  423. ++mySourceIndex;
  424. mySourceChar=UTF16_GET_PAIR_VALUE(args->converter->fromUChar32, trail);
  425. args->converter->fromUChar32=0x00;
  426. /* there are no surrogates in GB2312*/
  427. *err = U_INVALID_CHAR_FOUND;
  428. /* exit this condition tree */
  429. } else {
  430. /* this is an unmatched lead code unit (1st surrogate) */
  431. /* callback(illegal) */
  432. *err=U_ILLEGAL_CHAR_FOUND;
  433. }
  434. } else {
  435. /* no more input */
  436. *err = U_ZERO_ERROR;
  437. }
  438. } else {
  439. /* this is an unmatched trail code unit (2nd surrogate) */
  440. /* callback(illegal) */
  441. *err=U_ILLEGAL_CHAR_FOUND;
  442. }
  443. } else {
  444. /* callback(unassigned) for a BMP code point */
  445. *err = U_INVALID_CHAR_FOUND;
  446. }
  447. args->converter->fromUChar32=mySourceChar;
  448. break;
  449. }
  450. }
  451. else{
  452. *err = U_BUFFER_OVERFLOW_ERROR;
  453. break;
  454. }
  455. targetUniChar=missingCharMarker;
  456. }
  457. args->target += myTargetIndex;
  458. args->source += mySourceIndex;
  459. myConverterData->isTargetUCharDBCS = isTargetUCharDBCS;
  460. }
  461. static void
  462. _HZ_WriteSub(UConverterFromUnicodeArgs *args, int32_t offsetIndex, UErrorCode *err) {
  463. UConverter *cnv = args->converter;
  464. UConverterDataHZ *convData=(UConverterDataHZ *) cnv->extraInfo;
  465. char *p;
  466. char buffer[4];
  467. p = buffer;
  468. if( convData->isTargetUCharDBCS){
  469. *p++= UCNV_TILDE;
  470. *p++= UCNV_CLOSE_BRACE;
  471. convData->isTargetUCharDBCS=FALSE;
  472. }
  473. *p++= (char)cnv->subChars[0];
  474. ucnv_cbFromUWriteBytes(args,
  475. buffer, (int32_t)(p - buffer),
  476. offsetIndex, err);
  477. }
  478. /*
  479. * Structure for cloning an HZ converter into a single memory block.
  480. * ucnv_safeClone() of the HZ converter will align the entire cloneHZStruct,
  481. * and then ucnv_safeClone() of the sub-converter may additionally align
  482. * subCnv inside the cloneHZStruct, for which we need the deadSpace after
  483. * subCnv. This is because UAlignedMemory may be larger than the actually
  484. * necessary alignment size for the platform.
  485. * The other cloneHZStruct fields will not be moved around,
  486. * and are aligned properly with cloneHZStruct's alignment.
  487. */
  488. struct cloneHZStruct
  489. {
  490. UConverter cnv;
  491. UConverter subCnv;
  492. UAlignedMemory deadSpace;
  493. UConverterDataHZ mydata;
  494. };
  495. static UConverter *
  496. _HZ_SafeClone(const UConverter *cnv,
  497. void *stackBuffer,
  498. int32_t *pBufferSize,
  499. UErrorCode *status)
  500. {
  501. struct cloneHZStruct * localClone;
  502. int32_t size, bufferSizeNeeded = sizeof(struct cloneHZStruct);
  503. if (U_FAILURE(*status)){
  504. return 0;
  505. }
  506. if (*pBufferSize == 0){ /* 'preflighting' request - set needed size into *pBufferSize */
  507. *pBufferSize = bufferSizeNeeded;
  508. return 0;
  509. }
  510. localClone = (struct cloneHZStruct *)stackBuffer;
  511. /* ucnv.c/ucnv_safeClone() copied the main UConverter already */
  512. uprv_memcpy(&localClone->mydata, cnv->extraInfo, sizeof(UConverterDataHZ));
  513. localClone->cnv.extraInfo = &localClone->mydata;
  514. localClone->cnv.isExtraLocal = TRUE;
  515. /* deep-clone the sub-converter */
  516. size = (int32_t)(sizeof(UConverter) + sizeof(UAlignedMemory)); /* include size of padding */
  517. ((UConverterDataHZ*)localClone->cnv.extraInfo)->gbConverter =
  518. ucnv_safeClone(((UConverterDataHZ*)cnv->extraInfo)->gbConverter, &localClone->subCnv, &size, status);
  519. return &localClone->cnv;
  520. }
  521. static void
  522. _HZ_GetUnicodeSet(const UConverter *cnv,
  523. const USetAdder *sa,
  524. UConverterUnicodeSet which,
  525. UErrorCode *pErrorCode) {
  526. /* HZ converts all of ASCII */
  527. sa->addRange(sa->set, 0, 0x7f);
  528. /* add all of the code points that the sub-converter handles */
  529. ucnv_MBCSGetFilteredUnicodeSetForUnicode(
  530. ((UConverterDataHZ*)cnv->extraInfo)->gbConverter->sharedData,
  531. sa, which, UCNV_SET_FILTER_HZ,
  532. pErrorCode);
  533. }
  534. static const UConverterImpl _HZImpl={
  535. UCNV_HZ,
  536. NULL,
  537. NULL,
  538. _HZOpen,
  539. _HZClose,
  540. _HZReset,
  541. UConverter_toUnicode_HZ_OFFSETS_LOGIC,
  542. UConverter_toUnicode_HZ_OFFSETS_LOGIC,
  543. UConverter_fromUnicode_HZ_OFFSETS_LOGIC,
  544. UConverter_fromUnicode_HZ_OFFSETS_LOGIC,
  545. NULL,
  546. NULL,
  547. NULL,
  548. _HZ_WriteSub,
  549. _HZ_SafeClone,
  550. _HZ_GetUnicodeSet
  551. };
  552. static const UConverterStaticData _HZStaticData={
  553. sizeof(UConverterStaticData),
  554. "HZ",
  555. 0,
  556. UCNV_IBM,
  557. UCNV_HZ,
  558. 1,
  559. 4,
  560. { 0x1a, 0, 0, 0 },
  561. 1,
  562. FALSE,
  563. FALSE,
  564. 0,
  565. 0,
  566. { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* reserved */
  567. };
  568. const UConverterSharedData _HZData={
  569. sizeof(UConverterSharedData),
  570. ~((uint32_t) 0),
  571. NULL,
  572. NULL,
  573. &_HZStaticData,
  574. FALSE,
  575. &_HZImpl,
  576. 0
  577. };
  578. #endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */