ICU-516 streaming conversion functions set U_BUFFER_OVERFLOW_ERROR instead of U_INDEX_OUTOFBOUNDS_ERROR

X-SVN-Rev: 2200
This commit is contained in:
Markus Scherer 2000-08-11 19:39:34 +00:00
parent 17df34956e
commit 3508752164
3 changed files with 33 additions and 52 deletions

View file

@ -753,15 +753,10 @@ int32_t ucnv_fromUChars (const UConverter * converter,
/*Updates targetCapacity to contain the number of bytes written to target */
if (targetSize == 0)
{
*err = U_INDEX_OUTOFBOUNDS_ERROR;
}
/* If the output buffer is exhausted, we need to stop writing
* to it but continue the conversion in order to store in targetSize
* the number of bytes that was required*/
if (*err == U_INDEX_OUTOFBOUNDS_ERROR)
if (*err == U_BUFFER_OVERFLOW_ERROR || targetSize == 0)
{
char target2[CHUNK_SIZE];
const char *target2_limit = target2 + CHUNK_SIZE;
@ -769,20 +764,17 @@ int32_t ucnv_fromUChars (const UConverter * converter,
/*We use a stack allocated buffer around which we loop
*(in case the output is greater than CHUNK_SIZE)
*/
while (*err == U_INDEX_OUTOFBOUNDS_ERROR)
do
{
*err = U_ZERO_ERROR;
args.target = target2;
args.targetLimit = target2_limit;
args.converter->sharedData->impl->fromUnicode(&args, err);
/*updates the output parameter to contain the number of char required */
targetCapacity += (args.target - target2) + 1;
}
/*We will set the erro code to U_BUFFER_OVERFLOW_ERROR only if
targetCapacity += (args.target - target2);
} while (*err == U_BUFFER_OVERFLOW_ERROR);
/*We will set the error code to U_BUFFER_OVERFLOW_ERROR only if
*nothing graver happened in the previous loop*/
(targetCapacity)--;
if (U_SUCCESS (*err))
*err = U_BUFFER_OVERFLOW_ERROR;
}
@ -863,34 +855,29 @@ int32_t ucnv_toUChars (const UConverter * converter,
/*Updates targetCapacity to contain the number of bytes written to target */
targetCapacity = 1;
targetCapacity += args.target - target;
if (targetSize == 0)
{
*err = U_INDEX_OUTOFBOUNDS_ERROR;
}
/* If the output buffer is exhausted, we need to stop writing
* to it but if the input buffer is not exhausted,
* we need to continue the conversion in order to store in targetSize
* the number of bytes that was required
*/
if (*err == U_INDEX_OUTOFBOUNDS_ERROR)
if (*err == U_BUFFER_OVERFLOW_ERROR || targetSize == 0)
{
UChar target2[CHUNK_SIZE];
const UChar *target2_limit = target2 + CHUNK_SIZE;
/*We use a stack allocated buffer around which we loop
(in case the output is greater than CHUNK_SIZE) */
while (*err == U_INDEX_OUTOFBOUNDS_ERROR)
do
{
*err = U_ZERO_ERROR;
args.target = target2;
args.targetLimit = target2_limit;
args.converter->sharedData->impl->toUnicode(&args, err);
/*updates the output parameter to contain the number of char required */
targetCapacity += args.target - target2 + 1;
}
(targetCapacity)--; /*adjust for last one */
targetCapacity += args.target - target2;
} while (*err == U_BUFFER_OVERFLOW_ERROR);
if (U_SUCCESS (*err))
*err = U_BUFFER_OVERFLOW_ERROR;
}
@ -996,11 +983,10 @@ T_UConverter_fromCodepageToCodepage (UConverter * outConverter,
flush,
err);
/*U_INDEX_OUTOFBOUNDS_ERROR means that the output "CHUNK" is full
/*U_BUFFER_OVERFLOW_ERROR means that the output "CHUNK" is full
*we will require at least another loop (it's a recoverable error)
*/
if (U_SUCCESS (*err) || (*err == U_INDEX_OUTOFBOUNDS_ERROR))
if (U_SUCCESS (*err) || (*err == U_BUFFER_OVERFLOW_ERROR))
{
*err = U_ZERO_ERROR;
out_chunk_alias2 = out_chunk;
@ -1015,7 +1001,6 @@ T_UConverter_fromCodepageToCodepage (UConverter * outConverter,
NULL,
TRUE,
err);
}
}
else
@ -1080,20 +1065,14 @@ int32_t ucnv_convert(const char *toConverterName,
NULL,
TRUE,
err);
/*Updates targetCapacity to contain the number of bytes written to target */
targetCapacity = myTarget - target;
}
/*Updates targetCapacity to contain the number of bytes written to target */
targetCapacity = myTarget - target;
if (targetSize == 0)
{
*err = U_INDEX_OUTOFBOUNDS_ERROR;
}
/* If the output buffer is exhausted, we need to stop writing
/* If the output buffer is exhausted (or we are "pre-flighting"), we need to stop writing
* to it but continue the conversion in order to store in targetSize
* the number of bytes that was required*/
if (*err == U_INDEX_OUTOFBOUNDS_ERROR)
if (*err == U_BUFFER_OVERFLOW_ERROR || targetSize == 0)
{
char target2[CHUNK_SIZE];
char *target2_alias = target2;
@ -1103,7 +1082,7 @@ int32_t ucnv_convert(const char *toConverterName,
*(in case the output is greater than CHUNK_SIZE)
*/
while (*err == U_INDEX_OUTOFBOUNDS_ERROR)
do
{
*err = U_ZERO_ERROR;
target2_alias = target2;
@ -1118,11 +1097,11 @@ int32_t ucnv_convert(const char *toConverterName,
err);
/*updates the output parameter to contain the number of char required */
targetCapacity += (target2_alias - target2) + 1;
}
/*We will set the erro code to U_BUFFER_OVERFLOW_ERROR only if
targetCapacity += (target2_alias - target2);
} while (*err == U_BUFFER_OVERFLOW_ERROR);
/*We will set the error code to U_BUFFER_OVERFLOW_ERROR only if
*nothing graver happened in the previous loop*/
(targetCapacity)--;
if (U_SUCCESS (*err))
*err = U_BUFFER_OVERFLOW_ERROR;
}

View file

@ -324,6 +324,7 @@ void TestConvert()
}
/*Testing ucnv_convert()*/
do /* do {} while(0) allows to leave this block with a break */
{
int32_t targetLimit=0, sourceLimit=0, i=0, targetCapacity=0;
const uint8_t source[]={ 0x00, 0x04, 0x05, 0x06, 0xa2, 0xb4, 0x00};
@ -339,9 +340,10 @@ void TestConvert()
targetLimit=targetCapacity+1;
target=(char*)malloc(sizeof(char) * targetLimit);
targetCapacity=ucnv_convert("ibm-1364", "ibm-1363", target, targetLimit , source, sourceLimit, &err);
if(U_FAILURE(err)){
log_err("FAILURE! ucnv_convert(ibm-1363->ibm-1364) failed. %s\n", myErrorName(err));
}
}
if(U_FAILURE(err)){
log_err("FAILURE! ucnv_convert(ibm-1363->ibm-1364) failed. %s\n", myErrorName(err));
break;
}
for(i=0; i<targetCapacity; i++){
if(target[i] != expectedTarget[i]){
@ -372,7 +374,7 @@ void TestConvert()
err=U_ZERO_ERROR;
free(target);
ucnv_flushCache();
}
} while(0);
/*Testing ucnv_open()*/
/* Note: These converters have been chosen because they do NOT
@ -841,7 +843,7 @@ void TestConvert()
{
log_err("ERR: calling toUChars: Didn't get U_BUFFER_OVERFLOW .. expected it.\n");
}
/*Testing ucnv_fromUChars and ucnv_toUChars wwith error conditions*/
/*Testing ucnv_fromUChars and ucnv_toUChars with error conditions*/
err=U_ILLEGAL_ARGUMENT_ERROR;
log_verbose("\n---Testing ucnv_fromUChars() with err != U_ZERO_ERROR\n");
targetcapacity = ucnv_fromUChars(myConverter, output_cp_buffer, testLong1, uchar1, -1, &err);

