/*
**********************************************************************
-* Copyright (C) 2000-2008, International Business Machines
+* Copyright (C) 2000-2011, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: ucnvhz.c
#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 /* { */
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;
}
/* 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;