1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
2004-08-26 22:51:40 +00:00
|
|
|
* Copyright (C) 1999-2004, International Business Machines
|
2000-01-13 23:54:23 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
|
|
|
* uconv_cnv.c:
|
|
|
|
* Implements all the low level conversion functions
|
|
|
|
* T_UnicodeConverter_{to,from}Unicode_$ConversionType
|
|
|
|
*
|
2000-06-27 20:47:56 +00:00
|
|
|
* Change history:
|
|
|
|
*
|
|
|
|
* 06/29/2000 helena Major rewrite of the callback APIs.
|
2000-01-13 23:54:23 +00:00
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
2004-08-26 22:51:40 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_CONVERSION
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ucnv_err.h"
|
|
|
|
#include "unicode/ucnv.h"
|
2003-04-05 01:33:02 +00:00
|
|
|
#include "unicode/uset.h"
|
|
|
|
#include "ucnv_cnv.h"
|
2003-11-08 00:09:50 +00:00
|
|
|
#include "ucnv_bld.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
|
2003-04-05 01:33:02 +00:00
|
|
|
U_CFUNC void
|
|
|
|
ucnv_getCompleteUnicodeSet(const UConverter *cnv,
|
2004-12-02 04:18:35 +00:00
|
|
|
const USetAdder *sa,
|
2003-04-05 01:33:02 +00:00
|
|
|
UConverterUnicodeSet which,
|
|
|
|
UErrorCode *pErrorCode) {
|
2004-09-07 17:59:53 +00:00
|
|
|
sa->addRange(sa->set, 0, 0x10ffff);
|
2003-04-05 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CFUNC void
|
|
|
|
ucnv_getNonSurrogateUnicodeSet(const UConverter *cnv,
|
2004-12-02 04:18:35 +00:00
|
|
|
const USetAdder *sa,
|
2003-04-05 01:33:02 +00:00
|
|
|
UConverterUnicodeSet which,
|
|
|
|
UErrorCode *pErrorCode) {
|
2004-09-07 17:59:53 +00:00
|
|
|
sa->addRange(sa->set, 0, 0xd7ff);
|
|
|
|
sa->addRange(sa->set, 0xe000, 0x10ffff);
|
2003-04-05 01:33:02 +00:00
|
|
|
}
|
2003-07-24 00:28:47 +00:00
|
|
|
|
|
|
|
U_CFUNC void
|
|
|
|
ucnv_fromUWriteBytes(UConverter *cnv,
|
|
|
|
const char *bytes, int32_t length,
|
|
|
|
char **target, const char *targetLimit,
|
|
|
|
int32_t **offsets,
|
|
|
|
int32_t sourceIndex,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
char *t=*target;
|
|
|
|
int32_t *o;
|
|
|
|
|
|
|
|
/* write bytes */
|
|
|
|
if(offsets==NULL || (o=*offsets)==NULL) {
|
|
|
|
while(length>0 && t<targetLimit) {
|
|
|
|
*t++=*bytes++;
|
|
|
|
--length;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* output with offsets */
|
|
|
|
while(length>0 && t<targetLimit) {
|
|
|
|
*t++=*bytes++;
|
|
|
|
*o++=sourceIndex;
|
|
|
|
--length;
|
|
|
|
}
|
|
|
|
*offsets=o;
|
|
|
|
}
|
|
|
|
*target=t;
|
|
|
|
|
|
|
|
/* write overflow */
|
|
|
|
if(length>0) {
|
|
|
|
if(cnv!=NULL) {
|
|
|
|
t=(char *)cnv->charErrorBuffer;
|
|
|
|
cnv->charErrorBufferLength=(int8_t)length;
|
|
|
|
do {
|
|
|
|
*t++=(uint8_t)*bytes++;
|
|
|
|
} while(--length>0);
|
|
|
|
}
|
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2003-08-01 15:05:35 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
U_CFUNC void
|
|
|
|
ucnv_toUWriteUChars(UConverter *cnv,
|
|
|
|
const UChar *uchars, int32_t length,
|
|
|
|
UChar **target, const UChar *targetLimit,
|
|
|
|
int32_t **offsets,
|
|
|
|
int32_t sourceIndex,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
UChar *t=*target;
|
|
|
|
int32_t *o;
|
|
|
|
|
|
|
|
/* write UChars */
|
|
|
|
if(offsets==NULL || (o=*offsets)==NULL) {
|
|
|
|
while(length>0 && t<targetLimit) {
|
|
|
|
*t++=*uchars++;
|
|
|
|
--length;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* output with offsets */
|
|
|
|
while(length>0 && t<targetLimit) {
|
|
|
|
*t++=*uchars++;
|
|
|
|
*o++=sourceIndex;
|
|
|
|
--length;
|
|
|
|
}
|
|
|
|
*offsets=o;
|
|
|
|
}
|
|
|
|
*target=t;
|
|
|
|
|
|
|
|
/* write overflow */
|
|
|
|
if(length>0) {
|
|
|
|
if(cnv!=NULL) {
|
|
|
|
t=cnv->UCharErrorBuffer;
|
|
|
|
cnv->UCharErrorBufferLength=(int8_t)length;
|
|
|
|
do {
|
|
|
|
*t++=*uchars++;
|
|
|
|
} while(--length>0);
|
|
|
|
}
|
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-01 15:05:35 +00:00
|
|
|
U_CFUNC void
|
|
|
|
ucnv_toUWriteCodePoint(UConverter *cnv,
|
|
|
|
UChar32 c,
|
|
|
|
UChar **target, const UChar *targetLimit,
|
|
|
|
int32_t **offsets,
|
|
|
|
int32_t sourceIndex,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
UChar *t;
|
|
|
|
int32_t *o;
|
|
|
|
|
|
|
|
t=*target;
|
|
|
|
|
|
|
|
if(t<targetLimit) {
|
|
|
|
if(c<=0xffff) {
|
|
|
|
*t++=(UChar)c;
|
|
|
|
c=U_SENTINEL;
|
|
|
|
} else /* c is a supplementary code point */ {
|
|
|
|
*t++=U16_LEAD(c);
|
|
|
|
c=U16_TRAIL(c);
|
|
|
|
if(t<targetLimit) {
|
|
|
|
*t++=(UChar)c;
|
|
|
|
c=U_SENTINEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write offsets */
|
|
|
|
if(offsets!=NULL && (o=*offsets)!=NULL) {
|
|
|
|
*o++=sourceIndex;
|
|
|
|
if((*target+1)<t) {
|
|
|
|
*o++=sourceIndex;
|
|
|
|
}
|
|
|
|
*offsets=o;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*target=t;
|
|
|
|
|
|
|
|
/* write overflow from c */
|
|
|
|
if(c>=0) {
|
|
|
|
if(cnv!=NULL) {
|
|
|
|
int8_t i=0;
|
|
|
|
U16_APPEND_UNSAFE(cnv->UCharErrorBuffer, i, c);
|
|
|
|
cnv->UCharErrorBufferLength=i;
|
|
|
|
}
|
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2004-08-26 22:51:40 +00:00
|
|
|
|
|
|
|
#endif
|