ICU-1109 implement new NUL-termination semantics

X-SVN-Rev: 5696
This commit is contained in:
Markus Scherer 2001-09-05 23:39:38 +00:00
parent 06973e024e
commit 0844431640
7 changed files with 22 additions and 121 deletions

View File

@ -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(destIndex<destCapacity) {
dest[destIndex]=0;
} else if(destIndex>destCapacity) {
*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(destIndex<destCapacity) {
/* ### TODO: this one would make sense -- dest[destIndex++]=0; -- but the following is more compatible */
dest[destIndex]=0;
} else {
/* ### TODO: same as above -- ++destIndex; */
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
}
} else {
/* we may NUL-terminate if it fits as a convenience */
if(destIndex<destCapacity) {
dest[destIndex]=0;
} else if(destIndex>destCapacity) {
*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(destIndex<destCapacity) {
dest[destIndex]=0;
} else if(destIndex>destCapacity) {
*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(destIndex<destCapacity) {
/* ### TODO: this one would make sense -- dest[destIndex++]=0; -- but the following is more compatible */
dest[destIndex]=0;
} else {
/* ### TODO: same as above -- ++destIndex; */
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
}
} else {
/* we may NUL-terminate if it fits as a convenience */
if(destIndex<destCapacity) {
dest[destIndex]=0;
} else if(destIndex>destCapacity) {
*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(destIndex<destCapacity) {
dest[destIndex]=0;
} else if(destIndex>destCapacity) {
*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(destIndex<destCapacity) {
/* ### TODO: this one would make sense -- dest[destIndex++]=0; -- but the following is more compatible */
dest[destIndex]=0;
} else {
/* ### TODO: same as above -- ++destIndex; */
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
}
} else {
/* we may NUL-terminate if it fits as a convenience */
if(destIndex<destCapacity) {
dest[destIndex]=0;
} else if(destIndex>destCapacity) {
*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(srcLength<destCapacity) {
dest[srcLength]=0;
} else if(srcLength>destCapacity) {
*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;

View File

@ -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

View File

@ -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*

View File

@ -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);
}
}

View File

@ -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

View File

@ -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

View File

@ -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;
}