Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ****************************************************************************** |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 1999-2004, International Business Machines |
michael@0 | 5 | * Corporation and others. All Rights Reserved. |
michael@0 | 6 | * |
michael@0 | 7 | ****************************************************************************** |
michael@0 | 8 | * |
michael@0 | 9 | * uconv_cnv.c: |
michael@0 | 10 | * Implements all the low level conversion functions |
michael@0 | 11 | * T_UnicodeConverter_{to,from}Unicode_$ConversionType |
michael@0 | 12 | * |
michael@0 | 13 | * Change history: |
michael@0 | 14 | * |
michael@0 | 15 | * 06/29/2000 helena Major rewrite of the callback APIs. |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | #include "unicode/utypes.h" |
michael@0 | 19 | |
michael@0 | 20 | #if !UCONFIG_NO_CONVERSION |
michael@0 | 21 | |
michael@0 | 22 | #include "unicode/ucnv_err.h" |
michael@0 | 23 | #include "unicode/ucnv.h" |
michael@0 | 24 | #include "unicode/uset.h" |
michael@0 | 25 | #include "ucnv_cnv.h" |
michael@0 | 26 | #include "ucnv_bld.h" |
michael@0 | 27 | #include "cmemory.h" |
michael@0 | 28 | |
michael@0 | 29 | U_CFUNC void |
michael@0 | 30 | ucnv_getCompleteUnicodeSet(const UConverter *cnv, |
michael@0 | 31 | const USetAdder *sa, |
michael@0 | 32 | UConverterUnicodeSet which, |
michael@0 | 33 | UErrorCode *pErrorCode) { |
michael@0 | 34 | sa->addRange(sa->set, 0, 0x10ffff); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | U_CFUNC void |
michael@0 | 38 | ucnv_getNonSurrogateUnicodeSet(const UConverter *cnv, |
michael@0 | 39 | const USetAdder *sa, |
michael@0 | 40 | UConverterUnicodeSet which, |
michael@0 | 41 | UErrorCode *pErrorCode) { |
michael@0 | 42 | sa->addRange(sa->set, 0, 0xd7ff); |
michael@0 | 43 | sa->addRange(sa->set, 0xe000, 0x10ffff); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | U_CFUNC void |
michael@0 | 47 | ucnv_fromUWriteBytes(UConverter *cnv, |
michael@0 | 48 | const char *bytes, int32_t length, |
michael@0 | 49 | char **target, const char *targetLimit, |
michael@0 | 50 | int32_t **offsets, |
michael@0 | 51 | int32_t sourceIndex, |
michael@0 | 52 | UErrorCode *pErrorCode) { |
michael@0 | 53 | char *t=*target; |
michael@0 | 54 | int32_t *o; |
michael@0 | 55 | |
michael@0 | 56 | /* write bytes */ |
michael@0 | 57 | if(offsets==NULL || (o=*offsets)==NULL) { |
michael@0 | 58 | while(length>0 && t<targetLimit) { |
michael@0 | 59 | *t++=*bytes++; |
michael@0 | 60 | --length; |
michael@0 | 61 | } |
michael@0 | 62 | } else { |
michael@0 | 63 | /* output with offsets */ |
michael@0 | 64 | while(length>0 && t<targetLimit) { |
michael@0 | 65 | *t++=*bytes++; |
michael@0 | 66 | *o++=sourceIndex; |
michael@0 | 67 | --length; |
michael@0 | 68 | } |
michael@0 | 69 | *offsets=o; |
michael@0 | 70 | } |
michael@0 | 71 | *target=t; |
michael@0 | 72 | |
michael@0 | 73 | /* write overflow */ |
michael@0 | 74 | if(length>0) { |
michael@0 | 75 | if(cnv!=NULL) { |
michael@0 | 76 | t=(char *)cnv->charErrorBuffer; |
michael@0 | 77 | cnv->charErrorBufferLength=(int8_t)length; |
michael@0 | 78 | do { |
michael@0 | 79 | *t++=(uint8_t)*bytes++; |
michael@0 | 80 | } while(--length>0); |
michael@0 | 81 | } |
michael@0 | 82 | *pErrorCode=U_BUFFER_OVERFLOW_ERROR; |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | U_CFUNC void |
michael@0 | 87 | ucnv_toUWriteUChars(UConverter *cnv, |
michael@0 | 88 | const UChar *uchars, int32_t length, |
michael@0 | 89 | UChar **target, const UChar *targetLimit, |
michael@0 | 90 | int32_t **offsets, |
michael@0 | 91 | int32_t sourceIndex, |
michael@0 | 92 | UErrorCode *pErrorCode) { |
michael@0 | 93 | UChar *t=*target; |
michael@0 | 94 | int32_t *o; |
michael@0 | 95 | |
michael@0 | 96 | /* write UChars */ |
michael@0 | 97 | if(offsets==NULL || (o=*offsets)==NULL) { |
michael@0 | 98 | while(length>0 && t<targetLimit) { |
michael@0 | 99 | *t++=*uchars++; |
michael@0 | 100 | --length; |
michael@0 | 101 | } |
michael@0 | 102 | } else { |
michael@0 | 103 | /* output with offsets */ |
michael@0 | 104 | while(length>0 && t<targetLimit) { |
michael@0 | 105 | *t++=*uchars++; |
michael@0 | 106 | *o++=sourceIndex; |
michael@0 | 107 | --length; |
michael@0 | 108 | } |
michael@0 | 109 | *offsets=o; |
michael@0 | 110 | } |
michael@0 | 111 | *target=t; |
michael@0 | 112 | |
michael@0 | 113 | /* write overflow */ |
michael@0 | 114 | if(length>0) { |
michael@0 | 115 | if(cnv!=NULL) { |
michael@0 | 116 | t=cnv->UCharErrorBuffer; |
michael@0 | 117 | cnv->UCharErrorBufferLength=(int8_t)length; |
michael@0 | 118 | do { |
michael@0 | 119 | *t++=*uchars++; |
michael@0 | 120 | } while(--length>0); |
michael@0 | 121 | } |
michael@0 | 122 | *pErrorCode=U_BUFFER_OVERFLOW_ERROR; |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | U_CFUNC void |
michael@0 | 127 | ucnv_toUWriteCodePoint(UConverter *cnv, |
michael@0 | 128 | UChar32 c, |
michael@0 | 129 | UChar **target, const UChar *targetLimit, |
michael@0 | 130 | int32_t **offsets, |
michael@0 | 131 | int32_t sourceIndex, |
michael@0 | 132 | UErrorCode *pErrorCode) { |
michael@0 | 133 | UChar *t; |
michael@0 | 134 | int32_t *o; |
michael@0 | 135 | |
michael@0 | 136 | t=*target; |
michael@0 | 137 | |
michael@0 | 138 | if(t<targetLimit) { |
michael@0 | 139 | if(c<=0xffff) { |
michael@0 | 140 | *t++=(UChar)c; |
michael@0 | 141 | c=U_SENTINEL; |
michael@0 | 142 | } else /* c is a supplementary code point */ { |
michael@0 | 143 | *t++=U16_LEAD(c); |
michael@0 | 144 | c=U16_TRAIL(c); |
michael@0 | 145 | if(t<targetLimit) { |
michael@0 | 146 | *t++=(UChar)c; |
michael@0 | 147 | c=U_SENTINEL; |
michael@0 | 148 | } |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | /* write offsets */ |
michael@0 | 152 | if(offsets!=NULL && (o=*offsets)!=NULL) { |
michael@0 | 153 | *o++=sourceIndex; |
michael@0 | 154 | if((*target+1)<t) { |
michael@0 | 155 | *o++=sourceIndex; |
michael@0 | 156 | } |
michael@0 | 157 | *offsets=o; |
michael@0 | 158 | } |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | *target=t; |
michael@0 | 162 | |
michael@0 | 163 | /* write overflow from c */ |
michael@0 | 164 | if(c>=0) { |
michael@0 | 165 | if(cnv!=NULL) { |
michael@0 | 166 | int8_t i=0; |
michael@0 | 167 | U16_APPEND_UNSAFE(cnv->UCharErrorBuffer, i, c); |
michael@0 | 168 | cnv->UCharErrorBufferLength=i; |
michael@0 | 169 | } |
michael@0 | 170 | *pErrorCode=U_BUFFER_OVERFLOW_ERROR; |
michael@0 | 171 | } |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | #endif |