From 7bb221a1877d1e6c3998bb861bad85b52efaa94e Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Fri, 31 Aug 2007 19:39:14 +0000 Subject: [PATCH] ICU-5869 revert changes (r22476); too risky and needs further discussion; see ticket reply X-SVN-Rev: 22607 --- icu4c/source/common/ucasemap.c | 2 +- icu4c/source/common/ucnv.c | 32 ++++++----- icu4c/source/common/uloc.c | 22 ++++---- icu4c/source/common/unames.c | 8 +-- icu4c/source/common/unicode/ucnv.h | 11 ++-- icu4c/source/common/unicode/unistr.h | 17 ++---- icu4c/source/common/unistr.cpp | 2 +- icu4c/source/common/unistr_cnv.cpp | 10 ++-- icu4c/source/common/uresbund.c | 4 +- icu4c/source/common/ustr_imp.h | 9 +--- icu4c/source/common/ustring.c | 22 ++++---- icu4c/source/common/ustrtrns.c | 2 +- icu4c/source/test/cintltst/nfsprep.c | 4 +- icu4c/source/test/intltest/ustrtest.cpp | 72 ------------------------- icu4c/source/tools/toolutil/uparse.c | 2 +- 15 files changed, 59 insertions(+), 160 deletions(-) diff --git a/icu4c/source/common/ucasemap.c b/icu4c/source/common/ucasemap.c index c15d6c6339b..ac20ba313da 100644 --- a/icu4c/source/common/ucasemap.c +++ b/icu4c/source/common/ucasemap.c @@ -509,7 +509,7 @@ caseMap(const UCaseMap *csm, } } - return u_terminateChars((char *)dest, destCapacity, destLength, 1, pErrorCode); + return u_terminateChars((char *)dest, destCapacity, destLength, pErrorCode); } /* public API functions */ diff --git a/icu4c/source/common/ucnv.c b/icu4c/source/common/ucnv.c index 0197e9c7d10..9ef346fb612 100644 --- a/icu4c/source/common/ucnv.c +++ b/icu4c/source/common/ucnv.c @@ -1762,7 +1762,7 @@ ucnv_fromUChars(UConverter *cnv, destLength=0; } - return u_terminateChars(originalDest, destCapacity, destLength, ucnv_getMinCharSize(cnv), pErrorCode); + return u_terminateChars(originalDest, destCapacity, destLength, pErrorCode); } U_CAPI int32_t U_EXPORT2 @@ -2415,7 +2415,7 @@ ucnv_internalConvert(UConverter *outConverter, UConverter *inConverter, /* if there is no input data, we're done */ if(source==sourceLimit) { - return u_terminateChars(target, targetCapacity, 0, ucnv_getMinCharSize(outConverter), pErrorCode); + return u_terminateChars(target, targetCapacity, 0, pErrorCode); } pivot=pivot2=pivotBuffer; @@ -2459,7 +2459,7 @@ ucnv_internalConvert(UConverter *outConverter, UConverter *inConverter, } while(*pErrorCode==U_BUFFER_OVERFLOW_ERROR); /* done with preflighting, set warnings and errors as appropriate */ - return u_terminateChars(target, targetCapacity, targetLength, ucnv_getMinCharSize(outConverter), pErrorCode); + return u_terminateChars(target, targetCapacity, targetLength, pErrorCode); } /* no need to call u_terminateChars() because ucnv_convertEx() took care of that */ @@ -2470,11 +2470,10 @@ U_CAPI int32_t U_EXPORT2 ucnv_convert(const char *toConverterName, const char *fromConverterName, char *target, int32_t targetCapacity, const char *source, int32_t sourceLength, - UErrorCode *pErrorCode) -{ + UErrorCode *pErrorCode) { UConverter in, out; /* stack-allocated */ - UConverter *inConverter = NULL, *outConverter = NULL; - int32_t targetLength = 0; + UConverter *inConverter, *outConverter; + int32_t targetLength; if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { return 0; @@ -2487,21 +2486,21 @@ ucnv_convert(const char *toConverterName, const char *fromConverterName, return 0; } - outConverter=ucnv_createConverter(&out, toConverterName, pErrorCode); - if(U_FAILURE(*pErrorCode)) { - goto cleanup; - } - /* if there is no input data, we're done */ if(sourceLength==0 || (sourceLength<0 && *source==0)) { - targetLength = u_terminateChars(target, targetCapacity, 0, ucnv_getMinCharSize(outConverter), pErrorCode); - goto cleanup; + return u_terminateChars(target, targetCapacity, 0, pErrorCode); } /* create the converters */ inConverter=ucnv_createConverter(&in, fromConverterName, pErrorCode); if(U_FAILURE(*pErrorCode)) { - goto cleanup; + return 0; + } + + outConverter=ucnv_createConverter(&out, toConverterName, pErrorCode); + if(U_FAILURE(*pErrorCode)) { + ucnv_close(inConverter); + return 0; } targetLength=ucnv_internalConvert(outConverter, inConverter, @@ -2509,7 +2508,6 @@ ucnv_convert(const char *toConverterName, const char *fromConverterName, source, sourceLength, pErrorCode); -cleanup: ucnv_close(inConverter); ucnv_close(outConverter); @@ -2541,7 +2539,7 @@ ucnv_convertAlgorithmic(UBool convertToAlgorithmic, /* if there is no input data, we're done */ if(sourceLength==0 || (sourceLength<0 && *source==0)) { - return u_terminateChars(target, targetCapacity, 0, ucnv_getMinCharSize(cnv), pErrorCode); + return u_terminateChars(target, targetCapacity, 0, pErrorCode); } /* create the algorithmic converter */ diff --git a/icu4c/source/common/uloc.c b/icu4c/source/common/uloc.c index be23db87ba0..1d8be3b44a9 100644 --- a/icu4c/source/common/uloc.c +++ b/icu4c/source/common/uloc.c @@ -774,7 +774,7 @@ _getKeywords(const char *localeID, *valLen = valuesLen; } } - return u_terminateChars(keywords, keywordCapacity, keywordsLen, 1, status); + return u_terminateChars(keywords, keywordCapacity, keywordsLen, status); } else { return 0; } @@ -856,14 +856,14 @@ uloc_getKeywordValue(const char* localeID, startSearchHere--; } uprv_strncpy(buffer, nextSeparator, startSearchHere - nextSeparator); - result = u_terminateChars(buffer, bufferCapacity, (int32_t)(startSearchHere - nextSeparator), 1, status); + result = u_terminateChars(buffer, bufferCapacity, (int32_t)(startSearchHere - nextSeparator), status); } else if(!startSearchHere && (int32_t)uprv_strlen(nextSeparator) < bufferCapacity) { /* last item in string */ i = (int32_t)uprv_strlen(nextSeparator); while(nextSeparator[i - 1] == ' ') { i--; } uprv_strncpy(buffer, nextSeparator, i); - result = u_terminateChars(buffer, bufferCapacity, i, 1, status); + result = u_terminateChars(buffer, bufferCapacity, i, status); } else { /* give a bigger buffer, please */ *status = U_BUFFER_OVERFLOW_ERROR; @@ -1766,7 +1766,7 @@ _canonicalize(const char* localeID, uprv_strncpy(result, localeBuffer, (len > resultCapacity) ? resultCapacity : len); } - return u_terminateChars(result, resultCapacity, len, 1, err); + return u_terminateChars(result, resultCapacity, len, err); } /* ### ID parsing API **************************************************/ @@ -1796,7 +1796,7 @@ uloc_getParent(const char* localeID, if(i>0 && parent != localeID) { uprv_memcpy(parent, localeID, uprv_min(i, parentCapacity)); } - return u_terminateChars(parent, parentCapacity, i, 1, err); + return u_terminateChars(parent, parentCapacity, i, err); } U_CAPI int32_t U_EXPORT2 @@ -1817,7 +1817,7 @@ uloc_getLanguage(const char* localeID, } i=_getLanguage(localeID, language, languageCapacity, NULL); - return u_terminateChars(language, languageCapacity, i, 1, err); + return u_terminateChars(language, languageCapacity, i, err); } U_CAPI int32_t U_EXPORT2 @@ -1841,7 +1841,7 @@ uloc_getScript(const char* localeID, if(_isIDSeparator(*localeID)) { i=_getScript(localeID+1, script, scriptCapacity, NULL); } - return u_terminateChars(script, scriptCapacity, i, 1, err); + return u_terminateChars(script, scriptCapacity, i, err); } U_CAPI int32_t U_EXPORT2 @@ -1874,7 +1874,7 @@ uloc_getCountry(const char* localeID, i=_getCountry(localeID+1, country, countryCapacity, NULL); } } - return u_terminateChars(country, countryCapacity, i, 1, err); + return u_terminateChars(country, countryCapacity, i, err); } U_CAPI int32_t U_EXPORT2 @@ -1919,7 +1919,7 @@ uloc_getVariant(const char* localeID, i=_getVariant(localeID+1, '@', variant, variantCapacity); } */ - return u_terminateChars(variant, variantCapacity, i, 1, err); + return u_terminateChars(variant, variantCapacity, i, err); } U_CAPI int32_t U_EXPORT2 @@ -2978,7 +2978,7 @@ uloc_acceptLanguage(char *result, int32_t resultAvailable, uprv_free(fallbackList[j]); } uprv_free(fallbackList); - return u_terminateChars(result, resultAvailable, len, 1, status); + return u_terminateChars(result, resultAvailable, len, status); } if(len>maxLen) { maxLen = len; @@ -3018,7 +3018,7 @@ uloc_acceptLanguage(char *result, int32_t resultAvailable, uprv_free(fallbackList[j]); } uprv_free(fallbackList); - return u_terminateChars(result, resultAvailable, len, 1, status); + return u_terminateChars(result, resultAvailable, len, status); } } uenum_reset(availableLocales, status); diff --git a/icu4c/source/common/unames.c b/icu4c/source/common/unames.c index a6c568b7bf4..c12033fa47d 100644 --- a/icu4c/source/common/unames.c +++ b/icu4c/source/common/unames.c @@ -1441,7 +1441,7 @@ u_charName(UChar32 code, UCharNameChoice nameChoice, } if((uint32_t)code>UCHAR_MAX_VALUE || !isDataLoaded(pErrorCode)) { - return u_terminateChars(buffer, bufferLength, 0, 1, pErrorCode); + return u_terminateChars(buffer, bufferLength, 0, pErrorCode); } length=0; @@ -1472,7 +1472,7 @@ u_charName(UChar32 code, UCharNameChoice nameChoice, } } - return u_terminateChars(buffer, bufferLength, length, 1, pErrorCode); + return u_terminateChars(buffer, bufferLength, length, pErrorCode); } U_CAPI int32_t U_EXPORT2 @@ -1490,12 +1490,12 @@ u_getISOComment(UChar32 c, } if((uint32_t)c>UCHAR_MAX_VALUE || !isDataLoaded(pErrorCode)) { - return u_terminateChars(dest, destCapacity, 0, 1, pErrorCode); + return u_terminateChars(dest, destCapacity, 0, pErrorCode); } /* the ISO comment is stored like a normal character name */ length=getName(uCharNames, (uint32_t)c, U_ISO_COMMENT, dest, (uint16_t)destCapacity); - return u_terminateChars(dest, destCapacity, length, 1, pErrorCode); + return u_terminateChars(dest, destCapacity, length, pErrorCode); } U_CAPI UChar32 U_EXPORT2 diff --git a/icu4c/source/common/unicode/ucnv.h b/icu4c/source/common/unicode/ucnv.h index 6579934a8a1..5e49a83e323 100644 --- a/icu4c/source/common/unicode/ucnv.h +++ b/icu4c/source/common/unicode/ucnv.h @@ -1149,14 +1149,9 @@ ucnv_toUnicode(UConverter *converter, * common error codes that may be set by this function include * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING, * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors - * @return The length of the output string, not counting the terminating NUL. - * The terminating NUL may be larger than one byte for the encodings of - * some codepages, like UTF-32, where the terminating NUL is 4 bytes. - * The terminating NUL is written when there is room in the dest buffer. - * If the length is greater than destCapacity, then the string will not fit - * and a buffer of the indicated length would need to be passed in. - * This return value plus the value of ucnv_getMinCharSize will give you a - * buffer large enough for the conversion. + * @return the length of the output string, not counting the terminating NUL; + * if the length is greater than destCapacity, then the string will not fit + * and a buffer of the indicated length would need to be passed in * @see ucnv_fromUnicode * @see ucnv_convert * @see UCNV_GET_MAX_BYTES_FOR_STRING diff --git a/icu4c/source/common/unicode/unistr.h b/icu4c/source/common/unicode/unistr.h index 433c7210aa0..575998e4ed4 100644 --- a/icu4c/source/common/unicode/unistr.h +++ b/icu4c/source/common/unicode/unistr.h @@ -1468,10 +1468,7 @@ public: * If target is NULL, then the number of bytes required for * target is returned. It is assumed that the target is big enough * to fit all of the characters. - * @return the output string length, not including the terminating NUL. - * The terminating NUL may be larger than one byte for the encodings of - * some codepages, like UTF-32, where the terminating NUL is 4 bytes. - * The terminating NUL is written when there is room in the target buffer. + * @return the output string length, not including the terminating NUL * @stable ICU 2.0 */ inline int32_t extract(int32_t start, @@ -1506,9 +1503,6 @@ public: * If target is NULL, then the number of bytes required for * target is returned. * @return the output string length, not including the terminating NUL - * The terminating NUL may be larger than one byte for the encodings of - * some codepages, like UTF-32, where the terminating NUL is 4 bytes. - * The terminating NUL is written when there is room in the target buffer. * @stable ICU 2.0 */ int32_t extract(int32_t start, @@ -1529,12 +1523,9 @@ public: * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called), * or NULL for the default converter * @param errorCode normal ICU error code - * @return the length of the output string, not counting the terminating NUL. - * The terminating NUL may be larger than one byte for the encodings of - * some codepages, like UTF-32, where the terminating NUL is 4 bytes. - * The terminating NUL is written when there is room in the dest buffer. - * If the length is greater than destCapacity, then the string will not fit - * and a buffer of the indicated length would need to be passed in. + * @return the length of the output string, not counting the terminating NUL; + * if the length is greater than destCapacity, then the string will not fit + * and a buffer of the indicated length would need to be passed in * @stable ICU 2.0 */ int32_t extract(char *dest, int32_t destCapacity, diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index fa8db8e9fb4..d8bea383267 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -723,7 +723,7 @@ UnicodeString::extract(int32_t start, u_UCharsToChars(getArrayStart() + start, target, length); } UErrorCode status = U_ZERO_ERROR; - return u_terminateChars(target, targetCapacity, length, 1, &status); + return u_terminateChars(target, targetCapacity, length, &status); } void diff --git a/icu4c/source/common/unistr_cnv.cpp b/icu4c/source/common/unistr_cnv.cpp index fb927d2897e..a5166e09d8b 100644 --- a/icu4c/source/common/unistr_cnv.cpp +++ b/icu4c/source/common/unistr_cnv.cpp @@ -123,8 +123,6 @@ UnicodeString::extract(int32_t start, UConverter *converter; UErrorCode status = U_ZERO_ERROR; - // We don't NULL terminate here because we might need 1 to 4 bytes for the termination. - /* // just write the NUL if the string length is 0 if(length == 0) { if(dstSize >= 0x80000000) { @@ -133,7 +131,7 @@ UnicodeString::extract(int32_t start, dstSize=0x7fffffff; } return u_terminateChars(target, dstSize, 0, &status); - }*/ + } // if the codepage is the default, use our cache // if it is an empty string, then use the "invariant character" conversion @@ -153,7 +151,7 @@ UnicodeString::extract(int32_t start, destLength = (int32_t)dstSize; } u_UCharsToChars(getArrayStart() + start, target, destLength); - return u_terminateChars(target, (int32_t)dstSize, length, 1, &status); + return u_terminateChars(target, (int32_t)dstSize, length, &status); } else { converter = ucnv_open(codepage, &status); } @@ -186,7 +184,7 @@ UnicodeString::extract(char *dest, int32_t destCapacity, // nothing to do? if(fLength<=0) { - return u_terminateChars(dest, destCapacity, 0, ucnv_getMinCharSize(cnv), &errorCode); + return u_terminateChars(dest, destCapacity, 0, &errorCode); } // get the converter @@ -258,7 +256,7 @@ UnicodeString::doExtract(int32_t start, int32_t length, } while(errorCode==U_BUFFER_OVERFLOW_ERROR); } - return u_terminateChars(originalDest, destCapacity, length, ucnv_getMinCharSize(cnv), &errorCode); + return u_terminateChars(originalDest, destCapacity, length, &errorCode); } void diff --git a/icu4c/source/common/uresbund.c b/icu4c/source/common/uresbund.c index 4b33718c202..df66876269a 100644 --- a/icu4c/source/common/uresbund.c +++ b/icu4c/source/common/uresbund.c @@ -1032,7 +1032,7 @@ ures_toUTF8String(const UChar *s16, int32_t length16, *pLength = 0; } if (forceCopy) { - u_terminateChars(dest, capacity, 0, 1, status); + u_terminateChars(dest, capacity, 0, status); return dest; } else { return ""; @@ -2460,7 +2460,7 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, length = 0; result[0]=0; } - return u_terminateChars(result, resultCapacity, length, 1, status); + return u_terminateChars(result, resultCapacity, length, status); } U_CAPI UEnumeration* U_EXPORT2 diff --git a/icu4c/source/common/ustr_imp.h b/icu4c/source/common/ustr_imp.h index 52903cdf94f..7c6681682cc 100644 --- a/icu4c/source/common/ustr_imp.h +++ b/icu4c/source/common/ustr_imp.h @@ -190,16 +190,9 @@ u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode /** * NUL-terminate a char * string if possible. * Same as u_terminateUChars() but for a different string type. - * @param dest The buffer to NULL terminate. - * @param destCapacity The size in bytes for the dest buffer. - * @param length The number of bytes used in dest. - * @param sizeOfNULL When a non-ASCII compatible encoding is used, like UTF-32, - * UTF-16 or some DBCS encoding, this specifies the number of bytes used - * by the NULL termination. This should be 1 for the invariant codepage. - * @return length */ U_CAPI int32_t U_EXPORT2 -u_terminateChars(char *dest, int32_t destCapacity, int32_t length, int32_t sizeOfNULL, UErrorCode *pErrorCode); +u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); /** * NUL-terminate a UChar32 * string if possible. diff --git a/icu4c/source/common/ustring.c b/icu4c/source/common/ustring.c index 597e9f9a89a..4ccd7a00591 100644 --- a/icu4c/source/common/ustring.c +++ b/icu4c/source/common/ustring.c @@ -1443,16 +1443,15 @@ u_growBufferFromStatic(void *context, * NUL-terminate a string no matter what its type. * Set warning and error codes accordingly. */ -#define __TERMINATE_STRING(dest, destCapacity, length, sizeOfNull, pErrorCode) \ +#define __TERMINATE_STRING(dest, destCapacity, length, pErrorCode) \ if(pErrorCode!=NULL && U_SUCCESS(*pErrorCode)) { \ /* not a public function, so no complete argument checking */ \ + \ if(length<0) { \ /* assume that the caller handles this */ \ - } else if(sizeOfNull > 0 && (length+sizeOfNull)<=destCapacity) {\ + } else if(length 0); \ + dest[length]=0; \ /* unset the not-terminated warning but leave all others */ \ if(*pErrorCode==U_STRING_NOT_TERMINATED_WARNING) { \ *pErrorCode=U_ZERO_ERROR; \ @@ -1468,27 +1467,24 @@ u_growBufferFromStatic(void *context, U_CAPI int32_t U_EXPORT2 u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode) { - int32_t sizeOfNull = 1; - __TERMINATE_STRING(dest, destCapacity, length, sizeOfNull, pErrorCode); + __TERMINATE_STRING(dest, destCapacity, length, pErrorCode); return length; } U_CAPI int32_t U_EXPORT2 -u_terminateChars(char *dest, int32_t destCapacity, int32_t length, int32_t sizeOfNull, UErrorCode *pErrorCode) { - __TERMINATE_STRING(dest, destCapacity, length, sizeOfNull, pErrorCode); +u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode) { + __TERMINATE_STRING(dest, destCapacity, length, pErrorCode); return length; } U_CAPI int32_t U_EXPORT2 u_terminateUChar32s(UChar32 *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode) { - int32_t sizeOfNull = 1; - __TERMINATE_STRING(dest, destCapacity, length, sizeOfNull, pErrorCode); + __TERMINATE_STRING(dest, destCapacity, length, pErrorCode); return length; } U_CAPI int32_t U_EXPORT2 u_terminateWChars(wchar_t *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode) { - int32_t sizeOfNull = 1; - __TERMINATE_STRING(dest, destCapacity, length, sizeOfNull, pErrorCode); + __TERMINATE_STRING(dest, destCapacity, length, pErrorCode); return length; } diff --git a/icu4c/source/common/ustrtrns.c b/icu4c/source/common/ustrtrns.c index dae017d2f44..5f013c10063 100644 --- a/icu4c/source/common/ustrtrns.c +++ b/icu4c/source/common/ustrtrns.c @@ -1161,7 +1161,7 @@ u_strToUTF8WithSub(char *dest, } /* Terminate the buffer */ - u_terminateChars((char*)dest,destCapacity,reqLength,1,pErrorCode); + u_terminateChars((char*)dest,destCapacity,reqLength,pErrorCode); return (char*)dest; } diff --git a/icu4c/source/test/cintltst/nfsprep.c b/icu4c/source/test/cintltst/nfsprep.c index 3f3395fb6d5..61b11214beb 100644 --- a/icu4c/source/test/cintltst/nfsprep.c +++ b/icu4c/source/test/cintltst/nfsprep.c @@ -129,7 +129,7 @@ CLEANUP: free(b3); } - return u_terminateChars(dest, destCapacity, reqLength, 1, status); + return u_terminateChars(dest, destCapacity, reqLength, status); } /* sorted array for binary search*/ @@ -273,7 +273,7 @@ CLEANUP: free(s); } - return u_terminateChars(dest, destCapacity, reqLen, 1, status); + return u_terminateChars(dest, destCapacity, reqLen, status); } int32_t diff --git a/icu4c/source/test/intltest/ustrtest.cpp b/icu4c/source/test/intltest/ustrtest.cpp index 39af66ea933..5b50fbaf48e 100644 --- a/icu4c/source/test/intltest/ustrtest.cpp +++ b/icu4c/source/test/intltest/ustrtest.cpp @@ -617,78 +617,6 @@ UnicodeStringTest::TestExtract() ucnv_close(cnv); } } - - { - // test UConverter extract() and constructor to properly NULL terminate - UnicodeString s=UNICODE_STRING_SIMPLE("hello"); - char buffer[24]; - static const char expect[]={ - 0,0,0,0x68, - 0,0,0,0x65, - 0,0,0,0x6C, - 0,0,0,0x6C, - 0,0,0,0x6F - }; - UErrorCode errorCode=U_ZERO_ERROR; - UConverter *cnv=ucnv_open("UTF-32BE", &errorCode); - int32_t length; - - if(U_SUCCESS(errorCode)) { - // test preflighting - if( (length=s.extract(NULL, 0, cnv, errorCode))!=20 || - errorCode!=U_BUFFER_OVERFLOW_ERROR - ) { - errln("UnicodeString::extract(NULL, UConverter) preflighting failed (length=%ld, %s)", - length, u_errorName(errorCode)); - } - errorCode=U_ZERO_ERROR; - if( (length=s.extract(buffer, 2, cnv, errorCode))!=20 || - errorCode!=U_BUFFER_OVERFLOW_ERROR - ) { - errln("UnicodeString::extract(too small, UConverter) preflighting failed (length=%ld, %s)", - length, u_errorName(errorCode)); - } - - // try error cases - errorCode=U_ZERO_ERROR; - if( s.extract(NULL, 2, cnv, errorCode)==20 || U_SUCCESS(errorCode)) { - errln("UnicodeString::extract(UConverter) succeeded with an illegal destination"); - } - errorCode=U_ILLEGAL_ARGUMENT_ERROR; - if( s.extract(NULL, 0, cnv, errorCode)==20 || U_SUCCESS(errorCode)) { - errln("UnicodeString::extract(UConverter) succeeded with a previous error code"); - } - errorCode=U_ZERO_ERROR; - - // extract for real - if( (length=s.extract(buffer, sizeof(buffer), cnv, errorCode))!=20 || - uprv_memcmp(buffer, expect, 20)!=0 || - buffer[20]!=0 || buffer[21]!=0 || buffer[22]!=0 || buffer[23]!=0 || - U_FAILURE(errorCode) - ) { - errln("UnicodeString::extract(UConverter) conversion failed (length=%ld, %s)", - length, u_errorName(errorCode)); - } - // Test again with just the converter name. - if( (length=s.extract(0, s.length(), buffer, sizeof(buffer), "UTF-32BE"))!=20 || - uprv_memcmp(buffer, expect, 20)!=0 || - buffer[20]!=0 || buffer[21]!=0 || buffer[22]!=0 || buffer[23]!=0 || - U_FAILURE(errorCode) - ) { - errln("UnicodeString::extract(\"UTF-32BE\") conversion failed (length=%ld, %s)", - length, u_errorName(errorCode)); - } - - // try the constructor - UnicodeString t((const char *)expect, sizeof(expect), cnv, errorCode); - if(U_FAILURE(errorCode) || s!=t) { - errln("UnicodeString(UConverter) conversion failed (%s)", - u_errorName(errorCode)); - } - - ucnv_close(cnv); - } - } } void diff --git a/icu4c/source/tools/toolutil/uparse.c b/icu4c/source/tools/toolutil/uparse.c index 1762fc448cf..ed2f1e90005 100644 --- a/icu4c/source/tools/toolutil/uparse.c +++ b/icu4c/source/tools/toolutil/uparse.c @@ -366,5 +366,5 @@ u_parseUTF8(const char *source, int32_t sLen, char *dest, int32_t destCapacity, i++; read += 2; } - return u_terminateChars(dest, destCapacity, i, 1, status); + return u_terminateChars(dest, destCapacity, i, status); }