View file

@ -531,7 +531,7 @@ myMultipassTest(const UChar *chars,
chars + len,
&status);
if(status != U_INDEX_OUTOFBOUNDS_ERROR && U_FAILURE(status)) {
if(status != U_BUFFER_OVERFLOW_ERROR && U_FAILURE(status)) {
log_err("Failing status code at line %d.\n", __LINE__);
return;
}
@ -549,7 +549,7 @@ myMultipassTest(const UChar *chars,
totalBytesWritten += (myCTarget - myCompressionBuffer);
} while(status == U_INDEX_OUTOFBOUNDS_ERROR/*totalCharsCompressed < len*/);
} while(status == U_BUFFER_OVERFLOW_ERROR/*totalCharsCompressed < len*/);
/* reset */
scsu_reset(&myCompressor);
@ -570,7 +570,7 @@ myMultipassTest(const UChar *chars,
myCompressed + totalBytesWritten,
&status);
if(status != U_INDEX_OUTOFBOUNDS_ERROR && U_FAILURE(status)) {
if(status != U_BUFFER_OVERFLOW_ERROR && U_FAILURE(status)) {
log_err("Failing status code at line %d.\n", __LINE__);
return;
}
@ -588,7 +588,7 @@ myMultipassTest(const UChar *chars,
totalCharsWritten += (myDTarget - myDecompressionBuffer);
} while(status == U_INDEX_OUTOFBOUNDS_ERROR/*totalBytesDecompressed < totalBytesWritten*/);
} while(status == U_BUFFER_OVERFLOW_ERROR/*totalBytesDecompressed < totalBytesWritten*/);
/* find differences */
if( printDiffs(chars, len, myDecompressed, totalCharsWritten) == FALSE) {