X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..4388f060552cc537e71e957d32f35e9d75a61233:/icuSources/common/ucnvhz.c diff --git a/icuSources/common/ucnvhz.c b/icuSources/common/ucnvhz.c index 21c1ea3d..ef8334c0 100644 --- a/icuSources/common/ucnvhz.c +++ b/icuSources/common/ucnvhz.c @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (C) 2000-2008, International Business Machines +* Copyright (C) 2000-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * file name: ucnvhz.c @@ -22,8 +22,10 @@ #include "unicode/ucnv.h" #include "unicode/ucnv_cb.h" #include "unicode/uset.h" +#include "unicode/utf16.h" #include "ucnv_bld.h" #include "ucnv_cnv.h" +#include "ucnv_imp.h" #define UCNV_TILDE 0x7E /* ~ */ #define UCNV_OPEN_BRACE 0x7B /* { */ @@ -65,17 +67,26 @@ typedef struct{ static void -_HZOpen(UConverter *cnv, const char *name,const char *locale,uint32_t options, UErrorCode *errorCode){ +_HZOpen(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *errorCode){ + UConverter *gbConverter; + if(pArgs->onlyTestIsLoadable) { + ucnv_canCreateConverter("GBK", errorCode); /* errorCode carries result */ + return; + } + gbConverter = ucnv_open("GBK", errorCode); + if(U_FAILURE(*errorCode)) { + return; + } cnv->toUnicodeStatus = 0; cnv->fromUnicodeStatus= 0; cnv->mode=0; cnv->fromUChar32=0x0000; - cnv->extraInfo = uprv_malloc(sizeof(UConverterDataHZ)); + cnv->extraInfo = uprv_calloc(1, sizeof(UConverterDataHZ)); if(cnv->extraInfo != NULL){ - uprv_memset(cnv->extraInfo, 0, sizeof(UConverterDataHZ)); - ((UConverterDataHZ*)cnv->extraInfo)->gbConverter = ucnv_open("GBK",errorCode); + ((UConverterDataHZ*)cnv->extraInfo)->gbConverter = gbConverter; } else { + ucnv_close(gbConverter); *errorCode = U_MEMORY_ALLOCATION_ERROR; return; } @@ -435,17 +446,17 @@ UConverter_fromUnicode_HZ_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args, /* oops.. the code point is unassigned */ /*Handle surrogates */ /*check if the char is a First surrogate*/ - if(UTF_IS_SURROGATE(mySourceChar)) { - if(UTF_IS_SURROGATE_FIRST(mySourceChar)) { + if(U16_IS_SURROGATE(mySourceChar)) { + if(U16_IS_SURROGATE_LEAD(mySourceChar)) { args->converter->fromUChar32=mySourceChar; getTrail: /*look ahead to find the trail surrogate*/ if(mySourceIndex < mySourceLength) { /* test the following code unit */ UChar trail=(UChar) args->source[mySourceIndex]; - if(UTF_IS_SECOND_SURROGATE(trail)) { + if(U16_IS_TRAIL(trail)) { ++mySourceIndex; - mySourceChar=UTF16_GET_PAIR_VALUE(args->converter->fromUChar32, trail); + mySourceChar=U16_GET_SUPPLEMENTARY(args->converter->fromUChar32, trail); args->converter->fromUChar32=0x00; /* there are no surrogates in GB2312*/ *err = U_INVALID_CHAR_FOUND;