From 20baeae40179f4fec0f43613abcc0b35f25cda2b Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Mon, 7 Feb 2000 17:35:21 +0000 Subject: [PATCH] ICU-266 c++-ify UConverter (UConverterImpl resembles a vtable) X-SVN-Rev: 723 --- icu4c/source/common/Makefile.in | 2 +- icu4c/source/common/common.dsp | 22 ++- .../source/common/{ucnv_2022.c => ucnv2022.c} | 2 +- icu4c/source/common/ucnv_utf.c | 139 --------------- icu4c/source/common/ucnvlat1.c | 159 ++++++++++++++++++ .../source/common/{ucnv_mbcs.c => ucnvmbcs.c} | 2 +- .../source/common/{ucnv_sbcs.c => ucnvsbcs.c} | 2 +- 7 files changed, 176 insertions(+), 152 deletions(-) rename icu4c/source/common/{ucnv_2022.c => ucnv2022.c} (99%) create mode 100644 icu4c/source/common/ucnvlat1.c rename icu4c/source/common/{ucnv_mbcs.c => ucnvmbcs.c} (99%) rename icu4c/source/common/{ucnv_sbcs.c => ucnvsbcs.c} (99%) diff --git a/icu4c/source/common/Makefile.in b/icu4c/source/common/Makefile.in index 64c7d2e79d..57ce863dce 100644 --- a/icu4c/source/common/Makefile.in +++ b/icu4c/source/common/Makefile.in @@ -75,7 +75,7 @@ uchar.o uchriter.o ucmp8.o ucmp16.o ucmp32.o ucnv.o ucnv_bld.o \ ucnv_cnv.o ucnv_err.o ucnv_io.o uhash.o uloc.o unicode.o unistr.o \ ures.o ustring.o rbread.o rbdata.o ubidi.o ubidiln.o \ bidi.o uvector.o udata.o unames.o utf_impl.o \ -ucnv_2022.o ucnv_utf.o ucnv_sbcs.o ucnv_mbcs.o +ucnv2022.o ucnvlat1.o ucnv_utf.o ucnvsbcs.o ucnvmbcs.o DEPS = $(OBJECTS:.o=.d) diff --git a/icu4c/source/common/common.dsp b/icu4c/source/common/common.dsp index 85ad768293..36e821f83a 100644 --- a/icu4c/source/common/common.dsp +++ b/icu4c/source/common/common.dsp @@ -211,7 +211,7 @@ SOURCE=.\ucnv.c # End Source File # Begin Source File -SOURCE=.\ucnv_2022.c +SOURCE=.\ucnv2022.c # End Source File # Begin Source File @@ -231,18 +231,22 @@ SOURCE=.\ucnv_io.c # End Source File # Begin Source File -SOURCE=.\ucnv_mbcs.c -# End Source File -# Begin Source File - -SOURCE=.\ucnv_sbcs.c -# End Source File -# Begin Source File - SOURCE=.\ucnv_utf.c # End Source File # Begin Source File +SOURCE=.\ucnvlat1.c +# End Source File +# Begin Source File + +SOURCE=.\ucnvmbcs.c +# End Source File +# Begin Source File + +SOURCE=.\ucnvsbcs.c +# End Source File +# Begin Source File + SOURCE=.\udata.c # ADD CPP /Ze # End Source File diff --git a/icu4c/source/common/ucnv_2022.c b/icu4c/source/common/ucnv2022.c similarity index 99% rename from icu4c/source/common/ucnv_2022.c rename to icu4c/source/common/ucnv2022.c index 6bf1ebc4a2..73fe108cc7 100644 --- a/icu4c/source/common/ucnv_2022.c +++ b/icu4c/source/common/ucnv2022.c @@ -3,7 +3,7 @@ * Copyright (C) 2000, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** -* file name: ucnv_2022.cpp +* file name: ucnv2022.cpp * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 diff --git a/icu4c/source/common/ucnv_utf.c b/icu4c/source/common/ucnv_utf.c index d16e47b4ec..0caacef570 100644 --- a/icu4c/source/common/ucnv_utf.c +++ b/icu4c/source/common/ucnv_utf.c @@ -19,145 +19,6 @@ #include "unicode/ucnv.h" #include "ucnv_cnv.h" -/* ISO 8859-1 --------------------------------------------------------------- */ - -void T_UConverter_toUnicode_LATIN_1 (UConverter * _this, - UChar ** target, - const UChar * targetLimit, - const char **source, - const char *sourceLimit, - int32_t *offsets, - bool_t flush, - UErrorCode * err) -{ - unsigned char *mySource = (unsigned char *) *source; - UChar *myTarget = *target; - int32_t sourceLength = sourceLimit - (char *) mySource; - int32_t readLen = 0; - int32_t i = 0; - - /*Since there is no risk of encountering illegal Chars - *we need to pad our latin1 chars to create Unicode codepoints - *we need to go as far a min(targetLen, sourceLen) - *in case we don't have enough buffer space - *we set the error flag accordingly - */ - if ((targetLimit - *target) < sourceLength) - { - readLen = targetLimit - *target; - *err = U_INDEX_OUTOFBOUNDS_ERROR; - } - else - { - readLen = sourceLimit - (char *) mySource; - } - - for (i = 0; i < readLen; i++) myTarget[i] = (UChar) mySource[i]; - - *target += i; - *source += i; - return; -} - -void T_UConverter_fromUnicode_LATIN_1 (UConverter * _this, - char **target, - const char *targetLimit, - const UChar ** source, - const UChar * sourceLimit, - int32_t *offsets, - bool_t flush, - UErrorCode * err) -{ - const UChar *mySource = *source; - unsigned char *myTarget = (unsigned char *) *target; - int32_t mySourceIndex = 0; - int32_t myTargetIndex = 0; - int32_t targetLength = targetLimit - (char *) myTarget; - int32_t sourceLength = sourceLimit - mySource; - - /*writing the char to the output stream */ - while (mySourceIndex < sourceLength) - { - - if (myTargetIndex < targetLength) - { - if (mySource[mySourceIndex] < 0x0100) - { - /*writes the char to the output stream */ - myTarget[myTargetIndex++] = (char) mySource[mySourceIndex++]; - } - else - { - *err = U_INVALID_CHAR_FOUND; - _this->invalidUCharBuffer[0] = (UChar) mySource[mySourceIndex++]; - _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); - - if (U_FAILURE (*err)) break; - _this->invalidUCharLength = 0; - } - } - else - { - *err = U_INDEX_OUTOFBOUNDS_ERROR; - break; - } - } - - *target += myTargetIndex; - *source += mySourceIndex;; - - return; -} - -UChar T_UConverter_getNextUChar_LATIN_1(UConverter* converter, - const char** source, - const char* sourceLimit, - UErrorCode* err) -{ - - /* Empties the internal buffers if need be - * In this case since ErrorFunctors are never called - * (LATIN_1 is a subset of Unicode) - */ - - if ((*source)+1 > sourceLimit) - { - *err = U_INDEX_OUTOFBOUNDS_ERROR; - return 0xFFFD; - } - - return (UChar)*((*source)++); -} - -static UConverterImpl _Latin1Impl={ - UCNV_LATIN_1, - - T_UConverter_toUnicode_LATIN_1, - NULL, - T_UConverter_fromUnicode_LATIN_1, - NULL, - T_UConverter_getNextUChar_LATIN_1 -}; - -extern UConverterSharedData _Latin1Data={ - sizeof(UConverterSharedData), ~0, - NULL, NULL, &_Latin1Impl, "LATIN_1", - 819, UCNV_IBM, UCNV_LATIN_1, 1, 1, - { 0, 1, 0x1a, 0, 0, 0 } -}; - /* UTF-8 -------------------------------------------------------------------- */ /* UTF-8 Conversion DATA diff --git a/icu4c/source/common/ucnvlat1.c b/icu4c/source/common/ucnvlat1.c new file mode 100644 index 0000000000..b016e737e2 --- /dev/null +++ b/icu4c/source/common/ucnvlat1.c @@ -0,0 +1,159 @@ +/* +********************************************************************** +* Copyright (C) 2000, International Business Machines +* Corporation and others. All Rights Reserved. +********************************************************************** +* file name: ucnvlat1.cpp +* encoding: US-ASCII +* tab size: 8 (not used) +* indentation:4 +* +* created on: 2000feb07 +* created by: Markus W. Scherer +*/ + +#include "unicode/utypes.h" +#include "ucmp16.h" +#include "ucmp8.h" +#include "unicode/ucnv_bld.h" +#include "unicode/ucnv.h" +#include "ucnv_cnv.h" + +/* ISO 8859-1 --------------------------------------------------------------- */ + +void T_UConverter_toUnicode_LATIN_1 (UConverter * _this, + UChar ** target, + const UChar * targetLimit, + const char **source, + const char *sourceLimit, + int32_t *offsets, + bool_t flush, + UErrorCode * err) +{ + unsigned char *mySource = (unsigned char *) *source; + UChar *myTarget = *target; + int32_t sourceLength = sourceLimit - (char *) mySource; + int32_t readLen = 0; + int32_t i = 0; + + /*Since there is no risk of encountering illegal Chars + *we need to pad our latin1 chars to create Unicode codepoints + *we need to go as far a min(targetLen, sourceLen) + *in case we don't have enough buffer space + *we set the error flag accordingly + */ + if ((targetLimit - *target) < sourceLength) + { + readLen = targetLimit - *target; + *err = U_INDEX_OUTOFBOUNDS_ERROR; + } + else + { + readLen = sourceLimit - (char *) mySource; + } + + for (i = 0; i < readLen; i++) myTarget[i] = (UChar) mySource[i]; + + *target += i; + *source += i; + return; +} + +void T_UConverter_fromUnicode_LATIN_1 (UConverter * _this, + char **target, + const char *targetLimit, + const UChar ** source, + const UChar * sourceLimit, + int32_t *offsets, + bool_t flush, + UErrorCode * err) +{ + const UChar *mySource = *source; + unsigned char *myTarget = (unsigned char *) *target; + int32_t mySourceIndex = 0; + int32_t myTargetIndex = 0; + int32_t targetLength = targetLimit - (char *) myTarget; + int32_t sourceLength = sourceLimit - mySource; + + /*writing the char to the output stream */ + while (mySourceIndex < sourceLength) + { + + if (myTargetIndex < targetLength) + { + if (mySource[mySourceIndex] < 0x0100) + { + /*writes the char to the output stream */ + myTarget[myTargetIndex++] = (char) mySource[mySourceIndex++]; + } + else + { + *err = U_INVALID_CHAR_FOUND; + _this->invalidUCharBuffer[0] = (UChar) mySource[mySourceIndex++]; + _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); + + if (U_FAILURE (*err)) break; + _this->invalidUCharLength = 0; + } + } + else + { + *err = U_INDEX_OUTOFBOUNDS_ERROR; + break; + } + } + + *target += myTargetIndex; + *source += mySourceIndex;; + + return; +} + +UChar T_UConverter_getNextUChar_LATIN_1(UConverter* converter, + const char** source, + const char* sourceLimit, + UErrorCode* err) +{ + + /* Empties the internal buffers if need be + * In this case since ErrorFunctors are never called + * (LATIN_1 is a subset of Unicode) + */ + + if ((*source)+1 > sourceLimit) + { + *err = U_INDEX_OUTOFBOUNDS_ERROR; + return 0xFFFD; + } + + return (UChar)*((*source)++); +} + +static UConverterImpl _Latin1Impl={ + UCNV_LATIN_1, + + T_UConverter_toUnicode_LATIN_1, + NULL, + T_UConverter_fromUnicode_LATIN_1, + NULL, + T_UConverter_getNextUChar_LATIN_1 +}; + +extern UConverterSharedData _Latin1Data={ + sizeof(UConverterSharedData), ~0, + NULL, NULL, &_Latin1Impl, "LATIN_1", + 819, UCNV_IBM, UCNV_LATIN_1, 1, 1, + { 0, 1, 0x1a, 0, 0, 0 } +}; diff --git a/icu4c/source/common/ucnv_mbcs.c b/icu4c/source/common/ucnvmbcs.c similarity index 99% rename from icu4c/source/common/ucnv_mbcs.c rename to icu4c/source/common/ucnvmbcs.c index 1b1ba1da4b..2528a89829 100644 --- a/icu4c/source/common/ucnv_mbcs.c +++ b/icu4c/source/common/ucnvmbcs.c @@ -3,7 +3,7 @@ * Copyright (C) 2000, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** -* file name: ucnv_mbcs.cpp +* file name: ucnvmbcs.cpp * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 diff --git a/icu4c/source/common/ucnv_sbcs.c b/icu4c/source/common/ucnvsbcs.c similarity index 99% rename from icu4c/source/common/ucnv_sbcs.c rename to icu4c/source/common/ucnvsbcs.c index c09bf2e7ff..2ec6d6c484 100644 --- a/icu4c/source/common/ucnv_sbcs.c +++ b/icu4c/source/common/ucnvsbcs.c @@ -3,7 +3,7 @@ * Copyright (C) 2000, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** -* file name: ucnv_sbcs.cpp +* file name: ucnvsbcs.cpp * encoding: US-ASCII * tab size: 8 (not used) * indentation:4