**********************************************************************
* Copyright (C) 1998-2009, International Business Machines Corporation
* and others. All Rights Reserved.
**********************************************************************
*
* File uprint.cpp
*
* Modification History:
*
* Date Name Description
* 06/14/99 stephen Creation.
*******************************************************************************
*/
#include "uprint.h"
#include "unicode/ucnv.h"
#include "unicode/ustring.h"
#define BUF_SIZE 128
U_CAPI void
uprint(const char16_t *s,
FILE *f,
UErrorCode *status)
{
UConverter *converter;
char buf [BUF_SIZE];
int32_t sourceLen;
const char16_t *mySource;
const char16_t *mySourceEnd;
char *myTarget;
int32_t arraySize;
if(s == 0) return;
sourceLen = u_strlen(s);
mySource = s;
mySourceEnd = mySource + sourceLen;
myTarget = buf;
arraySize = BUF_SIZE;
converter = ucnv_open(0, status);
if(U_FAILURE(*status)) goto finish;
do {
*status = U_ZERO_ERROR;
ucnv_fromUnicode(converter, &myTarget, myTarget + arraySize,
&mySource, mySourceEnd, nullptr,
true, status);
fwrite(buf, sizeof(char), myTarget - buf, f);
myTarget = buf;
arraySize = BUF_SIZE;
}
while(*status == U_BUFFER_OVERFLOW_ERROR);
finish:
ucnv_close(converter);
}