From 0844431640b6fff2167044ecbf7b26e079f1cbc5 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Wed, 5 Sep 2001 23:39:38 +0000 Subject: [PATCH] ICU-1109 implement new NUL-termination semantics X-SVN-Rev: 5696 --- icu4c/source/common/unorm.cpp | 107 ++-------------------------------- icu4c/source/i18n/ucal.cpp | 2 +- icu4c/source/i18n/ucol.cpp | 2 +- icu4c/source/i18n/udat.cpp | 18 +++--- icu4c/source/i18n/umsg.cpp | 2 +- icu4c/source/i18n/unum.cpp | 8 +-- icu4c/source/i18n/utrans.cpp | 4 +- 7 files changed, 22 insertions(+), 121 deletions(-) diff --git a/icu4c/source/common/unorm.cpp b/icu4c/source/common/unorm.cpp index cc11327d094..3e581099d11 100644 --- a/icu4c/source/common/unorm.cpp +++ b/icu4c/source/common/unorm.cpp @@ -1049,36 +1049,7 @@ unorm_decompose(UChar *dest, int32_t destCapacity, trailCC, pErrorCode); -#if 1 - /* ### TODO: this passes the tests but seems weird */ - /* we may NUL-terminate if it fits as a convenience */ - if(destIndexdestCapacity) { - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - } -#else - /* ### TODO: this looks slightly to much more reasonable but fails some tests, esp. /tscoll/cmsccoll/TestIncrementalNormalize */ - if(limit==NULL) { - /* assume that we must NUL-terminate */ - if(destIndexdestCapacity) { - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - } - } -#endif - - return destIndex; + return u_terminateUChars(dest, destCapacity, destIndex, pErrorCode); } /* make FCD ----------------------------------------------------------------- */ @@ -1414,36 +1385,7 @@ unorm_makeFCD(UChar *dest, int32_t destCapacity, } } -#if 1 - /* ### TODO: this passes the tests but seems weird */ - /* we may NUL-terminate if it fits as a convenience */ - if(destIndexdestCapacity) { - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - } -#else - /* ### TODO: this looks slightly to much more reasonable but fails some tests, esp. /tscoll/cmsccoll/TestIncrementalNormalize */ - if(limit==NULL) { - /* assume that we must NUL-terminate */ - if(destIndexdestCapacity) { - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - } - } -#endif - - return destIndex; + return u_terminateUChars(dest, destCapacity, destIndex, pErrorCode); } /* make NFC & NFKC ---------------------------------------------------------- */ @@ -2170,40 +2112,7 @@ unorm_compose(UChar *dest, int32_t destCapacity, } } -#if 1 - /* ### TODO: this passes the tests but seems weird */ - /* we may NUL-terminate if it fits as a convenience */ - if(destIndexdestCapacity) { - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - } -#else - /* ### TODO: this looks slightly to much more reasonable but fails some tests, esp. /tscoll/cmsccoll/TestIncrementalNormalize */ - if(limit==NULL) { - /* assume that we must NUL-terminate */ - if(destIndexdestCapacity) { - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - } - } -#endif - - if(buffer!=stackBuffer) { - uprv_free(buffer); - } - - return destIndex; + return u_terminateUChars(dest, destCapacity, destIndex, pErrorCode); } /* @@ -2266,16 +2175,8 @@ unorm_internalNormalize(UChar *dest, int32_t destCapacity, (growBuffer!=NULL && growBuffer(context, &dest, &destCapacity, srcLength+1, 0)) ) { uprv_memcpy(dest, src, srcLength*U_SIZEOF_UCHAR); - /* ### TODO: revise NUL-termination parallel to rest of API */ - /* we may NUL-terminate if it fits as a convenience */ - if(srcLengthdestCapacity) { - *pErrorCode=U_BUFFER_OVERFLOW_ERROR; - } } - /* ### TODO: revise NUL-termination parallel to rest of API */ - return srcLength; + return u_terminateUChars(dest, destCapacity, srcLength, pErrorCode); default: *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; return 0; diff --git a/icu4c/source/i18n/ucal.cpp b/icu4c/source/i18n/ucal.cpp index da2bb6a1419..9fd89e4b263 100644 --- a/icu4c/source/i18n/ucal.cpp +++ b/icu4c/source/i18n/ucal.cpp @@ -153,7 +153,7 @@ ucal_getTimeZoneDisplayName(const UCalendar* cal, break; } - return uprv_fillOutputString(id, result, resultLength, status); + return id.extract(result, resultLength, *status); } U_CAPI UBool diff --git a/icu4c/source/i18n/ucol.cpp b/icu4c/source/i18n/ucol.cpp index 99c05a1c55c..06792c85aec 100644 --- a/icu4c/source/i18n/ucol.cpp +++ b/icu4c/source/i18n/ucol.cpp @@ -4337,7 +4337,7 @@ ucol_getDisplayName( const char *objLoc, if(U_FAILURE(*status)) return -1; UnicodeString dst(result, resultLength, resultLength); Collator::getDisplayName(Locale(objLoc), Locale(dispLoc), dst); - return uprv_fillOutputString(dst, result, resultLength, status); + return dst.extract(result, resultLength, *status); } U_CAPI const char* diff --git a/icu4c/source/i18n/udat.cpp b/icu4c/source/i18n/udat.cpp index 22ef2be657e..a039a4222e6 100644 --- a/icu4c/source/i18n/udat.cpp +++ b/icu4c/source/i18n/udat.cpp @@ -201,7 +201,7 @@ udat_format( const UDateFormat* format, position->endIndex = fp.getEndIndex(); } - return uprv_fillOutputString(res, result, resultLength, status); + return res.extract(result, resultLength, *status); } U_CAPI UDate @@ -319,7 +319,7 @@ udat_toPattern( const UDateFormat *fmt, else ((SimpleDateFormat*)fmt)->toPattern(res); - return uprv_fillOutputString(res, result, resultLength, status); + return res.extract(result, resultLength, *status); } // TBD: should this take an UErrorCode? @@ -358,42 +358,42 @@ udat_getSymbols(const UDateFormat *fmt, case UDAT_ERAS: res = syms->getEras(count); if(index < count) { - return uprv_fillOutputString(res[index], result, resultLength, status); + return res[index].extract(result, resultLength, *status); } break; case UDAT_MONTHS: res = syms->getMonths(count); if(index < count) { - return uprv_fillOutputString(res[index], result, resultLength, status); + return res[index].extract(result, resultLength, *status); } break; case UDAT_SHORT_MONTHS: res = syms->getShortMonths(count); if(index < count) { - return uprv_fillOutputString(res[index], result, resultLength, status); + return res[index].extract(result, resultLength, *status); } break; case UDAT_WEEKDAYS: res = syms->getWeekdays(count); if(index < count) { - return uprv_fillOutputString(res[index], result, resultLength, status); + return res[index].extract(result, resultLength, *status); } break; case UDAT_SHORT_WEEKDAYS: res = syms->getShortWeekdays(count); if(index < count) { - return uprv_fillOutputString(res[index], result, resultLength, status); + return res[index].extract(result, resultLength, *status); } break; case UDAT_AM_PMS: res = syms->getAmPmStrings(count); if(index < count) { - return uprv_fillOutputString(res[index], result, resultLength, status); + return res[index].extract(result, resultLength, *status); } break; @@ -401,7 +401,7 @@ udat_getSymbols(const UDateFormat *fmt, { UnicodeString res1(result, 0, resultLength); syms->getLocalPatternChars(res1); - return uprv_fillOutputString(res1, result, resultLength, status); + return res1.extract(result, resultLength, *status); } } diff --git a/icu4c/source/i18n/umsg.cpp b/icu4c/source/i18n/umsg.cpp index 64db0cbc817..81fcd914f1e 100644 --- a/icu4c/source/i18n/umsg.cpp +++ b/icu4c/source/i18n/umsg.cpp @@ -726,7 +726,7 @@ umsg_toPattern(UMessageFormat *fmt, UnicodeString res(result, 0, resultLength); ((MessageFormat*)fmt)->toPattern(res); - return uprv_fillOutputString(res, result, resultLength, status); + return res.extract(result, resultLength, *status); } U_CAPI int32_t diff --git a/icu4c/source/i18n/unum.cpp b/icu4c/source/i18n/unum.cpp index 8f733d6a56d..6ce382fe752 100644 --- a/icu4c/source/i18n/unum.cpp +++ b/icu4c/source/i18n/unum.cpp @@ -222,7 +222,7 @@ unum_format( const UNumberFormat* fmt, pos->endIndex = fp.getEndIndex(); } - return uprv_fillOutputString(res, result, resultLength, status); + return res.extract(result, resultLength, *status); } U_CAPI int32_t @@ -248,7 +248,7 @@ unum_formatDouble( const UNumberFormat* fmt, pos->endIndex = fp.getEndIndex(); } - return uprv_fillOutputString(res, result, resultLength, status); + return res.extract(result, resultLength, *status); } U_CAPI int32_t @@ -522,7 +522,7 @@ unum_getTextAttribute(const UNumberFormat* fmt, return -1; } - return uprv_fillOutputString(res, result, resultLength, status); + return res.extract(result, resultLength, *status); } U_CAPI void @@ -580,7 +580,7 @@ unum_toPattern( const UNumberFormat* fmt, else ((DecimalFormat*)fmt)->toPattern(pat); - return uprv_fillOutputString(pat, result, resultLength, status); + return pat.extract(result, resultLength, *status); } U_CAPI void diff --git a/icu4c/source/i18n/utrans.cpp b/icu4c/source/i18n/utrans.cpp index a7be153946f..0c98678ea30 100644 --- a/icu4c/source/i18n/utrans.cpp +++ b/icu4c/source/i18n/utrans.cpp @@ -404,7 +404,7 @@ utrans_transUChars(const UTransliterator* trans, // Copy the string buffer back to text (only if necessary) // and fill in *neededCapacity (if neededCapacity != NULL). - textLen = uprv_fillOutputString(str, text, textCapacity, status); + textLen = str.extract(text, textCapacity, *status); if(textLength != NULL) { *textLength = textLen; } @@ -434,7 +434,7 @@ utrans_transIncrementalUChars(const UTransliterator* trans, // Copy the string buffer back to text (only if necessary) // and fill in *neededCapacity (if neededCapacity != NULL). - textLen = uprv_fillOutputString(str, text, textCapacity, status); + textLen = str.extract(text, textCapacity, *status); if(textLength != NULL) { *textLength = textLen; }