1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 1999-2004, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
12 * Implements all the low level conversion functions
13 * T_UnicodeConverter_{to,from}Unicode_$ConversionType
17 * 06/29/2000 helena Major rewrite of the callback APIs.
20 #include "unicode/utypes.h"
22 #if !UCONFIG_NO_CONVERSION
24 #include "unicode/ucnv_err.h"
25 #include "unicode/ucnv.h"
26 #include "unicode/uset.h"
32 ucnv_getCompleteUnicodeSet(const UConverter
*cnv
,
34 UConverterUnicodeSet which
,
35 UErrorCode
*pErrorCode
) {
39 sa
->addRange(sa
->set
, 0, 0x10ffff);
43 ucnv_getNonSurrogateUnicodeSet(const UConverter
*cnv
,
45 UConverterUnicodeSet which
,
46 UErrorCode
*pErrorCode
) {
50 sa
->addRange(sa
->set
, 0, 0xd7ff);
51 sa
->addRange(sa
->set
, 0xe000, 0x10ffff);
55 ucnv_fromUWriteBytes(UConverter
*cnv
,
56 const char *bytes
, int32_t length
,
57 char **target
, const char *targetLimit
,
60 UErrorCode
*pErrorCode
) {
65 if(offsets
==NULL
|| (o
=*offsets
)==NULL
) {
66 while(length
>0 && t
<targetLimit
) {
71 /* output with offsets */
72 while(length
>0 && t
<targetLimit
) {
84 t
=(char *)cnv
->charErrorBuffer
;
85 cnv
->charErrorBufferLength
=(int8_t)length
;
87 *t
++=(uint8_t)*bytes
++;
90 *pErrorCode
=U_BUFFER_OVERFLOW_ERROR
;
95 ucnv_toUWriteUChars(UConverter
*cnv
,
96 const UChar
*uchars
, int32_t length
,
97 UChar
**target
, const UChar
*targetLimit
,
100 UErrorCode
*pErrorCode
) {
105 if(offsets
==NULL
|| (o
=*offsets
)==NULL
) {
106 while(length
>0 && t
<targetLimit
) {
111 /* output with offsets */
112 while(length
>0 && t
<targetLimit
) {
124 t
=cnv
->UCharErrorBuffer
;
125 cnv
->UCharErrorBufferLength
=(int8_t)length
;
130 *pErrorCode
=U_BUFFER_OVERFLOW_ERROR
;
135 ucnv_toUWriteCodePoint(UConverter
*cnv
,
137 UChar
**target
, const UChar
*targetLimit
,
140 UErrorCode
*pErrorCode
) {
150 } else /* c is a supplementary code point */ {
160 if(offsets
!=NULL
&& (o
=*offsets
)!=NULL
) {
171 /* write overflow from c */
175 U16_APPEND_UNSAFE(cnv
->UCharErrorBuffer
, i
, c
);
176 cnv
->UCharErrorBufferLength
=i
;
178 *pErrorCode
=U_BUFFER_OVERFLOW_ERROR
;