diff --git a/icu4c/source/common/Makefile.in b/icu4c/source/common/Makefile.in index 8a345103adf..c02c56bbf31 100644 --- a/icu4c/source/common/Makefile.in +++ b/icu4c/source/common/Makefile.in @@ -71,7 +71,7 @@ LIBS = @LIBS@ OBJECTS = chariter.o umutex.o compdata.o compitr.o convert.o \ cpputils.o cstring.o dcmpdata.o digitlst.o filestrm.o umemstrm.o locid.o locmap.o \ mutex.o normlzr.o putil.o resbund.o schriter.o scsu.o \ -uchar.o uchriter.o ucmp8.o ucmp16.o ucmp32.o ucnv.o ucnv_bld.o \ +uchar.o uchriter.o ucmp8.o ucmp16.o ucmp32.o ucnv.o ucnv_bld.o ucnv_cb.o \ ucnv_cnv.o ucnv_err.o ucnv_io.o uhash.o uhash_us.o uloc.o unicode.o unistr.o \ uresbund.o uresdata.o ustring.o rbdata.o ubidi.o ubidiln.o \ bidi.o uvector.o udata.o unames.o utf_impl.o \ diff --git a/icu4c/source/common/common.dsp b/icu4c/source/common/common.dsp index a1e11be28fe..0c2943d3e40 100644 --- a/icu4c/source/common/common.dsp +++ b/icu4c/source/common/common.dsp @@ -306,6 +306,10 @@ SOURCE=.\ucnv_bld.c # End Source File # Begin Source File +SOURCE=.\ucnv_cb.c +# End Source File +# Begin Source File + SOURCE=.\ucnv_cnv.c # End Source File # Begin Source File @@ -884,29 +888,10 @@ InputPath=.\unicode\ucnv.h # Begin Source File SOURCE=.\unicode\ucnv_bld.h +# End Source File +# Begin Source File -!IF "$(CFG)" == "common - Win32 Release" - -# Begin Custom Build -InputPath=.\unicode\ucnv_bld.h - -"..\..\include\unicode\ucnv_bld.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - copy unicode\ucnv_bld.h ..\..\include\unicode - -# End Custom Build - -!ELSEIF "$(CFG)" == "common - Win32 Debug" - -# Begin Custom Build -InputPath=.\unicode\ucnv_bld.h - -"..\..\include\unicode\ucnv_bld.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - copy unicode\ucnv_bld.h ..\..\include\unicode - -# End Custom Build - -!ENDIF - +SOURCE=.\unicode\ucnv_cb.h # End Source File # Begin Source File diff --git a/icu4c/source/common/convert.cpp b/icu4c/source/common/convert.cpp index dd43243d26f..57177c86fc6 100644 --- a/icu4c/source/common/convert.cpp +++ b/icu4c/source/common/convert.cpp @@ -16,7 +16,8 @@ class Mutex; #include "mutex.h" extern "C" { #include "ucnv_io.h" -#include "unicode/ucnv_bld.h" +#include "unicode/ucnv_err.h" +#include "ucnv_bld.h" #include "unicode/ucnv.h" } #include "unicode/convert.h" @@ -337,17 +338,23 @@ UnicodeConverterCPP::getMissingUnicodeAction() const void -UnicodeConverterCPP::setMissingCharAction(UConverterToUCallback action, +UnicodeConverterCPP::setMissingCharAction(UConverterToUCallback newAction, + void *newContext, + UConverterToUCallback oldAction, + void **oldContext, UErrorCode& err) { - ucnv_setToUCallBack(myUnicodeConverter, action, &err); + ucnv_setToUCallBack(myUnicodeConverter, newAction, newContext, oldAction, oldContext, &err); } void -UnicodeConverterCPP::setMissingUnicodeAction(UConverterFromUCallback action, +UnicodeConverterCPP::setMissingUnicodeAction(UConverterFromUCallback newAction, + void* newContext, + UConverterFromUCallback oldAction, + void** oldContext, UErrorCode& err) { - ucnv_setFromUCallBack(myUnicodeConverter, action, &err); + ucnv_setFromUCallBack(myUnicodeConverter, newAction, newContext, oldAction, oldContext, &err); } diff --git a/icu4c/source/common/ucnv.c b/icu4c/source/common/ucnv.c index ea48b31c872..6332f469e54 100644 --- a/icu4c/source/common/ucnv.c +++ b/icu4c/source/common/ucnv.c @@ -23,7 +23,6 @@ #include "uhash.h" #include "ucmp16.h" #include "ucmp8.h" -#include "unicode/ucnv_bld.h" #include "ucnv_io.h" #include "unicode/ucnv_err.h" #include "ucnv_cnv.h" @@ -33,6 +32,7 @@ #include "cstring.h" #include "unicode/ustring.h" #include "unicode/uloc.h" +#include "ucnv_bld.h" #define CHUNK_SIZE 5*1024 @@ -394,32 +394,37 @@ UConverterFromUCallback ucnv_getFromUCallBack (const UConverter * converter) return converter->fromUCharErrorBehaviour; } -UConverterToUCallback ucnv_setToUCallBack (UConverter * converter, - UConverterToUCallback action, +void ucnv_setToUCallBack (UConverter * converter, + UConverterToUCallback newAction, + void* newContext, + UConverterToUCallback oldAction, + void** oldContext, UErrorCode * err) { UConverterToUCallback myReturn = NULL; if (U_FAILURE (*err)) - return NULL; - myReturn = converter->fromCharErrorBehaviour; - converter->fromCharErrorBehaviour = action; - - return myReturn; + return; + oldAction = converter->fromCharErrorBehaviour; + converter->fromCharErrorBehaviour = newAction; + oldContext = converter->toUContext; + converter->toUContext = newContext; } -UConverterFromUCallback ucnv_setFromUCallBack (UConverter * converter, - UConverterFromUCallback action, - UErrorCode * err) +void ucnv_setFromUCallBack (UConverter * converter, + UConverterFromUCallback newAction, + void* newContext, + UConverterFromUCallback oldAction, + void** oldContext, + UErrorCode * err) { - UConverterFromUCallback myReturn = NULL; if (U_FAILURE (*err)) - return NULL; - myReturn = converter->fromUCharErrorBehaviour; - converter->fromUCharErrorBehaviour = action; - - return myReturn; + return; + oldAction = converter->fromUCharErrorBehaviour; + converter->fromUCharErrorBehaviour = newAction; + oldContext = converter->fromUContext; + converter->fromUContext = newContext; } void ucnv_fromUnicode (UConverter * _this, char **target, diff --git a/icu4c/source/common/ucnv2022.c b/icu4c/source/common/ucnv2022.c index 22a807a6ee9..eb286df00e7 100644 --- a/icu4c/source/common/ucnv2022.c +++ b/icu4c/source/common/ucnv2022.c @@ -10,13 +10,18 @@ * * created on: 2000feb03 * created by: Markus W. Scherer +* +* Change history: +* +* 06/29/2000 helena Major rewrite of the callback APIs. */ #include "unicode/utypes.h" #include "cmemory.h" #include "ucmp16.h" #include "ucmp8.h" -#include "unicode/ucnv_bld.h" +#include "unicode/ucnv_err.h" +#include "ucnv_bld.h" #include "unicode/ucnv.h" #include "ucnv_cnv.h" @@ -719,8 +724,8 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL (UConverter * _this, UBool flush, UErrorCode * err) { - const char *mySource = *source; - UChar *myTarget = *target; + const char *mySource = *source, *srcTemp; + UChar *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -729,10 +734,11 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL (UConverter * _this, UChar targetUniChar = 0x0000; UChar mySourceChar = 0x0000; int32_t myMode = _this->mode; + UConverterToUnicodeArgs args; myToUnicode = &_this->sharedData->table->dbcs.toUnicode; - + args.sourceStart = *source; while (mySourceIndex < sourceLength) { if (myTargetIndex < targetLength) @@ -783,19 +789,28 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL (UConverter * _this, _this->invalidCharBuffer[0] = (char) mySourceChar; } _this->mode = myMode; - ToU_CALLBACK_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, + args.converter = _this; + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + + ToU_CALLBACK_MACRO(_this->toUContext, + args, + srcTemp, + 1, + UCNV_UNASSIGNED, err); if (U_FAILURE (*err)) break; _this->invalidCharLength = 0; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; } } } @@ -836,8 +851,8 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this, UBool flush, UErrorCode * err) { - const char *mySource = *source; - UChar *myTarget = *target; + const char *mySource = *source, *srcTemp; + UChar *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -847,9 +862,10 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this, UChar mySourceChar = 0x0000; int32_t myMode = _this->mode; int32_t* originalOffsets = offsets; - + UConverterToUnicodeArgs args; myToUnicode = &_this->sharedData->table->dbcs.toUnicode; + args.sourceStart = *source; while (mySourceIndex < sourceLength) { @@ -909,20 +925,29 @@ void T_UConverter_toUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this, _this->invalidCharBuffer[0] = (char) mySourceChar; } _this->mode = myMode; - ToU_CALLBACK_OFFSETS_LOGIC_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); - + + args.converter = _this; + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + /* call back handles the offset array */ + ToU_CALLBACK_MACRO(_this->toUContext, + args, + srcTemp, + 1, + UCNV_UNASSIGNED, + err); if (U_FAILURE (*err)) break; _this->invalidCharLength = 0; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; } } } @@ -964,8 +989,8 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL (UConverter * _this, UErrorCode * err) { - const UChar *mySource = *source; - char *myTarget = *target; + const UChar *mySource = *source, *srcTemp; + char *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -976,8 +1001,10 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL (UConverter * _this, UChar mySourceChar = 0x0000; UBool isTargetUCharDBCS = (UBool)_this->fromUnicodeStatus; UBool oldIsTargetUCharDBCS = isTargetUCharDBCS; + UConverterFromUnicodeArgs args; + myFromUnicode = &_this->sharedData->table->dbcs.fromUnicode; - + args.sourceStart = *source; /*writing the char to the output stream */ while (mySourceIndex < sourceLength) { @@ -1042,19 +1069,28 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL (UConverter * _this, _this->invalidUCharLength = 1; _this->fromUnicodeStatus = (int32_t)isTargetUCharDBCS; - FromU_CALLBACK_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); - + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.converter = _this; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + /* HSYS: to do: more smarts */ + FromU_CALLBACK_MACRO(args.converter->fromUContext, + args, + srcTemp, + 1, + (UChar32) (*srcTemp), + UCNV_UNASSIGNED, + err); if (U_FAILURE (*err)) break; _this->invalidUCharLength = 0; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; } } else @@ -1084,8 +1120,8 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this, UErrorCode * err) { - const UChar *mySource = *source; - char *myTarget = *target; + const UChar *mySource = *source, *srcTemp; + char *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -1097,9 +1133,10 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this, UBool isTargetUCharDBCS = (UBool)_this->fromUnicodeStatus; UBool oldIsTargetUCharDBCS = isTargetUCharDBCS; int32_t* originalOffsets = offsets; + UConverterFromUnicodeArgs args; myFromUnicode = &_this->sharedData->table->dbcs.fromUnicode; - + args.sourceStart = *source; /*writing the char to the output stream */ while (mySourceIndex < sourceLength) { @@ -1168,19 +1205,29 @@ void T_UConverter_fromUnicode_EBCDIC_STATEFUL_OFFSETS_LOGIC (UConverter * _this, /* Breaks out of the loop since behaviour was set to stop */ _this->fromUnicodeStatus = (int32_t)isTargetUCharDBCS; - FromU_CALLBACK_OFFSETS_LOGIC_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.converter = _this; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + /* HSYS: to do: more smarts, including offsets */ + FromU_CALLBACK_MACRO(args.converter->fromUContext, + args, + srcTemp, + 1, + (UChar32) (*srcTemp), + UCNV_UNASSIGNED, + err); if (U_FAILURE (*err)) break; _this->invalidUCharLength = 0; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; } } else @@ -1207,6 +1254,7 @@ UChar32 T_UConverter_getNextUChar_EBCDIC_STATEFUL(UConverter* converter, { UChar myUChar; char const *sourceInitial = *source; + UConverterToUnicodeArgs args; /*safe keeps a ptr to the beginning in case we need to step back*/ /*Input boundary check*/ @@ -1216,6 +1264,7 @@ UChar32 T_UConverter_getNextUChar_EBCDIC_STATEFUL(UConverter* converter, return 0xFFFD; } + args.sourceStart = *source; /*Checks to see if with have SI/SO shifters if we do we change the mode appropriately and we consume the byte*/ if ((**source == UCNV_SI) || (**source == UCNV_SO)) @@ -1266,14 +1315,21 @@ UChar32 T_UConverter_getNextUChar_EBCDIC_STATEFUL(UConverter* converter, /*It's is very likely that the ErrorFunctor will write to the *internal buffers */ - converter->fromCharErrorBehaviour(converter, - &myUCharPtr, - myUCharPtr + 1, - &sourceFinal, - sourceLimit, - NULL, - TRUE, - err); + args.converter = converter; + args.pTarget = &myUCharPtr; + args.targetLimit = myUCharPtr + 1; + args.pSource = &sourceFinal; + args.sourceLimit = sourceLimit; + args.flush = TRUE; + args.offsets = NULL; + args.size = sizeof(args); + + converter->fromCharErrorBehaviour(converter->toUContext, + &args, + sourceFinal, + 1, + UCNV_UNASSIGNED, + err); /*makes the internal caching transparent to the user*/ if (*err == U_INDEX_OUTOFBOUNDS_ERROR) *err = U_ZERO_ERROR; diff --git a/icu4c/source/common/ucnv_bld.c b/icu4c/source/common/ucnv_bld.c index c16271fa273..a68a0c828ac 100644 --- a/icu4c/source/common/ucnv_bld.c +++ b/icu4c/source/common/ucnv_bld.c @@ -16,6 +16,7 @@ * Date Name Description * * 06/20/2000 helena OS/400 port changes; mostly typecast. + * 06/29/2000 helena Major rewrite of the callback interface. */ @@ -23,7 +24,7 @@ #include "uhash.h" #include "ucmp16.h" #include "ucmp8.h" -#include "unicode/ucnv_bld.h" +#include "ucnv_bld.h" #include "unicode/ucnv_err.h" #include "ucnv_cnv.h" #include "ucnv_imp.h" diff --git a/icu4c/source/common/ucnv_cnv.c b/icu4c/source/common/ucnv_cnv.c index c35c876a05b..8c6ebe3365d 100644 --- a/icu4c/source/common/ucnv_cnv.c +++ b/icu4c/source/common/ucnv_cnv.c @@ -10,10 +10,12 @@ * Implements all the low level conversion functions * T_UnicodeConverter_{to,from}Unicode_$ConversionType * +* Change history: +* +* 06/29/2000 helena Major rewrite of the callback APIs. */ #include "unicode/utypes.h" -#include "unicode/ucnv_bld.h" #include "unicode/ucnv_err.h" #include "ucnv_cnv.h" #include "unicode/ucnv.h" diff --git a/icu4c/source/common/ucnv_cnv.h b/icu4c/source/common/ucnv_cnv.h index 61d36695fad..1e13c4cb21e 100644 --- a/icu4c/source/common/ucnv_cnv.h +++ b/icu4c/source/common/ucnv_cnv.h @@ -12,14 +12,15 @@ * * Date Name Description * 05/09/00 helena Added implementation to handle fallback mappings. +* 06/29/2000 helena Major rewrite of the callback APIs. */ #ifndef UCNV_CNV_H #define UCNV_CNV_H #include "unicode/utypes.h" -#include "unicode/ucnv_bld.h" - +#include "unicode/ucnv_err.h" +#include "ucnv_bld.h" #include "ucmp8.h" #include "ucmp16.h" @@ -65,90 +66,35 @@ U_CDECL_BEGIN #define missingCharMarker 0xFFFF #define missingUCharMarker 0xFFFD -#define FromU_CALLBACK_MACRO(_this, myTarget, myTargetIndex, targetLimit, mySource, mySourceIndex, sourceLimit, offsets, flush, err) \ - if (_this->fromUCharErrorBehaviour == (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_STOP) break;\ +#define FromU_CALLBACK_MACRO(context, args, codeUnits, length, codePoint, reason, err) \ + if (args.converter->fromUCharErrorBehaviour == (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_STOP) break;\ else \ { \ - char *myTargetCopy = myTarget + myTargetIndex; \ - const UChar *mySourceCopy = mySource + mySourceIndex; \ /*copies current values for the ErrorFunctor to update */ \ /*Calls the ErrorFunctor */ \ - _this->fromUCharErrorBehaviour (_this, \ - (char **) &myTargetCopy, \ - targetLimit, \ - (const UChar **) &mySourceCopy, \ - sourceLimit, \ - offsets, \ - flush, \ + args.converter->fromUCharErrorBehaviour ( context, \ + &args, \ + codeUnits, \ + length, \ + codePoint, \ + reason, \ err); \ - /*Update the local Indexes so that the conversion can restart at the right points */ \ - mySourceIndex = (mySourceCopy - mySource) ; \ - myTargetIndex = (char*)myTargetCopy - (char*)myTarget ; \ } -#define ToU_CALLBACK_MACRO(_this, myTarget, myTargetIndex, targetLimit, mySource, mySourceIndex, sourceLimit, offsets, flush, err) \ - if (_this->fromCharErrorBehaviour == (UConverterToUCallback) UCNV_TO_U_CALLBACK_STOP) break; \ +#define ToU_CALLBACK_MACRO(context, args, codePoints, length, reason, err) \ + if (args.converter->fromCharErrorBehaviour == (UConverterToUCallback) UCNV_TO_U_CALLBACK_STOP) break; \ else \ { \ - UChar *myTargetCopy = myTarget + myTargetIndex; \ - const char *mySourceCopy = mySource + mySourceIndex; \ /*Calls the ErrorFunctor */ \ - _this->fromCharErrorBehaviour (_this, \ - &myTargetCopy, \ - targetLimit, \ - (const char **) &mySourceCopy, \ - sourceLimit, \ - offsets, \ - flush, \ + args.converter->fromCharErrorBehaviour ( \ + context, \ + &args, \ + codePoints, \ + length, \ + reason, \ err); \ - /*Update the local Indexes so that the conversion can restart at the right points */ \ - mySourceIndex = ((char*)mySourceCopy - (char*)mySource); \ - myTargetIndex = (myTargetCopy - myTarget); \ } -#define FromU_CALLBACK_OFFSETS_LOGIC_MACRO(_this, myTarget, myTargetIndex, targetLimit, mySource, mySourceIndex, sourceLimit, offsets, flush, err) \ - if (_this->fromUCharErrorBehaviour == (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_STOP) break;\ - else \ - { \ - char *myTargetCopy = myTarget + myTargetIndex; \ - const UChar *mySourceCopy = mySource + mySourceIndex; \ - int32_t My_i = myTargetIndex; \ - /*copies current values for the ErrorFunctor to update */ \ - /*Calls the ErrorFunctor */ \ - _this->fromUCharErrorBehaviour (_this, \ - (char **) &myTargetCopy, \ - targetLimit, \ - (const UChar **) &mySourceCopy, \ - sourceLimit, \ - offsets + myTargetIndex, \ - flush, \ - err); \ - /*Update the local Indexes so that the conversion can restart at the right points */ \ - mySourceIndex = mySourceCopy - mySource ; \ - myTargetIndex = (char*)myTargetCopy - (char*)myTarget ; \ - for (;My_i < myTargetIndex;My_i++) offsets[My_i] += currentOffset ; \ - } - -#define ToU_CALLBACK_OFFSETS_LOGIC_MACRO(_this, myTarget, myTargetIndex, targetLimit, mySource, mySourceIndex, sourceLimit, offsets, flush, err) \ - if (_this->fromCharErrorBehaviour == (UConverterToUCallback) UCNV_TO_U_CALLBACK_STOP) break; \ - else \ - { \ - UChar *myTargetCopy = myTarget + myTargetIndex; \ - const char *mySourceCopy = mySource + mySourceIndex; \ - int32_t My_i = myTargetIndex; \ - _this->fromCharErrorBehaviour (_this, \ - &myTargetCopy, \ - targetLimit, \ - (const char **) &mySourceCopy, \ - sourceLimit, \ - offsets + myTargetIndex, \ - flush, \ - err); \ - /*Update the local Indexes so that the conversion can restart at the right points */ \ - mySourceIndex = (char *)mySourceCopy - (char*)mySource; \ - myTargetIndex = ((UChar*)myTargetCopy - (UChar*)myTarget); \ - for (;My_i < myTargetIndex;My_i++) {offsets[My_i] += currentOffset ; } \ - } typedef void (*UConverterLoad) (UConverterSharedData *sharedData, const uint8_t *raw, UErrorCode *pErrorCode); typedef void (*UConverterUnload) (UConverterSharedData *sharedData); diff --git a/icu4c/source/common/ucnv_err.c b/icu4c/source/common/ucnv_err.c index a89290fe5d8..d7f4c4158c0 100644 --- a/icu4c/source/common/ucnv_err.c +++ b/icu4c/source/common/ucnv_err.c @@ -9,11 +9,14 @@ * ucnv_err.c * Implements error behaviour functions called by T_UConverter_{from,to}Unicode * - */ + * +* Change history: +* +* 06/29/2000 helena Major rewrite of the callback APIs. +*/ #include "ucmp8.h" #include "ucmp16.h" -#include "unicode/ucnv_bld.h" #include "unicode/ucnv_err.h" #include "ucnv_cnv.h" #include "cmemory.h" @@ -72,53 +75,54 @@ static void itou (UChar * buffer, int32_t i, int32_t radix, int32_t pad) } /*Function Pointer STOPS at the ILLEGAL_SEQUENCE */ -void UCNV_FROM_U_CALLBACK_STOP (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t *offsets, - UBool flush, +void UCNV_FROM_U_CALLBACK_STOP ( + void *context, + UConverterFromUnicodeArgs *fromUArgs, + const UChar* codeUnits, + int32_t length, + UChar32 codePoint, + UConverterCallbackReason reason, UErrorCode * err) { + reason = UCNV_ILLEGAL; return; } /*Function Pointer STOPS at the ILLEGAL_SEQUENCE */ -void UCNV_TO_U_CALLBACK_STOP (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t *offsets, - UBool flush, +void UCNV_TO_U_CALLBACK_STOP ( + void *context, + UConverterToUnicodeArgs *toUArgs, + const char* codePoints, + int32_t length, + UConverterCallbackReason reason, UErrorCode * err) { + reason = UCNV_ILLEGAL; return; } -void UCNV_FROM_U_CALLBACK_SKIP (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t *offsets, - UBool flush, +void UCNV_FROM_U_CALLBACK_SKIP ( + void *context, + UConverterFromUnicodeArgs *fromUArgs, + const UChar* codeUnits, + int32_t length, + UChar32 codePoint, + UConverterCallbackReason reason, UErrorCode * err) { if (CONVERSION_U_SUCCESS (*err)) return; *err = U_ZERO_ERROR; } -void UCNV_FROM_U_CALLBACK_SUBSTITUTE (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t *offsets, - UBool flush, - UErrorCode * err) +void UCNV_FROM_U_CALLBACK_SUBSTITUTE ( + void *context, + UConverterFromUnicodeArgs *fromArgs, + const UChar* codeUnits, + int32_t length, + UChar32 codePoint, + UConverterCallbackReason reason, + UErrorCode * err) { char togo[5]; int32_t togoLen; @@ -129,21 +133,21 @@ void UCNV_FROM_U_CALLBACK_SUBSTITUTE (UConverter * _this, /*In case we're dealing with a modal converter a la UCNV_EBCDIC_STATEFUL, we need to make sure that the emitting of the substitution charater in the right mode*/ - uprv_memcpy(togo, _this->subChar, togoLen = _this->subCharLen); - if (ucnv_getType(_this) == UCNV_EBCDIC_STATEFUL) + uprv_memcpy(togo, fromArgs->converter->subChar, togoLen = fromArgs->converter->subCharLen); + if (ucnv_getType(fromArgs->converter) == UCNV_EBCDIC_STATEFUL) { - if ((_this->fromUnicodeStatus)&&(togoLen != 2)) + if ((fromArgs->converter->fromUnicodeStatus)&&(togoLen != 2)) { togo[0] = UCNV_SI; - togo[1] = _this->subChar[0]; + togo[1] = fromArgs->converter->subChar[0]; togo[2] = UCNV_SO; togoLen = 3; } - else if (!(_this->fromUnicodeStatus)&&(togoLen != 1)) + else if (!(fromArgs->converter->fromUnicodeStatus)&&(togoLen != 1)) { togo[0] = UCNV_SO; - togo[1] = _this->subChar[0]; - togo[2] = _this->subChar[1]; + togo[1] = fromArgs->converter->subChar[0]; + togo[2] = fromArgs->converter->subChar[1]; togo[3] = UCNV_SI; togoLen = 4; } @@ -151,16 +155,16 @@ void UCNV_FROM_U_CALLBACK_SUBSTITUTE (UConverter * _this, /*if we have enough space on the output buffer we just copy the subchar there and update the pointer */ - if ((targetLimit - *target) >= togoLen) + if ((fromArgs->targetLimit - *(fromArgs->pTarget)) >= togoLen) { - uprv_memcpy (*target, togo, togoLen); - *target += togoLen; + uprv_memcpy (*(fromArgs->pTarget), togo, togoLen); + *(fromArgs->pTarget) += togoLen; *err = U_ZERO_ERROR; - if (offsets) + if (fromArgs->offsets) { int i=0; - for (i=0;ioffsets[i]=0; + fromArgs->offsets += togoLen; } } else @@ -170,18 +174,18 @@ void UCNV_FROM_U_CALLBACK_SUBSTITUTE (UConverter * _this, *copy the rest in the internal buffer, and increase the *length marker */ - uprv_memcpy (*target, togo, (targetLimit - *target)); - if (offsets) + uprv_memcpy (*(fromArgs->pTarget), togo, (fromArgs->targetLimit - *(fromArgs->pTarget))); + if (fromArgs->offsets) { int i=0; - for (i=0;i<(targetLimit - *target);i++) offsets[i]=0; - offsets += (targetLimit - *target); + for (i=0;i<(fromArgs->targetLimit - *(fromArgs->pTarget));i++) fromArgs->offsets[i]=0; + fromArgs->offsets += (fromArgs->targetLimit - *(fromArgs->pTarget)); } - uprv_memcpy (_this->charErrorBuffer + _this->charErrorBufferLength, - togo + (targetLimit - *target), - togoLen - (targetLimit - *target)); - _this->charErrorBufferLength += togoLen - (targetLimit - *target); - *target += (targetLimit - *target); + uprv_memcpy (fromArgs->converter->charErrorBuffer + fromArgs->converter->charErrorBufferLength, + togo + (fromArgs->targetLimit - *(fromArgs->pTarget)), + togoLen - (fromArgs->targetLimit - *(fromArgs->pTarget))); + fromArgs->converter->charErrorBufferLength += togoLen - (fromArgs->targetLimit - *(fromArgs->pTarget)); + *(fromArgs->pTarget) += (fromArgs->targetLimit - *(fromArgs->pTarget)); *err = U_INDEX_OUTOFBOUNDS_ERROR; } @@ -194,13 +198,13 @@ void UCNV_FROM_U_CALLBACK_SUBSTITUTE (UConverter * _this, *escape sequence to the target codepage (if conversion failure happens then *we revert to substituting with subchar) */ -void UCNV_FROM_U_CALLBACK_ESCAPE (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t *offsets, - UBool flush, +void UCNV_FROM_U_CALLBACK_ESCAPE ( + void *context, + UConverterFromUnicodeArgs *fromArgs, + const UChar *codeUnits, + int32_t length, + UChar32 codePoint, + UConverterCallbackReason reason, UErrorCode * err) { @@ -209,13 +213,13 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (UConverter * _this, UChar codepoint[CODEPOINT_STRING_LENGTH]; int32_t i = 0; /*Makes a bitwise copy of the converter passwd in */ - UConverter myConverter = *_this; + UConverter myConverter = *(fromArgs->converter); char myTarget[VALUE_STRING_LENGTH]; char *myTargetAlias = myTarget; const UChar *myValueSource = NULL; UErrorCode err2 = U_ZERO_ERROR; - uint32_t myFromUnicodeStatus = _this->fromUnicodeStatus; - + uint32_t myFromUnicodeStatus = fromArgs->converter->fromUnicodeStatus; + UConverterFromUCallback original = NULL; if (CONVERSION_U_SUCCESS (*err)) return; @@ -224,6 +228,9 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (UConverter * _this, ucnv_setFromUCallBack (&myConverter, (UConverterFromUCallback) UCNV_FROM_U_CALLBACK_STOP, + NULL, /* To Do for HSYS: context is null? */ + original, + NULL, &err2); if (U_FAILURE (err2)) { @@ -234,9 +241,9 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (UConverter * _this, codepoint[0] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */ codepoint[1] = (UChar) UNICODE_U_CODEPOINT; /* adding U */ - while (i < _this->invalidUCharLength) + while (i < fromArgs->converter->invalidUCharLength) { - itou (codepoint + 2, _this->invalidUCharBuffer[i++], 16, 4); + itou (codepoint + 2, fromArgs->converter->invalidUCharBuffer[i++], 16, 4); uprv_memcpy (valueString + valueStringLength, codepoint, sizeof (UChar) * 6); valueStringLength += CODEPOINT_STRING_LENGTH - 1; } @@ -255,13 +262,13 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (UConverter * _this, if (U_FAILURE (err2)) { - UCNV_FROM_U_CALLBACK_SUBSTITUTE (_this, - target, - targetLimit, - source, - sourceLimit, - offsets, - flush, + UCNV_FROM_U_CALLBACK_SUBSTITUTE ( + NULL, /* TO do for HSYS: context */ + fromArgs, + codeUnits, + length, + codePoint, + reason, err); return; } @@ -273,17 +280,17 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (UConverter * _this, /*if we have enough space on the output buffer we just copy * the subchar there and update the pointer */ - if ((targetLimit - *target) >= valueStringLength) + if ((fromArgs->targetLimit - *(fromArgs->pTarget)) >= valueStringLength) { - uprv_memcpy (*target, myTarget, valueStringLength); - *target += valueStringLength; + uprv_memcpy (*(fromArgs->pTarget), myTarget, valueStringLength); + *(fromArgs->pTarget) += valueStringLength; *err = U_ZERO_ERROR; - if (offsets) + if (fromArgs->offsets) { int j=0; - for (j=0;joffsets[j]=0; + fromArgs->offsets += valueStringLength; } } else @@ -294,18 +301,18 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (UConverter * _this, *length marker */ - if (offsets) + if (fromArgs->offsets) { int j=0; - for (j=0;j<(targetLimit - *target);j++) offsets[j]=0; - offsets += (targetLimit - *target); + for (j=0;j<(fromArgs->targetLimit - *(fromArgs->pTarget));j++) fromArgs->offsets[j]=0; + fromArgs->offsets += (fromArgs->targetLimit - *(fromArgs->pTarget)); } - uprv_memcpy (*target, myTarget, (targetLimit - *target)); - uprv_memcpy (_this->charErrorBuffer + _this->charErrorBufferLength, - myTarget + (targetLimit - *target), - valueStringLength - (targetLimit - *target)); - _this->charErrorBufferLength += valueStringLength - (targetLimit - *target); - *target += (targetLimit - *target); + uprv_memcpy (*(fromArgs->pTarget), myTarget, (fromArgs->targetLimit - *(fromArgs->pTarget))); + uprv_memcpy (fromArgs->converter->charErrorBuffer + fromArgs->converter->charErrorBufferLength, + myTarget + (fromArgs->targetLimit - *(fromArgs->pTarget)), + valueStringLength - (fromArgs->targetLimit - *(fromArgs->pTarget))); + fromArgs->converter->charErrorBufferLength += valueStringLength - (fromArgs->targetLimit - *(fromArgs->pTarget)); + *(fromArgs->pTarget) += (fromArgs->targetLimit - *(fromArgs->pTarget)); *err = U_INDEX_OUTOFBOUNDS_ERROR; } @@ -314,42 +321,40 @@ void UCNV_FROM_U_CALLBACK_ESCAPE (UConverter * _this, -void UCNV_TO_U_CALLBACK_SKIP (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t *offsets, - UBool flush, +void UCNV_TO_U_CALLBACK_SKIP ( + void *context, + UConverterToUnicodeArgs *toArgs, + const char* codeUnits, + int32_t length, + UConverterCallbackReason reason, UErrorCode * err) { if (CONVERSION_U_SUCCESS (*err)) return; *err = U_ZERO_ERROR; } -void UCNV_TO_U_CALLBACK_SUBSTITUTE (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t *offsets, - UBool flush, - UErrorCode * err) +void UCNV_TO_U_CALLBACK_SUBSTITUTE ( + void *context, + UConverterToUnicodeArgs *toArgs, + const char* codeUnits, + int32_t length, + UConverterCallbackReason reason, + UErrorCode * err) { if (CONVERSION_U_SUCCESS (*err)) return; - if ((targetLimit - *target) >= 1) + if ((toArgs->targetLimit - *(toArgs->pTarget)) >= 1) { - **target = 0xFFFD; - (*target)++; - if (offsets) *offsets = 0; + **(toArgs->pTarget) = 0xFFFD; + (*(toArgs->pTarget))++; + if (toArgs->offsets) *(toArgs->offsets) = 0; *err = U_ZERO_ERROR; } else { - _this->UCharErrorBuffer[_this->UCharErrorBufferLength] = 0xFFFD; - _this->UCharErrorBufferLength++; + toArgs->converter->UCharErrorBuffer[toArgs->converter->UCharErrorBufferLength] = 0xFFFD; + toArgs->converter->UCharErrorBufferLength++; *err = U_INDEX_OUTOFBOUNDS_ERROR; } @@ -360,14 +365,13 @@ void UCNV_TO_U_CALLBACK_SUBSTITUTE (UConverter * _this, /*uses itou to get a unicode escape sequence of the offensive sequence, *and uses that as the substitution sequence */ -void UCNV_TO_U_CALLBACK_ESCAPE (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t *offsets, - UBool flush, - UErrorCode * err) +void UCNV_TO_U_CALLBACK_ESCAPE ( + void *context, + UConverterToUnicodeArgs *toArgs, + const char* codeUnits, + int32_t length, + UConverterCallbackReason reason, + UErrorCode * err) { UChar uniValueString[VALUE_STRING_LENGTH]; int32_t valueStringLength = 0; @@ -379,24 +383,24 @@ void UCNV_TO_U_CALLBACK_ESCAPE (UConverter * _this, codepoint[0] = (UChar) UNICODE_PERCENT_SIGN_CODEPOINT; /* adding % */ codepoint[1] = (UChar) UNICODE_X_CODEPOINT; /* adding X */ - while (i < _this->invalidCharLength) + while (i < toArgs->converter->invalidCharLength) { - itou (codepoint + 2, _this->invalidCharBuffer[i++], 16, 2); + itou (codepoint + 2, toArgs->converter->invalidCharBuffer[i++], 16, 2); uprv_memcpy (uniValueString + valueStringLength, codepoint, sizeof (UChar) * 4); valueStringLength += 4; } - if ((targetLimit - *target) >= valueStringLength) + if ((toArgs->targetLimit - *(toArgs->pTarget)) >= valueStringLength) { /*if we have enough space on the output buffer we just copy * the subchar there and update the pointer */ - uprv_memcpy (*target, uniValueString, (sizeof (UChar)) * (valueStringLength)); - if (offsets) + uprv_memcpy (*(toArgs->pTarget), uniValueString, (sizeof (UChar)) * (valueStringLength)); + if (toArgs->offsets) { - for (i = 0; i < valueStringLength; i++) offsets[i] = 0; + for (i = 0; i < valueStringLength; i++) toArgs->offsets[i] = 0; } - *target += valueStringLength; + *(toArgs->pTarget) += valueStringLength; *err = U_ZERO_ERROR; } @@ -407,18 +411,18 @@ void UCNV_TO_U_CALLBACK_ESCAPE (UConverter * _this, *copy the rest in the internal buffer, and increase the *length marker */ - uprv_memcpy (*target, uniValueString, (sizeof (UChar)) * (targetLimit - *target)); - if (offsets) + uprv_memcpy (*(toArgs->pTarget), uniValueString, (sizeof (UChar)) * (toArgs->targetLimit - *(toArgs->pTarget))); + if (toArgs->offsets) { - for (i = 0; i < (targetLimit - *target); i++) offsets[i] = 0; + for (i = 0; i < (toArgs->targetLimit - *(toArgs->pTarget)); i++) toArgs->offsets[i] = 0; } - uprv_memcpy (_this->UCharErrorBuffer, - uniValueString + (targetLimit - *target), - (sizeof (UChar)) * (valueStringLength - (targetLimit - *target))); - _this->UCharErrorBufferLength += valueStringLength - (targetLimit - *target); - *target += (targetLimit - *target); + uprv_memcpy (toArgs->converter->UCharErrorBuffer, + uniValueString + (toArgs->targetLimit - *(toArgs->pTarget)), + (sizeof (UChar)) * (valueStringLength - (toArgs->targetLimit - *(toArgs->pTarget)))); + toArgs->converter->UCharErrorBufferLength += valueStringLength - (toArgs->targetLimit - *(toArgs->pTarget)); + *(toArgs->pTarget) += (toArgs->targetLimit - *(toArgs->pTarget)); *err = U_INDEX_OUTOFBOUNDS_ERROR; } diff --git a/icu4c/source/common/ucnv_imp.h b/icu4c/source/common/ucnv_imp.h index 2ffb67b08ca..3d83ea31427 100644 --- a/icu4c/source/common/ucnv_imp.h +++ b/icu4c/source/common/ucnv_imp.h @@ -21,6 +21,7 @@ #define UCNV_IMP_H #include "unicode/utypes.h" +#include "ucnv_bld.h" #ifndef UHASH_H typedef struct _UHashtable UHashtable; diff --git a/icu4c/source/common/ucnv_lmb.c b/icu4c/source/common/ucnv_lmb.c index 671b65ab1f3..2793ce5da15 100644 --- a/icu4c/source/common/ucnv_lmb.c +++ b/icu4c/source/common/ucnv_lmb.c @@ -26,7 +26,8 @@ #include "cmemory.h" #include "ucmp16.h" #include "ucmp8.h" -#include "unicode/ucnv_bld.h" +#include "unicode/ucnv_err.h" +#include "ucnv_bld.h" #include "unicode/ucnv.h" #include "ucnv_cnv.h" diff --git a/icu4c/source/common/ucnv_utf.c b/icu4c/source/common/ucnv_utf.c index 68d67242682..f7676177fc5 100644 --- a/icu4c/source/common/ucnv_utf.c +++ b/icu4c/source/common/ucnv_utf.c @@ -10,12 +10,17 @@ * * created on: 2000feb03 * created by: Markus W. Scherer +* +* Change history: +* +* 06/29/2000 helena Major rewrite of the callback APIs. */ #include "unicode/utypes.h" #include "ucmp16.h" #include "ucmp8.h" -#include "unicode/ucnv_bld.h" +#include "unicode/ucnv_err.h" +#include "ucnv_bld.h" #include "unicode/ucnv.h" #include "ucnv_cnv.h" @@ -65,8 +70,8 @@ void T_UConverter_toUnicode_UTF8 (UConverter * _this, UBool flush, UErrorCode * err) { - const unsigned char *mySource = (unsigned char *) *source; - UChar *myTarget = *target; + const unsigned char *mySource = (unsigned char *) *source, *srcTemp; + UChar *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -75,7 +80,9 @@ void T_UConverter_toUnicode_UTF8 (UConverter * _this, ch2 =0 , i =0; /* Index into the current # of bytes consumed in the current sequence */ uint32_t inBytes = 0; /* Total number of bytes in the current UTF8 sequence */ + UConverterToUnicodeArgs args; + args.sourceStart = *source; if (_this->toUnicodeStatus) { i = _this->invalidCharLength; /* restore # of bytes consumed */ @@ -170,18 +177,26 @@ void T_UConverter_toUnicode_UTF8 (UConverter * _this, printf("inbytes %d\n, _this->invalidCharLength = %d,\n mySource[mySourceIndex]=%X\n", inBytes, _this->invalidCharLength, mySource[mySourceIndex]); #endif /* Needed explicit cast for mySource on MVS to make compiler happy - JJD */ - ToU_CALLBACK_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - (const char *)mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, + args.converter = _this; + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + ToU_CALLBACK_MACRO(_this->toUContext, + args, + srcTemp, + 1, + UCNV_UNASSIGNED, err); if (U_FAILURE (*err)) break; _this->invalidCharLength = 0; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; } } } @@ -208,15 +223,17 @@ void T_UConverter_toUnicode_UTF8_OFFSETS_LOGIC (UConverter * _this, UBool flush, UErrorCode * err) { - const unsigned char *mySource = (unsigned char *) *source; - UChar *myTarget = *target; + const unsigned char *mySource = (unsigned char *) *source, *srcTemp; + UChar *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; int32_t sourceLength = sourceLimit - (char *) mySource; uint32_t ch = 0, ch2 = 0, i = 0; uint32_t inBytes = 0; + UConverterToUnicodeArgs args; + args.sourceStart = *source; if (_this->toUnicodeStatus) { i = _this->invalidCharLength; @@ -306,21 +323,30 @@ void T_UConverter_toUnicode_UTF8_OFFSETS_LOGIC (UConverter * _this, *err = U_ILLEGAL_CHAR_FOUND; _this->invalidCharLength = (int8_t)i; + args.converter = _this; + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + /* To do HSYS: more smarts here, including offsets */ + ToU_CALLBACK_MACRO(_this->toUContext, + args, + srcTemp, + 1, + UCNV_UNASSIGNED, + err); /* Needed explicit cast for mySource on MVS to make compiler happy - JJD */ - ToU_CALLBACK_OFFSETS_LOGIC_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - (const char *)mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); if (U_FAILURE (*err)) break; _this->invalidCharLength = 0; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; } } } @@ -574,8 +600,10 @@ UChar32 T_UConverter_getNextUChar_UTF8(UConverter* converter, uint8_t myByte; UChar32 ch; int8_t isLegalSequence = 1; + UConverterToUnicodeArgs args; /*Input boundary check*/ + args.sourceStart = *source; if ((*source) >= sourceLimit) { *err = U_INDEX_OUTOFBOUNDS_ERROR; @@ -655,14 +683,21 @@ UChar32 T_UConverter_getNextUChar_UTF8(UConverter* converter, /*It is very likely that the ErrorFunctor will write to the *internal buffers */ - converter->fromCharErrorBehaviour(converter, - &myUCharPtr, - myUCharPtr + 1, - &sourceFinal, - sourceLimit, - NULL, - TRUE, - err); + args.converter = converter; + args.pTarget = &myUCharPtr; + args.targetLimit = myUCharPtr + 1; + args.pSource = &sourceFinal; + args.sourceLimit = sourceLimit; + args.flush = TRUE; + args.offsets = NULL; + args.size = sizeof(args); + converter->fromCharErrorBehaviour(converter->toUContext, + &args, + sourceFinal, + 1, + UCNV_UNASSIGNED, + err); + /*makes the internal caching transparent to the user*/ if (*err == U_INDEX_OUTOFBOUNDS_ERROR) *err = U_ZERO_ERROR; diff --git a/icu4c/source/common/ucnvlat1.c b/icu4c/source/common/ucnvlat1.c index 6703d6283c2..e54ffb2ec4d 100644 --- a/icu4c/source/common/ucnvlat1.c +++ b/icu4c/source/common/ucnvlat1.c @@ -10,12 +10,16 @@ * * created on: 2000feb07 * created by: Markus W. Scherer +* Change history: +* +* 06/29/2000 helena Major rewrite of the callback APIs. */ #include "unicode/utypes.h" #include "ucmp16.h" #include "ucmp8.h" -#include "unicode/ucnv_bld.h" +#include "unicode/ucnv_err.h" +#include "ucnv_bld.h" #include "unicode/ucnv.h" #include "ucnv_cnv.h" @@ -68,13 +72,15 @@ static void T_UConverter_fromUnicode_LATIN_1 (UConverter * _this, UBool flush, UErrorCode * err) { - const UChar *mySource = *source; - unsigned char *myTarget = (unsigned char *) *target; + const UChar *mySource = *source, *srcTemp; + unsigned char *myTarget = (unsigned char *) *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - (char *) myTarget; int32_t sourceLength = sourceLimit - mySource; + UConverterFromUnicodeArgs args; + args.sourceStart = *source; /*writing the char to the output stream */ while (mySourceIndex < sourceLength) { @@ -93,19 +99,29 @@ static void T_UConverter_fromUnicode_LATIN_1 (UConverter * _this, _this->invalidUCharLength = 1; /* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */ - FromU_CALLBACK_MACRO(_this, - (char *)myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.converter = _this; + args.pTarget = (char**)&tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + + FromU_CALLBACK_MACRO(args.converter->fromUContext, + args, + srcTemp, + 1, + (UChar32) (*srcTemp), + UCNV_UNASSIGNED, + err); if (U_FAILURE (*err)) break; _this->invalidUCharLength = 0; + myTargetIndex = (unsigned char *) (*(args.pTarget)) - myTarget; + mySourceIndex = *(args.pSource) - mySource; } } else diff --git a/icu4c/source/common/ucnvmbcs.c b/icu4c/source/common/ucnvmbcs.c index 2cff5b634bd..0c82e66be00 100644 --- a/icu4c/source/common/ucnvmbcs.c +++ b/icu4c/source/common/ucnvmbcs.c @@ -14,13 +14,15 @@ * Change history: * * 05/09/00 helena Added implementation to handle fallback mappings. +* 06/29/2000 helena Major rewrite of the callback APIs. */ #include "unicode/utypes.h" #include "cmemory.h" #include "ucmp16.h" #include "ucmp8.h" -#include "unicode/ucnv_bld.h" +#include "unicode/ucnv_err.h" +#include "ucnv_bld.h" #include "unicode/ucnv.h" #include "ucnv_cnv.h" @@ -76,8 +78,8 @@ static void T_UConverter_toUnicode_MBCS (UConverter * _this, UBool flush, UErrorCode * err) { - const char *mySource = *source; - UChar *myTarget = *target; + const char *mySource = *source, *srcTemp; + UChar *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -86,10 +88,10 @@ static void T_UConverter_toUnicode_MBCS (UConverter * _this, UChar targetUniChar = 0x0000; UChar mySourceChar = 0x0000; UBool *myStarters = NULL; + UConverterToUnicodeArgs args; - - + args.sourceStart = *source; myToUnicode = &_this->sharedData->table->mbcs.toUnicode; myToUnicodeFallback = &_this->sharedData->table->mbcs.toUnicodeFallback; myStarters = _this->sharedData->table->mbcs.starters; @@ -153,19 +155,30 @@ static void T_UConverter_toUnicode_MBCS (UConverter * _this, _this->invalidCharBuffer[0] = (char) mySourceChar; } - ToU_CALLBACK_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, + + args.converter = _this; + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + + /* to do hsys: add more smarts to the codeUnits and length later */ + ToU_CALLBACK_MACRO(_this->toUContext, + args, + srcTemp, + 1, + UCNV_UNASSIGNED, err); if (U_FAILURE (*err)) break; _this->invalidCharLength = 0; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; } } } @@ -205,8 +218,8 @@ static void T_UConverter_toUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this, UBool flush, UErrorCode * err) { - const char *mySource = *source; - UChar *myTarget = *target; + const char *mySource = *source, *srcTemp; + UChar *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -216,11 +229,13 @@ static void T_UConverter_toUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this, UChar mySourceChar = 0x0000; UChar oldMySourceChar = 0x0000; UBool *myStarters = NULL; - + UConverterToUnicodeArgs args; + + args.sourceStart = *source; myToUnicode = &_this->sharedData->table->mbcs.toUnicode; myToUnicodeFallback = &_this->sharedData->table->mbcs.toUnicodeFallback; myStarters = _this->sharedData->table->mbcs.starters; - + while (mySourceIndex < sourceLength) { if (myTargetIndex < targetLength) @@ -302,20 +317,29 @@ static void T_UConverter_toUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this, _this->invalidCharLength = 1; _this->invalidCharBuffer[0] = (char) mySourceChar; } + args.converter = _this; + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); - ToU_CALLBACK_OFFSETS_LOGIC_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); + /* to do hsys: add more smarts to the codeUnits and length later and offsets */ + ToU_CALLBACK_MACRO(_this->toUContext, + args, + srcTemp, + 1, + UCNV_UNASSIGNED, + err); if (U_FAILURE (*err)) break; _this->invalidCharLength = 0; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; } } } @@ -356,8 +380,8 @@ static void T_UConverter_fromUnicode_MBCS (UConverter * _this, UErrorCode * err) { - const UChar *mySource = *source; - char *myTarget = *target; + const UChar *mySource = *source, *srcTemp; + char *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -365,7 +389,9 @@ static void T_UConverter_fromUnicode_MBCS (UConverter * _this, CompactShortArray *myFromUnicode = NULL, *myFromUnicodeFallback = NULL; UChar targetUniChar = 0x0000; UChar mySourceChar = 0x0000; + UConverterFromUnicodeArgs args; + args.sourceStart = *source; myFromUnicode = &_this->sharedData->table->mbcs.fromUnicode; myFromUnicodeFallback = &_this->sharedData->table->mbcs.fromUnicodeFallback; @@ -431,18 +457,28 @@ static void T_UConverter_fromUnicode_MBCS (UConverter * _this, _this->invalidUCharBuffer[0] = (UChar) mySourceChar; _this->invalidUCharLength = 1; - FromU_CALLBACK_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); - + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.converter = _this; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); +/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */ + /* HSYS: to do: more smarts */ + FromU_CALLBACK_MACRO(args.converter->fromUContext, + args, + srcTemp, + 1, + (UChar32) (*srcTemp), + UCNV_UNASSIGNED, + err); if (U_FAILURE (*err)) break; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; _this->invalidUCharLength = 0; } } @@ -472,8 +508,8 @@ static void T_UConverter_fromUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this, UErrorCode * err) { - const UChar *mySource = *source; - char *myTarget = *target; + const UChar *mySource = *source, *srcTemp; + char *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -481,7 +517,9 @@ static void T_UConverter_fromUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this, CompactShortArray *myFromUnicode = NULL, *myFromUnicodeFallback = NULL; UChar targetUniChar = 0x0000; UChar mySourceChar = 0x0000; + UConverterFromUnicodeArgs args; + args.sourceStart = *source; myFromUnicode = &_this->sharedData->table->mbcs.fromUnicode; myFromUnicodeFallback = &_this->sharedData->table->mbcs.fromUnicodeFallback; @@ -557,18 +595,30 @@ static void T_UConverter_fromUnicode_MBCS_OFFSETS_LOGIC (UConverter * _this, _this->invalidUCharBuffer[0] = (UChar) mySourceChar; _this->invalidUCharLength = 1; - FromU_CALLBACK_OFFSETS_LOGIC_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); + + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.converter = _this; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); +/* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */ + /* HSYS: to do: more smarts including offsets*/ + FromU_CALLBACK_MACRO(args.converter->fromUContext, + args, + srcTemp, + 1, + (UChar32) (*srcTemp), + UCNV_UNASSIGNED, + err); if (U_FAILURE (*err)) break; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; _this->invalidUCharLength = 0; } } @@ -595,6 +645,7 @@ static UChar32 T_UConverter_getNextUChar_MBCS(UConverter* converter, { UChar myUChar; char const *sourceInitial = *source; + UConverterToUnicodeArgs args; /*safe keeps a ptr to the beginning in case we need to step back*/ /*Input boundary check*/ @@ -603,7 +654,7 @@ static UChar32 T_UConverter_getNextUChar_MBCS(UConverter* converter, *err = U_INDEX_OUTOFBOUNDS_ERROR; return 0xFFFD; } - + args.sourceStart = *source; /*Checks to see if the byte is a lead*/ if (converter->sharedData->table->mbcs.starters[(uint8_t)**source] == FALSE) { @@ -654,15 +705,21 @@ static UChar32 T_UConverter_getNextUChar_MBCS(UConverter* converter, /*It's is very likely that the ErrorFunctor will write to the *internal buffers */ - converter->fromCharErrorBehaviour(converter, - &myUCharPtr, - myUCharPtr + 1, - &sourceFinal, - sourceLimit, - NULL, - TRUE, - err); - + args.converter = converter; + args.pTarget = &myUCharPtr; + args.targetLimit = myUCharPtr + 1; + args.pSource = &sourceFinal; + args.sourceLimit = sourceLimit; + args.flush = TRUE; + args.offsets = NULL; + args.size = sizeof(args); + converter->fromCharErrorBehaviour(converter->toUContext, + &args, + sourceFinal, + 1, + UCNV_UNASSIGNED, + err); + /*makes the internal caching transparent to the user*/ if (*err == U_INDEX_OUTOFBOUNDS_ERROR) *err = U_ZERO_ERROR; diff --git a/icu4c/source/common/ucnvsbcs.c b/icu4c/source/common/ucnvsbcs.c index 3d56f012653..d62206b92ff 100644 --- a/icu4c/source/common/ucnvsbcs.c +++ b/icu4c/source/common/ucnvsbcs.c @@ -15,13 +15,15 @@ * * 05/09/00 helena Added implementation to handle fallback mappings. * 06/20/2000 helena OS/400 port changes; mostly typecast. +* 06/29/2000 helena Major rewrite of the callback APIs. */ #include "unicode/utypes.h" #include "cmemory.h" #include "ucmp16.h" #include "ucmp8.h" -#include "unicode/ucnv_bld.h" +#include "unicode/ucnv_err.h" +#include "ucnv_bld.h" #include "unicode/ucnv.h" #include "ucnv_cnv.h" @@ -66,17 +68,19 @@ void T_UConverter_toUnicode_SBCS (UConverter * _this, UBool flush, UErrorCode * err) { - char *mySource = (char *) *source; - UChar *myTarget = *target; + char *mySource = (char *) *source, *srcTemp; + UChar *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; int32_t sourceLength = sourceLimit - (char *) mySource; UChar *myToUnicode = NULL, *myToUnicodeFallback = NULL; UChar targetUniChar = 0x0000; + UConverterToUnicodeArgs args; myToUnicode = _this->sharedData->table->sbcs.toUnicode; myToUnicodeFallback = _this->sharedData->table->sbcs.toUnicodeFallback; + args.sourceStart = *source; while (mySourceIndex < sourceLength) { @@ -109,18 +113,28 @@ void T_UConverter_toUnicode_SBCS (UConverter * _this, _this->invalidCharBuffer[0] = (char) mySource[mySourceIndex - 1]; _this->invalidCharLength = 1; - ToU_CALLBACK_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, + args.converter = _this; + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + + /* to do hsys: add more smarts to the codeUnits and length later */ + ToU_CALLBACK_MACRO(_this->toUContext, + args, + srcTemp, + 1, + UCNV_UNASSIGNED, err); - + /* Hsys: calculate the source and target advancement */ if (U_FAILURE (*err)) break; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; _this->invalidCharLength = 0; } } @@ -147,18 +161,19 @@ void T_UConverter_fromUnicode_SBCS (UConverter * _this, UBool flush, UErrorCode * err) { - const UChar *mySource = *source; - unsigned char *myTarget = (unsigned char *) *target; + const UChar *mySource = *source, *srcTemp; + unsigned char *myTarget = (unsigned char *) *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - (char *) myTarget; int32_t sourceLength = sourceLimit - mySource; CompactByteArray *myFromUnicode = NULL, *myFromUnicodeFallback = NULL; unsigned char targetChar = 0x00; + UConverterFromUnicodeArgs args; myFromUnicode = &_this->sharedData->table->sbcs.fromUnicode; myFromUnicodeFallback = &_this->sharedData->table->sbcs.fromUnicodeFallback; - + args.sourceStart = *source; /*writing the char to the output stream */ while (mySourceIndex < sourceLength) { @@ -189,21 +204,31 @@ void T_UConverter_fromUnicode_SBCS (UConverter * _this, _this->invalidUCharBuffer[0] = (UChar)mySource[mySourceIndex - 1]; _this->invalidUCharLength = 1; + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.converter = _this; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); /* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */ - FromU_CALLBACK_MACRO(_this, - (char *)myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); + /* HSYS: to do: more smarts */ + FromU_CALLBACK_MACRO(args.converter->fromUContext, + args, + srcTemp, + 1, + (UChar32) (*srcTemp), + UCNV_UNASSIGNED, + err); if (U_FAILURE (*err)) { break; } + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; _this->invalidUCharLength = 0; } } @@ -228,15 +253,17 @@ UChar32 T_UConverter_getNextUChar_SBCS(UConverter* converter, UErrorCode* err) { UChar myUChar; - + UConverterToUnicodeArgs args; + if (U_FAILURE(*err)) return 0xFFFD; + if ((*source)+1 > sourceLimit) { *err = U_INDEX_OUTOFBOUNDS_ERROR; return 0xFFFD; } - + args.sourceStart = *source; /*Gets the corresponding codepoint*/ myUChar = converter->sharedData->table->sbcs.toUnicode[(unsigned char)*((*source)++)]; @@ -260,14 +287,20 @@ UChar32 T_UConverter_getNextUChar_SBCS(UConverter* converter, (*source)--; /*It's is very likely that the ErrorFunctor will write to the *internal buffers */ - converter->fromCharErrorBehaviour(converter, - &myUCharPtr, - myUCharPtr + 1, - &sourceFinal, - sourceLimit, - NULL, - TRUE, - err); + args.converter = converter; + args.pTarget = &myUCharPtr; + args.targetLimit = myUCharPtr + 1; + args.pSource = &sourceFinal; + args.sourceLimit = sourceLimit; + args.flush = TRUE; + args.offsets = NULL; + args.size = sizeof(args); + converter->fromCharErrorBehaviour(converter->toUContext, + &args, + sourceFinal, + 1, + UCNV_UNASSIGNED, + err); /*makes the internal caching transparent to the user*/ if (*err == U_INDEX_OUTOFBOUNDS_ERROR) *err = U_ZERO_ERROR; @@ -354,8 +387,8 @@ void T_UConverter_toUnicode_DBCS (UConverter * _this, UBool flush, UErrorCode * err) { - const char *mySource = ( char *) *source; - UChar *myTarget = *target; + const char *mySource = ( char *) *source, *srcTemp; + UChar *myTarget = *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - myTarget; @@ -363,9 +396,11 @@ void T_UConverter_toUnicode_DBCS (UConverter * _this, CompactShortArray *myToUnicode = NULL, *myToUnicodeFallback = NULL; UChar targetUniChar = 0x0000; UChar mySourceChar = 0x0000; + UConverterToUnicodeArgs args; myToUnicode = &_this->sharedData->table->dbcs.toUnicode; myToUnicodeFallback = &_this->sharedData->table->dbcs.toUnicodeFallback; + args.sourceStart = *source; while (mySourceIndex < sourceLength) { @@ -412,18 +447,28 @@ void T_UConverter_toUnicode_DBCS (UConverter * _this, _this->invalidCharBuffer[1] = (char) mySourceChar; _this->invalidCharLength = 2; - ToU_CALLBACK_MACRO(_this, - myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.converter = _this; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); - if (U_FAILURE (*err)) break; + /* to do hsys: add more smarts to the codeUnits and length later */ + ToU_CALLBACK_MACRO(_this->toUContext, + args, + srcTemp, + 2, + UCNV_UNASSIGNED, + err); + /* Hsys: calculate the source and target advancement */ + if (U_FAILURE (*err)) break; + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; _this->invalidCharLength = 0; } } @@ -465,8 +510,8 @@ void T_UConverter_fromUnicode_DBCS (UConverter * _this, UBool flush, UErrorCode * err) { - const UChar *mySource = *source; - unsigned char *myTarget = (unsigned char *) *target; + const UChar *mySource = *source, *srcTemp; + unsigned char *myTarget = (unsigned char *) *target, *tgtTemp; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; int32_t targetLength = targetLimit - (char *) myTarget; @@ -474,9 +519,11 @@ void T_UConverter_fromUnicode_DBCS (UConverter * _this, CompactShortArray *myFromUnicode = NULL, *myFromUnicodeFallback = NULL; UChar targetUniChar = 0x0000; UChar mySourceChar = 0x0000; + UConverterFromUnicodeArgs args; myFromUnicode = &_this->sharedData->table->dbcs.fromUnicode; myFromUnicodeFallback = &_this->sharedData->table->dbcs.fromUnicodeFallback; + args.sourceStart = *source; /*writing the char to the output stream */ while (mySourceIndex < sourceLength) @@ -532,18 +579,30 @@ void T_UConverter_fromUnicode_DBCS (UConverter * _this, /* Needed explicit cast for myTarget on MVS to make compiler happy - JJD */ - FromU_CALLBACK_MACRO(_this, - (char *)myTarget, - myTargetIndex, - targetLimit, - mySource, - mySourceIndex, - sourceLimit, - offsets, - flush, - err); - - if (U_FAILURE (*err)) break; + /* HSYS: to do: more smarts */ + srcTemp = mySource + mySourceIndex; + tgtTemp = myTarget + myTargetIndex; + args.converter = _this; + args.pTarget = &tgtTemp; + args.targetLimit = targetLimit; + args.pSource = &srcTemp; + args.sourceLimit = sourceLimit; + args.flush = flush; + args.offsets = offsets+myTargetIndex; + args.size = sizeof(args); + FromU_CALLBACK_MACRO(args.converter->fromUContext, + args, + srcTemp, + 1, + (UChar32) (*srcTemp), + UCNV_UNASSIGNED, + err); + if (U_FAILURE (*err)) + { + break; + } + myTargetIndex = *(args.pTarget) - myTarget; + mySourceIndex = *(args.pSource) - mySource; _this->invalidUCharLength = 0; } } @@ -567,7 +626,9 @@ UChar32 T_UConverter_getNextUChar_DBCS(UConverter* converter, UErrorCode* err) { UChar myUChar; + UConverterToUnicodeArgs args; + if (U_FAILURE(*err)) return 0xFFFD; /*Checks boundaries and set appropriate error codes*/ if ((*source)+2 > sourceLimit) { @@ -584,7 +645,8 @@ UChar32 T_UConverter_getNextUChar_DBCS(UConverter* converter, return 0xFFFD; } - + + args.sourceStart = *source; /*Gets the corresponding codepoint*/ myUChar = ucmp16_getu((&converter->sharedData->table->dbcs.toUnicode), (uint16_t)(((UChar)((**source)) << 8) |((uint8_t)*((*source)+1)))); @@ -614,16 +676,22 @@ UChar32 T_UConverter_getNextUChar_DBCS(UConverter* converter, *err = U_INVALID_CHAR_FOUND; + args.converter = converter; + args.pTarget = &myUCharPtr; + args.targetLimit = myUCharPtr + 1; + args.pSource = &sourceFinal; + args.sourceLimit = sourceLimit; + args.flush = TRUE; + args.offsets = NULL; + args.size = sizeof(args); /*It's is very likely that the ErrorFunctor will write to the *internal buffers */ - converter->fromCharErrorBehaviour(converter, - &myUCharPtr, - myUCharPtr + 1, - &sourceFinal, - sourceLimit, - NULL, - TRUE, - err); + converter->fromCharErrorBehaviour(converter->toUContext, + &args, + sourceFinal, + 1, + UCNV_UNASSIGNED, + err); /*makes the internal caching transparent to the user*/ if (*err == U_INDEX_OUTOFBOUNDS_ERROR) *err = U_ZERO_ERROR; diff --git a/icu4c/source/common/unicode/convert.h b/icu4c/source/common/unicode/convert.h index b3df51a99e1..f1c332d0935 100644 --- a/icu4c/source/common/unicode/convert.h +++ b/icu4c/source/common/unicode/convert.h @@ -3,6 +3,10 @@ * Copyright (C) 1998-1999, International Business Machines * Corporation and others. All Rights Reserved. * + * + * Change history: + * + * 06/29/2000 helena Major rewrite of the callback APIs. *******************************************************************************/ #ifndef CONVERT_H @@ -288,21 +292,34 @@ const char* getName( UErrorCode& err) const; /** * Sets the current setting action taken when a character from a codepage is * missing. (Currently STOP or SUBSTITUTE). - * @param action the action constant if an equivalent codepage character is missing + * @param newAction the action constant if an equivalent codepage character is missing + * @param newContext the new toUnicode callback function state + * @param oldAction the original action constant, saved for later restoration. + * @param oldContext the old toUnicode callback function state + * @param err the error status code * @stable */ - void setMissingCharAction(UConverterToUCallback action, + void setMissingCharAction(UConverterToUCallback newAction, + void* newContext, + UConverterToUCallback oldAction, + void** oldContext, UErrorCode& err); /** * Sets the current setting action taken when a unicode character is missing. * (currently T_UnicodeConverter_MissingUnicodeAction is either STOP or SUBSTITUTE, * SKIP, CLOSEST_MATCH, ESCAPE_SEQ may be added in the future). - * @param action the action constant if an equivalent Unicode character is missing + * @param newAction the action constant if an equivalent Unicode character is missing + * @param newContext the new fromUnicode callback function state + * @param oldAction the original action constant, saved for later restoration. + * @param oldContext the old fromUnicode callback function state * @param err the error status code * @stable */ - void setMissingUnicodeAction(UConverterFromUCallback action, + void setMissingUnicodeAction(UConverterFromUCallback newAction, + void* newContext, + UConverterFromUCallback oldAction, + void** oldContext, UErrorCode& err); /** * Returns the localized name of the UnicodeConverter, if for any reason it is diff --git a/icu4c/source/common/unicode/ucnv.h b/icu4c/source/common/unicode/ucnv.h index 6732434383d..b7b4d7eea9d 100644 --- a/icu4c/source/common/unicode/ucnv.h +++ b/icu4c/source/common/unicode/ucnv.h @@ -12,6 +12,7 @@ * Date Name Description * 04/04/99 helena Fixed internal header inclusion. * 05/11/00 helena Added setFallback and usesFallback APIs. + * 06/29/2000 helena Major rewrite of the callback APIs. */ /** @@ -25,27 +26,81 @@ #define UCNV_H #include "unicode/utypes.h" -#include "unicode/ucnv_bld.h" #include "unicode/ucnv_err.h" U_CDECL_BEGIN -typedef void (*UConverterToUCallback) (UConverter *, - UChar **, - const UChar *, - const char **, - const char *, - int32_t* offsets, - UBool, + +#define UCNV_MAX_SUBCHAR_LEN 4 +#define UCNV_ERROR_BUFFER_LENGTH 20 +#define UCNV_MAX_AMBIGUOUSCCSIDS 5 + +#define UCNV_IMPLEMENTED_CONVERSION_TYPES 9 +/*Sentinel Value used to check the integrity of the binary data files */ + +#define UCNV_FILE_CHECK_MARKER 0xBEDA + +/*maximum length of the converter names */ +#define UCNV_MAX_CONVERTER_NAME_LENGTH 60 +#define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH) + +/*Pointer to the aforementioned file */ +#define UCNV_MAX_LINE_TEXT (UCNV_MAX_CONVERTER_NAME_LENGTH*400) + +#define UCNV_SI 0x0F /*Shift in for EBDCDIC_STATEFUL and iso2022 states */ +#define UCNV_SO 0x0E /*Shift out for EBDCDIC_STATEFUL and iso2022 states */ + +typedef enum { + UCNV_UNSUPPORTED_CONVERTER = -1, + UCNV_SBCS = 0, + UCNV_DBCS = 1, + UCNV_MBCS = 2, + UCNV_LATIN_1 = 3, + UCNV_UTF8 = 4, + UCNV_UTF16_BigEndian = 5, + UCNV_UTF16_LittleEndian = 6, + UCNV_EBCDIC_STATEFUL = 7, + UCNV_ISO_2022 = 8, + + UCNV_LMBCS_1 = 9, + UCNV_LMBCS_2, + UCNV_LMBCS_3, + UCNV_LMBCS_4, + UCNV_LMBCS_5, + UCNV_LMBCS_6, + UCNV_LMBCS_8, + UCNV_LMBCS_11, + UCNV_LMBCS_16, + UCNV_LMBCS_17, + UCNV_LMBCS_18, + UCNV_LMBCS_19, + UCNV_LMBCS_LAST = UCNV_LMBCS_19, + + /* Number of converter types for which we have conversion routines. */ + UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES = UCNV_LMBCS_LAST+1 + +} UConverterType; + +typedef enum { + UCNV_UNKNOWN = -1, + UCNV_IBM = 0 +} UConverterPlatform; + +typedef void (*UConverterToUCallback) ( + void* context, + UConverterToUnicodeArgs *args, + const char *codePoints, + int32_t length, + UConverterCallbackReason reason, UErrorCode *); -typedef void (*UConverterFromUCallback) (UConverter *, - char **, - const char *, - const UChar **, - const UChar *, - int32_t* offsets, - UBool, +typedef void (*UConverterFromUCallback) ( + void* context, + UConverterFromUnicodeArgs *args, + const UChar* codeUnits, + int32_t length, + UChar32 codePoint, /* HSYS: why can't just use the macros on the code units? */ + UConverterCallbackReason reason, UErrorCode *); U_CDECL_END @@ -384,30 +439,40 @@ U_CAPI UConverterFromUCallback U_EXPORT2 * Gets the current callback function used by the converter when illegal or invalid sequence found. * * @param converter the unicode converter - * @param action the callback function we want to set. + * @param newAction the callback function we want to set. + * @param newContext the new toUnicode callback function state + * @param oldAction the previously assigned callback function pointer + * @param oldContext the new toUnicode callback function state * @param err The error code status - * @return the previously assigned callback function pointer * @see ucnv_getToUCallBack * @stable */ -U_CAPI UConverterToUCallback U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_setToUCallBack (UConverter * converter, - UConverterToUCallback action, + UConverterToUCallback newAction, + void* newContext, + UConverterToUCallback oldAction, + void** oldContext, UErrorCode * err); /** * Gets the current callback function used by the converter when illegal or invalid sequence found. * * @param converter the unicode converter - * @param action the callback function we want to set. + * @param newAction the callback function we want to set. + * @param newContext the new fromUnicode callback function state + * @param oldAction the previously assigned callback function pointer + * @param oldContext the new fromUnicode callback function state * @param err The error code status - * @return the previously assigned callback function pointer * @see ucnv_getFromUCallBack * @stable */ -U_CAPI UConverterFromUCallback U_EXPORT2 +U_CAPI void U_EXPORT2 ucnv_setFromUCallBack (UConverter * converter, - UConverterFromUCallback action, + UConverterFromUCallback newAction, + void *newContext, + UConverterFromUCallback oldAction, + void **oldContext, UErrorCode * err); diff --git a/icu4c/source/common/unicode/ucnv_bld.h b/icu4c/source/common/unicode/ucnv_bld.h index 4c6b3692aca..f4cb7e87681 100644 --- a/icu4c/source/common/unicode/ucnv_bld.h +++ b/icu4c/source/common/unicode/ucnv_bld.h @@ -1,268 +1 @@ -/* -********************************************************************** -* Copyright (C) 1999, International Business Machines -* Corporation and others. All Rights Reserved. -********************************************************************** -* -* -* ucnv_bld.h: -* Contains all internal and external data structure definitions -* Created & Maitained by Bertrand A. Damiba -* -* -* -* ATTENTION: -* --------- -* Although the data structures in this file are open and stack allocatable -* we reserve the right to hide them in further releases. -*/ - -#ifndef UCNV_BLD_H -#define UCNV_BLD_H - -#include "unicode/utypes.h" - -#define UCNV_MAX_SUBCHAR_LEN 4 -#define UCNV_ERROR_BUFFER_LENGTH 20 -#define UCNV_MAX_AMBIGUOUSCCSIDS 5 - -#define UCNV_IMPLEMENTED_CONVERSION_TYPES 9 -/*Sentinel Value used to check the integrity of the binary data files */ - -#define UCNV_FILE_CHECK_MARKER 0xBEDA - -/*maximum length of the converter names */ -#define UCNV_MAX_CONVERTER_NAME_LENGTH 60 -#define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH) - -/*Pointer to the aforementioned file */ -#define UCNV_MAX_LINE_TEXT (UCNV_MAX_CONVERTER_NAME_LENGTH*400) - -#define UCNV_SI 0x0F /*Shift in for EBDCDIC_STATEFUL and iso2022 states */ -#define UCNV_SO 0x0E /*Shift out for EBDCDIC_STATEFUL and iso2022 states */ - -typedef enum { - UCNV_UNSUPPORTED_CONVERTER = -1, - UCNV_SBCS = 0, - UCNV_DBCS = 1, - UCNV_MBCS = 2, - UCNV_LATIN_1 = 3, - UCNV_UTF8 = 4, - UCNV_UTF16_BigEndian = 5, - UCNV_UTF16_LittleEndian = 6, - UCNV_EBCDIC_STATEFUL = 7, - UCNV_ISO_2022 = 8, - - UCNV_LMBCS_1 = 9, - UCNV_LMBCS_2, - UCNV_LMBCS_3, - UCNV_LMBCS_4, - UCNV_LMBCS_5, - UCNV_LMBCS_6, - UCNV_LMBCS_8, - UCNV_LMBCS_11, - UCNV_LMBCS_16, - UCNV_LMBCS_17, - UCNV_LMBCS_18, - UCNV_LMBCS_19, - UCNV_LMBCS_LAST = UCNV_LMBCS_19, - - /* Number of converter types for which we have conversion routines. */ - UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES = UCNV_LMBCS_LAST+1 - -} UConverterType; - -/* ### move the following typedef and array into implementation files! */ -typedef struct -{ - int32_t ccsid; - UChar mismapped; - UChar replacement; -} UAmbiguousConverter; - -static const UAmbiguousConverter UCNV_AMBIGUOUSCONVERTERS[UCNV_MAX_AMBIGUOUSCCSIDS] = -{ - { 943, 0x00A5, 0x005C }, - { 949, 0x20A9, 0x005C }, - { 1361, 0x20A9, 0x005C }, - { 942, 0x00A5, 0x005C }, - { 1363, 0x20A9, 0x005C } -}; - -typedef enum { - UCNV_UNKNOWN = -1, - UCNV_IBM = 0 -} UConverterPlatform; - -U_CDECL_BEGIN /* We must declare the following as 'extern "C"' so that if ucnv - itself is compiled under C++, the linkage of the funcptrs will - work. - */ - -union UConverterTable; -typedef union UConverterTable UConverterTable; - -struct UConverterImpl; -typedef struct UConverterImpl UConverterImpl; - -/* ### - * Markus Scherer on 2000feb04: - * I have change UConverter and UConverterSharedData; there may be more changes, - * or we may decide to roll back the structure definitions to what they were - * before, with the additional UConverterImpl field and the new semantics for - * referenceCounter. - * - * Reasons for changes: Attempt at performance improvements, especially - * a) decrease amount of internal, implicit padding by reordering the fields - * b) save space by storing the internal name of the converter only with a - * pointer instead of an array - * - * In addition to that, I added the UConverterImpl field for better - * modularizing the code and making it more maintainable. It may actually - * become slightly faster by doing this. - * - * I changed the UConverter.to|fromUnicodeStatus to be unsigned because - * the defaultValues.toUnicodeStatus is unsigned, and it seemed to be a safer choice. - * - * Ultimately, I would prefer not to expose these definitions any more at all, - * but this is suspect to discussions, proposals and design reviews. - * - * I would personally like to see more information hiding (with helper APIs), - * useful state fields in UConverter that are reserved for the callbacks, - * and directly included structures instead of pointers to allocated - * memory, like for UConverterTable and its variant fields. - * - * Also, with the more C++-like converter implementation, - * the conversionType does not need to be in UConverterSharedData any more: - * it is in UConverterImpl and hardly used. - */ - -typedef struct { - uint32_t structSize; /* Size of this structure */ - - char name [UCNV_MAX_CONVERTER_NAME_LENGTH]; /* internal name of the converter- invariant chars */ - - int32_t codepage; /* codepage # (now IBM-$codepage) */ - - int8_t platform; /* platform of the converter (only IBM now) */ - int8_t conversionType; /* conversion type */ - - int8_t minBytesPerChar; /* Minimum # bytes per char in this codepage */ - int8_t maxBytesPerChar; /* Maximum # bytes per char in this codepage */ - - int8_t subCharLen; - - uint8_t subChar[UCNV_MAX_SUBCHAR_LEN]; - uint8_t hasToUnicodeFallback; /* UBool needs to be changed to UBool to be consistent across platform */ - uint8_t hasFromUnicodeFallback; - uint8_t reserved[19]; /* to round out the structure */ - -} UConverterStaticData; - -/* - * Defines the UConverterSharedData struct, - * the immutable, shared part of UConverter. - */ -typedef struct { - uint32_t structSize; /* Size of this structure */ - uint32_t referenceCounter; /* used to count number of clients, 0xffffffff for static SharedData */ - - const void *dataMemory; /* from udata_openChoice() */ - UConverterTable *table; /* Pointer to conversion data */ - - const UConverterStaticData *staticData; /* pointer to the static (non changing) data. */ - UBool staticDataOwned; /* T if we own the staticData */ - const UConverterImpl *impl; /* vtable-style struct of mostly function pointers */ - - /*initial values of some members of the mutable part of object */ - uint32_t toUnicodeStatus; -} UConverterSharedData; - - -/* Defines a UConverter, the lightweight mutable part the user sees */ - -struct UConverter { - uint32_t toUnicodeStatus; /* Used to internalize stream status information */ - uint32_t fromUnicodeStatus; - int32_t mode; - UBool useFallback; - - int8_t subCharLen; /* length of the codepage specific character sequence */ - int8_t invalidCharLength; - int8_t invalidUCharLength; - int8_t charErrorBufferLength; /* number of valid bytes in charErrorBuffer */ - int8_t UCharErrorBufferLength; /* number of valid UChars in charErrorBuffer */ - - uint8_t subChar[UCNV_MAX_SUBCHAR_LEN]; /* codepage specific character sequence */ - char invalidCharBuffer[UCNV_MAX_SUBCHAR_LEN]; - uint8_t charErrorBuffer[UCNV_ERROR_BUFFER_LENGTH]; /* codepage output from Error functions */ - - UChar invalidUCharBuffer[3]; - UChar UCharErrorBuffer[UCNV_ERROR_BUFFER_LENGTH]; /* unicode output from Error functions */ - - /* - * Error function pointer called when conversion issues - * occur during a T_UConverter_fromUnicode call - */ - void (*fromUCharErrorBehaviour) (struct UConverter *, - char **, - const char *, - const UChar **, - const UChar *, - int32_t* offsets, - UBool, - UErrorCode *); - /* - * Error function pointer called when conversion issues - * occur during a T_UConverter_toUnicode call - */ - void (*fromCharErrorBehaviour) (struct UConverter *, - UChar **, - const UChar *, - const char **, - const char *, - int32_t* offsets, - UBool, - UErrorCode *); - - UConverterSharedData *sharedData; /* Pointer to the shared immutable part of the converter object */ - - /* - * currently only used to point to a struct containing UConverter used by iso 2022; - * could be used by clients writing their own call back function to pass context to them - */ - void *extraInfo; -}; - -U_CDECL_END /* end of UConverter */ - -typedef struct UConverter UConverter; - - -typedef struct - { - UConverter *currentConverter; - uint8_t escSeq2022[10]; - int8_t escSeq2022Length; - } -UConverterDataISO2022; - - -typedef struct - { - UConverter *OptGrpConverter[0x20]; /* Converter per Opt. grp. */ - uint8_t OptGroup; /* default Opt. grp. for this LMBCS session */ - uint8_t localeConverterIndex; /* reasonable locale match for index */ - - } -UConverterDataLMBCS; - - -#define CONVERTER_FILE_EXTENSION ".cnv" - -#endif /* _UCNV_BLD */ - - - - - +#error Please do not include this file, it's now internal only. diff --git a/icu4c/source/common/unicode/ucnv_err.h b/icu4c/source/common/unicode/ucnv_err.h index bba22eef7b3..16f94f0a79b 100644 --- a/icu4c/source/common/unicode/ucnv_err.h +++ b/icu4c/source/common/unicode/ucnv_err.h @@ -34,52 +34,102 @@ #ifndef UCNV_ERR_H #define UCNV_ERR_H -#include "unicode/ucnv.h" #include "unicode/utypes.h" +/** + * The process condition code to be used with the callbacks. + * UCNV_UNASSIGNED : the code point is unassigned. + * UCNV_ILLEGAL : The code point is illegal. For example,\x81\x2E is illegal + * because \x2E is not a valid trail byte for the \x81 lead byte in SJIS. + * UCNV_IRREGULAR : The code point is not a regular sequence in the encoding. + * For example,\xC0\E1 is irregular because the same character can be represented + * as \x61. + * UCNV_RESET : Whether the conversion operation has been reset. + * UCNV_CLOSE : Whether the conversion operation has ended. + */ +typedef enum { + UCNV_UNASSIGNED = 0, + UCNV_ILLEGAL = 1, + UCNV_IRREGULAR = 2, + UCNV_RESET = 3, + UCNV_CLOSE = 4, +} UConverterCallbackReason; + +/* Forward declaring the UConverter structure */ +struct UConverter; +typedef struct UConverter UConverter; /** - * Functor STOPS at the ILLEGAL_SEQUENCE - * @stable + * The structure for the fromUnicode callback function parameter. */ -U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_STOP (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t* offsets, - UBool flush, - UErrorCode * err); +typedef struct { + uint16_t size; + UBool flush; + UConverter *converter; + const UChar *sourceStart; + const UChar **pSource; + const UChar *sourceLimit; + char **pTarget; + const char *targetLimit; + int32_t *offsets; /* *offset = blah ; offset++; */ +} UConverterFromUnicodeArgs; + + +/** + * The structure for the toUnicode callback function parameter. + */ +typedef struct { + uint16_t size; + UBool flush; + UConverter *converter; + const char *sourceStart; + const char **pSource; + const char *sourceLimit; + UChar **pTarget; + const UChar *targetLimit; + int32_t *offsets; +} UConverterToUnicodeArgs; /** * Functor STOPS at the ILLEGAL_SEQUENCE * @stable */ -U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_STOP (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t* offsets, - UBool flush, +U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_STOP ( + void *context, + UConverterFromUnicodeArgs *fromUArgs, + const UChar* codeUnits, + int32_t length, + UChar32 codePoint, + UConverterCallbackReason reason, UErrorCode * err); +/** + * Functor STOPS at the ILLEGAL_SEQUENCE + * @stable + */ +U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_STOP ( + void *context, + UConverterToUnicodeArgs *fromUArgs, + const char* codeUnits, + int32_t length, + UConverterCallbackReason reason, + UErrorCode * err); /** * Functor SKIPs the ILLEGAL_SEQUENCE * @stable */ -U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_SKIP (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t* offsets, - UBool flush, - UErrorCode * err); +U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_SKIP ( + void *context, + UConverterFromUnicodeArgs *fromUArgs, + const UChar* codeUnits, + int32_t length, + UChar32 codePoint, + UConverterCallbackReason reason, + UErrorCode * err); /** * Functor Substitute the ILLEGAL SEQUENCE with the current substitution string assiciated with _this, @@ -89,14 +139,14 @@ U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_SKIP (UConverter * _this, * @stable */ -U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_SUBSTITUTE (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t* offsets, - UBool flush, - UErrorCode * err); +U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_SUBSTITUTE ( + void *context, + UConverterFromUnicodeArgs *fromUArgs, + const UChar* codeUnits, + int32_t length, + UChar32 codePoint, + UConverterCallbackReason reason, + UErrorCode * err); /** * Functor Substitute the ILLEGAL SEQUENCE with a sequence escaped codepoints corresponding to the ILLEGAL @@ -109,30 +159,28 @@ U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_SUBSTITUTE (UConverter * _this, * @stable */ -U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_ESCAPE (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t* offsets, - UBool flush, - UErrorCode * err); +U_CAPI void U_EXPORT2 UCNV_FROM_U_CALLBACK_ESCAPE ( + void *context, + UConverterFromUnicodeArgs *fromUArgs, + const UChar* codeUnits, + int32_t length, + UChar32 codePoint, + UConverterCallbackReason reason, + UErrorCode * err); /** * Functor SKIPs the ILLEGAL_SEQUENCE * @stable */ -U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_SKIP (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t* offsets, - UBool flush, +U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_SKIP ( + void *context, + UConverterToUnicodeArgs *fromUArgs, + const char* codeUnits, + int32_t length, + UConverterCallbackReason reason, UErrorCode * err); - /** * Functor Substitute the ILLEGAL SEQUENCE with the current substitution string assiciated with _this, * in the event target buffer is too small, it will store the extra info in the UConverter, and err @@ -140,14 +188,13 @@ U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_SKIP (UConverter * _this, * store the left over data in target, before transcoding the "source Stream" * @stable */ -U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_SUBSTITUTE (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t* offsets, - UBool flush, - UErrorCode * err); +U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_SUBSTITUTE ( + void *context, + UConverterToUnicodeArgs *fromUArgs, + const char* codeUnits, + int32_t length, + UConverterCallbackReason reason, + UErrorCode * err); /** * Functor Substitute the ILLEGAL SEQUENCE with a sequence escaped codepoints corresponding to the @@ -158,14 +205,12 @@ U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_SUBSTITUTE (UConverter * _this, * @stable */ -U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_ESCAPE (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t* offsets, - UBool flush, - UErrorCode * err); - +U_CAPI void U_EXPORT2 UCNV_TO_U_CALLBACK_ESCAPE ( + void *context, + UConverterToUnicodeArgs *fromUArgs, + const char* codeUnits, + int32_t length, + UConverterCallbackReason reason, + UErrorCode * err); #endif/*UCNV_ERR_H*/ diff --git a/icu4c/source/test/cintltst/ccapitst.c b/icu4c/source/test/cintltst/ccapitst.c index 7c93c3f36ad..206b9ed4248 100644 --- a/icu4c/source/test/cintltst/ccapitst.c +++ b/icu4c/source/test/cintltst/ccapitst.c @@ -197,6 +197,11 @@ void TestConvert() } }; + UConverterFromUCallback oldFromUAction; + UConverterToUCallback oldToUAction; + void* oldFromUContext = NULL; + void* oldToUContext = NULL; + /* flush the converter cache to get a consistent state before the flushing is tested */ ucnv_flushCache(); @@ -465,7 +470,7 @@ void TestConvert() MIA1 = ucnv_getFromUCallBack(myConverter); log_verbose("\n---Testing ucnv_setFromUCallBack...\n"); - ucnv_setFromUCallBack(myConverter,otherUnicodeAction(MIA1), &err); + ucnv_setFromUCallBack(myConverter, otherUnicodeAction(MIA1), NULL, oldFromUAction, &oldFromUContext, err); if (U_FAILURE(err)) { log_err("FAILURE! %s\n", myErrorName(err)); } @@ -475,7 +480,7 @@ void TestConvert() log_verbose("get From UCallBack ok\n"); log_verbose("\n---Testing getFromUCallBack Roundtrip...\n"); - ucnv_setFromUCallBack(myConverter,MIA1, &err); + ucnv_setFromUCallBack(myConverter,MIA1, NULL, oldFromUAction, &oldFromUContext, &err); if (U_FAILURE(err)) { log_err("FAILURE! %s\n", myErrorName(err)); } @@ -490,7 +495,7 @@ void TestConvert() MIA2 = ucnv_getToUCallBack(myConverter); log_verbose("\n---Testing setTo UCallBack...\n"); - ucnv_setToUCallBack(myConverter,otherCharAction(MIA2),&err); + ucnv_setToUCallBack(myConverter,otherCharAction(MIA2), NULL, oldToUAction, &oldToUContext, &err); if (U_FAILURE(err)) { log_err("FAILURE! %s\n", myErrorName(err));} @@ -500,7 +505,7 @@ void TestConvert() log_verbose("To UCallBack ok\n"); log_verbose("\n---Testing setTo UCallBack Roundtrip...\n"); - ucnv_setToUCallBack(myConverter,MIA2, &err); + ucnv_setToUCallBack(myConverter,MIA2, NULL, oldToUAction, &oldToUContext, &err); if (U_FAILURE(err)) { log_err("FAILURE! %s\n", myErrorName(err)); } diff --git a/icu4c/source/test/cintltst/nccbtst.c b/icu4c/source/test/cintltst/nccbtst.c index 391e0a8fc93..3b0c1dbb89c 100644 --- a/icu4c/source/test/cintltst/nccbtst.c +++ b/icu4c/source/test/cintltst/nccbtst.c @@ -435,6 +435,8 @@ UBool testConvertFromUnicode(const UChar *source, int sourceLen, const char *ex char junk[9999]; char offset_str[9999]; char *p; + UConverterFromUCallback oldAction; + void* oldContext = NULL; for(i=0;isetMissingUnicodeAction(otherUnicodeAction(MIA1),err); + myConverter->setMissingUnicodeAction(otherUnicodeAction(MIA1), NULL, fromUAction, &fromUContext, err); if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err)); if (myConverter->getMissingUnicodeAction() != otherUnicodeAction(MIA1)) logln("Missing action failed"); else logln("Missing action ok"); logln("\n---Testing UnicodeConverterCPP::setMissingUnicodeAction Roundtrip..."); - myConverter->setMissingUnicodeAction(MIA1, err); + myConverter->setMissingUnicodeAction(MIA1, NULL, fromUAction, &fromUContext, err); if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err)); if (myConverter->getMissingUnicodeAction() != MIA1) errln("Missing action failed"); else logln("Missing action ok"); @@ -372,13 +377,13 @@ void ConvertTest::TestConvert() /*setMissingCharAction*/ logln("\n---Testing UnicodeConverterCPP::setMissingCharAction..."); - myConverter->setMissingCharAction(otherCharAction(MIA2),err); + myConverter->setMissingCharAction(otherCharAction(MIA2), NULL, toUAction, &toUContext, err); if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err)); if (myConverter->getMissingCharAction() != otherCharAction(MIA2)) errln("Missing action failed"); else logln("Missing action ok"); logln("\n---Testing UnicodeConverterCPP::setMissingCharAction Roundtrip..."); - myConverter->setMissingCharAction(MIA2, err); + myConverter->setMissingCharAction(MIA2, NULL, toUAction, &toUContext, err); if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err)); if (myConverter->getMissingCharAction() != MIA2) errln("Missing action failed"); else logln("Missing action ok"); diff --git a/icu4c/source/tools/makeconv/makeconv.c b/icu4c/source/tools/makeconv/makeconv.c index 5796cb54f30..c6d26d4452b 100644 --- a/icu4c/source/tools/makeconv/makeconv.c +++ b/icu4c/source/tools/makeconv/makeconv.c @@ -12,14 +12,15 @@ * table (IBM NLTC ucmap format). * * 05/04/2000 helena Added fallback mapping into the picture... + * 06/29/2000 helena Major rewrite of the callback APIs. */ #include #include "ucmp16.h" #include "ucmp8.h" #include "ucnv_io.h" -#include "unicode/ucnv_bld.h" #include "unicode/ucnv_err.h" +#include "ucnv_bld.h" #include "ucnv_imp.h" #include "ucnv_cnv.h" #include "cstring.h" diff --git a/icu4c/source/tools/makeconv/ucnvstat.c b/icu4c/source/tools/makeconv/ucnvstat.c index a1850eeca8e..9bdc5cef248 100644 --- a/icu4c/source/tools/makeconv/ucnvstat.c +++ b/icu4c/source/tools/makeconv/ucnvstat.c @@ -13,7 +13,7 @@ #include "unicode/utypes.h" #include "unicode/ucnv.h" -#include "unicode/ucnv_bld.h" +#include "ucnv_bld.h" static const UConverterStaticData _SBCSStaticData={ sizeof(UConverterStaticData),