]> git.saurik.com Git - apple/icu.git/blame - icuSources/samples/cal/uprint.c
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / samples / cal / uprint.c
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
3* Copyright (C) 1998-2001, International Business Machines Corporation
4* and others. All Rights Reserved.
5**********************************************************************
6*
7* File date.c
8*
9* Modification History:
10*
11* Date Name Description
12* 06/14/99 stephen Creation.
13*******************************************************************************
14*/
15
16#include "uprint.h"
17#include "unicode/ucnv.h"
18#include "unicode/ustring.h"
19
20#define BUF_SIZE 128
21
22/* Print a ustring to the specified FILE* in the default codepage */
23void
24uprint(const UChar *s,
25 FILE *f,
26 UErrorCode *status)
27{
28 /* converter */
29 UConverter *converter;
30 char buf [BUF_SIZE];
31 int32_t sourceLen;
32 const UChar *mySource;
33 const UChar *mySourceEnd;
34 char *myTarget;
35 int32_t arraySize;
36
37 if(s == 0) return;
38
39 /* set up the conversion parameters */
40 sourceLen = u_strlen(s);
41 mySource = s;
42 mySourceEnd = mySource + sourceLen;
43 myTarget = buf;
44 arraySize = BUF_SIZE;
45
46 /* open a default converter */
47 converter = ucnv_open(0, status);
48
49 /* if we failed, clean up and exit */
50 if(U_FAILURE(*status)) goto finish;
51
52 /* perform the conversion */
53 do {
54 /* reset the error code */
55 *status = U_ZERO_ERROR;
56
57 /* perform the conversion */
58 ucnv_fromUnicode(converter, &myTarget, myTarget + arraySize,
59 &mySource, mySourceEnd, NULL,
60 TRUE, status);
61
62 /* Write the converted data to the FILE* */
63 fwrite(buf, sizeof(char), myTarget - buf, f);
64
65 /* update the conversion parameters*/
66 myTarget = buf;
67 arraySize = BUF_SIZE;
68 }
69 while(*status == U_BUFFER_OVERFLOW_ERROR);
70
71 finish:
72
73 /* close the converter */
74 ucnv_close(converter);
75}