1999-12-09 23:27:55 +00:00
|
|
|
/**********************************************************************
|
2001-03-17 23:31:46 +00:00
|
|
|
* Copyright (C) 1999-2001, International Business Machines
|
1999-12-09 23:27:55 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-17 23:31:46 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/unistr.h"
|
|
|
|
#include "cpputils.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-03-17 23:31:46 +00:00
|
|
|
/** Simple utility to fill a UChar array from a UnicodeString */
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
uprv_fillOutputString(const UnicodeString &temp,
|
|
|
|
UChar *dest,
|
|
|
|
int32_t destCapacity,
|
|
|
|
UErrorCode *status) {
|
|
|
|
int32_t length = temp.length();
|
2000-03-29 01:13:49 +00:00
|
|
|
|
2001-03-17 23:31:46 +00:00
|
|
|
if (destCapacity > 0) {
|
2000-03-29 01:13:49 +00:00
|
|
|
// copy the contents; extract() will check if it needs to copy anything at all
|
2001-03-17 23:31:46 +00:00
|
|
|
temp.extract(0, destCapacity, dest, 0);
|
2000-03-29 01:13:49 +00:00
|
|
|
|
2001-03-17 23:31:46 +00:00
|
|
|
// zero-terminate the dest buffer if possible
|
|
|
|
if (length < destCapacity) {
|
|
|
|
dest[length] = 0;
|
2000-03-29 01:13:49 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-03-29 01:13:49 +00:00
|
|
|
|
|
|
|
// set the error code according to the necessary buffer length
|
2001-03-17 23:31:46 +00:00
|
|
|
if (length > destCapacity && U_SUCCESS(*status)) {
|
2000-03-29 01:13:49 +00:00
|
|
|
*status = U_BUFFER_OVERFLOW_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-17 23:31:46 +00:00
|
|
|
|
|
|
|
// return the full string length
|
|
|
|
return length;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|