michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1999-2004, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * michael@0: * uconv_cnv.c: michael@0: * Implements all the low level conversion functions michael@0: * T_UnicodeConverter_{to,from}Unicode_$ConversionType michael@0: * michael@0: * Change history: michael@0: * michael@0: * 06/29/2000 helena Major rewrite of the callback APIs. michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: michael@0: #include "unicode/ucnv_err.h" michael@0: #include "unicode/ucnv.h" michael@0: #include "unicode/uset.h" michael@0: #include "ucnv_cnv.h" michael@0: #include "ucnv_bld.h" michael@0: #include "cmemory.h" michael@0: michael@0: U_CFUNC void michael@0: ucnv_getCompleteUnicodeSet(const UConverter *cnv, michael@0: const USetAdder *sa, michael@0: UConverterUnicodeSet which, michael@0: UErrorCode *pErrorCode) { michael@0: sa->addRange(sa->set, 0, 0x10ffff); michael@0: } michael@0: michael@0: U_CFUNC void michael@0: ucnv_getNonSurrogateUnicodeSet(const UConverter *cnv, michael@0: const USetAdder *sa, michael@0: UConverterUnicodeSet which, michael@0: UErrorCode *pErrorCode) { michael@0: sa->addRange(sa->set, 0, 0xd7ff); michael@0: sa->addRange(sa->set, 0xe000, 0x10ffff); michael@0: } michael@0: michael@0: U_CFUNC void michael@0: ucnv_fromUWriteBytes(UConverter *cnv, michael@0: const char *bytes, int32_t length, michael@0: char **target, const char *targetLimit, michael@0: int32_t **offsets, michael@0: int32_t sourceIndex, michael@0: UErrorCode *pErrorCode) { michael@0: char *t=*target; michael@0: int32_t *o; michael@0: michael@0: /* write bytes */ michael@0: if(offsets==NULL || (o=*offsets)==NULL) { michael@0: while(length>0 && t0 && t0) { michael@0: if(cnv!=NULL) { michael@0: t=(char *)cnv->charErrorBuffer; michael@0: cnv->charErrorBufferLength=(int8_t)length; michael@0: do { michael@0: *t++=(uint8_t)*bytes++; michael@0: } while(--length>0); michael@0: } michael@0: *pErrorCode=U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: } michael@0: michael@0: U_CFUNC void michael@0: ucnv_toUWriteUChars(UConverter *cnv, michael@0: const UChar *uchars, int32_t length, michael@0: UChar **target, const UChar *targetLimit, michael@0: int32_t **offsets, michael@0: int32_t sourceIndex, michael@0: UErrorCode *pErrorCode) { michael@0: UChar *t=*target; michael@0: int32_t *o; michael@0: michael@0: /* write UChars */ michael@0: if(offsets==NULL || (o=*offsets)==NULL) { michael@0: while(length>0 && t0 && t0) { michael@0: if(cnv!=NULL) { michael@0: t=cnv->UCharErrorBuffer; michael@0: cnv->UCharErrorBufferLength=(int8_t)length; michael@0: do { michael@0: *t++=*uchars++; michael@0: } while(--length>0); michael@0: } michael@0: *pErrorCode=U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: } michael@0: michael@0: U_CFUNC void michael@0: ucnv_toUWriteCodePoint(UConverter *cnv, michael@0: UChar32 c, michael@0: UChar **target, const UChar *targetLimit, michael@0: int32_t **offsets, michael@0: int32_t sourceIndex, michael@0: UErrorCode *pErrorCode) { michael@0: UChar *t; michael@0: int32_t *o; michael@0: michael@0: t=*target; michael@0: michael@0: if(t=0) { michael@0: if(cnv!=NULL) { michael@0: int8_t i=0; michael@0: U16_APPEND_UNSAFE(cnv->UCharErrorBuffer, i, c); michael@0: cnv->UCharErrorBufferLength=i; michael@0: } michael@0: *pErrorCode=U_BUFFER_OVERFLOW_ERROR; michael@0: } michael@0: } michael@0: michael@0: #endif