scuffed-code/icu4c/source/common/cpputils.cpp
Markus Scherer 07a2bc0937 ICU-6 more renaming of constant names
FAILURE -> U_FAILURE etc.

X-SVN-Rev: 76
1999-10-18 22:48:32 +00:00

35 lines
968 B
C++

#define EXTENDED_FUNCTIONALITY
#include "cpputils.h"
#include "cstring.h"
#include "ustring.h"
/******************************************************
* Simple utility to set output buffer parameters
******************************************************/
void T_fillOutputParams(const UnicodeString* temp,
UChar* result,
const int32_t resultLength,
int32_t* resultLengthOut,
UErrorCode* status)
{
const int32_t actual = temp->size();
const bool_t overflowed = actual >= resultLength;
const int32_t returnedSize = icu_min(actual, resultLength-1);
if ((temp->size() < resultLength) && (result != temp->getUChars()) && (returnedSize > 0)) {
u_strcpy(result, temp->getUChars());
}
if (resultLength > 0) {
result[returnedSize] = 0;
}
if (resultLengthOut) {
*resultLengthOut = actual;
if (U_SUCCESS(*status) && overflowed) {
*status = U_BUFFER_OVERFLOW_ERROR;
}
}
}