1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2000-01-15 02:00:06 +00:00
|
|
|
**********************************************************************
|
2001-03-21 20:46:06 +00:00
|
|
|
* Copyright (C) 1998-2001, International Business Machines Corporation
|
2000-01-15 02:00:06 +00:00
|
|
|
* and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File date.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
2002-04-02 02:55:31 +00:00
|
|
|
* Date Name Description
|
|
|
|
* 06/14/99 stephen Creation.
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uprint.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ucnv.h"
|
1999-12-30 03:07:17 +00:00
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#define BUF_SIZE 128
|
|
|
|
|
|
|
|
/* Print a ustring to the specified FILE* in the default codepage */
|
|
|
|
void
|
|
|
|
uprint(const UChar *s,
|
2002-04-02 02:55:31 +00:00
|
|
|
FILE *f,
|
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
/* converter */
|
|
|
|
UConverter *converter;
|
|
|
|
char buf [BUF_SIZE];
|
|
|
|
int32_t sourceLen;
|
|
|
|
const UChar *mySource;
|
|
|
|
const UChar *mySourceEnd;
|
|
|
|
char *myTarget;
|
|
|
|
int32_t arraySize;
|
|
|
|
|
|
|
|
if(s == 0) return;
|
|
|
|
|
|
|
|
/* set up the conversion parameters */
|
|
|
|
sourceLen = u_strlen(s);
|
2002-04-02 02:55:31 +00:00
|
|
|
mySource = s;
|
1999-08-16 21:50:52 +00:00
|
|
|
mySourceEnd = mySource + sourceLen;
|
2002-04-02 02:55:31 +00:00
|
|
|
myTarget = buf;
|
1999-08-16 21:50:52 +00:00
|
|
|
arraySize = BUF_SIZE;
|
|
|
|
|
|
|
|
/* open a default converter */
|
|
|
|
converter = ucnv_open(0, status);
|
|
|
|
|
|
|
|
/* if we failed, clean up and exit */
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(*status)) goto finish;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* perform the conversion */
|
|
|
|
do {
|
2002-04-02 02:55:31 +00:00
|
|
|
/* reset the error code */
|
|
|
|
*status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
/* perform the conversion */
|
|
|
|
ucnv_fromUnicode(converter, &myTarget, myTarget + arraySize,
|
|
|
|
&mySource, mySourceEnd, NULL,
|
|
|
|
TRUE, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
/* Write the converted data to the FILE* */
|
|
|
|
fwrite(buf, sizeof(char), myTarget - buf, f);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
/* update the conversion parameters*/
|
|
|
|
myTarget = buf;
|
|
|
|
arraySize = BUF_SIZE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-08-11 20:11:06 +00:00
|
|
|
while(*status == U_BUFFER_OVERFLOW_ERROR);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
finish:
|
|
|
|
|
|
|
|
/* close the converter */
|
|
|
|
ucnv_close(converter);
|
|
|
|
}
|