1999-08-16 21:50:52 +00:00
|
|
|
#define EXTENDED_FUNCTIONALITY
|
|
|
|
#include "cpputils.h"
|
|
|
|
#include "cstring.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-09 23:27:55 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Copyright (C) 1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* Simple utility to set output buffer parameters
|
|
|
|
******************************************************/
|
|
|
|
void T_fillOutputParams(const UnicodeString* temp,
|
2000-03-29 01:13:49 +00:00
|
|
|
UChar* result,
|
|
|
|
const int32_t resultLength,
|
|
|
|
int32_t* resultLengthOut,
|
|
|
|
UErrorCode* status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-03-29 01:13:49 +00:00
|
|
|
int32_t actual = temp->length();
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if (resultLength > 0) {
|
2000-03-29 01:13:49 +00:00
|
|
|
// copy the contents; extract() will check if it needs to copy anything at all
|
|
|
|
temp->extract(0, resultLength - 1, result, 0);
|
|
|
|
|
|
|
|
// zero-terminate the result buffer
|
|
|
|
if (actual < resultLength) {
|
|
|
|
result[actual] = 0;
|
|
|
|
} else {
|
|
|
|
result[resultLength - 1] = 0;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-03-29 01:13:49 +00:00
|
|
|
|
|
|
|
// set the output length to the actual string length
|
|
|
|
if (resultLengthOut != 0) {
|
1999-08-16 21:50:52 +00:00
|
|
|
*resultLengthOut = actual;
|
2000-03-29 01:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set the error code according to the necessary buffer length
|
|
|
|
if (actual >= resultLength && U_SUCCESS(*status)) {
|
|
|
|
*status = U_BUFFER_OVERFLOW_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|