ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
***********************************************************************
* © 2016 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html#License
***********************************************************************
**********************************************************************
* Copyright (C) 1998-2001, International Business Machines Corporation
* and others.  All Rights Reserved.
**********************************************************************
*
* File date.c
*
* 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
 
/* Print a ustring to the specified FILE* in the default codepage */
void
uprint(const UChar *s,
      FILE *f,
      UErrorCode *status)
{
  /* 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);
  mySource       = s;
  mySourceEnd  = mySource + sourceLen;
  myTarget       = buf;
  arraySize    = BUF_SIZE;
 
  /* open a default converter */
  converter = ucnv_open(0, status);
  
  /* if we failed, clean up and exit */
  if(U_FAILURE(*status)) goto finish;
  
  /* perform the conversion */
  do {
   /* reset the error code */
   *status = U_ZERO_ERROR;
 
   /* perform the conversion */
   ucnv_fromUnicode(converter, &myTarget,    myTarget + arraySize,
            &mySource, mySourceEnd, NULL,
            TRUE, status);
 
   /* Write the converted data to the FILE* */
   fwrite(buf, sizeof(char), myTarget - buf, f);
 
   /* update the conversion parameters*/
   myTarget     = buf;
   arraySize     = BUF_SIZE;
  }
  while(*status == U_BUFFER_OVERFLOW_ERROR); 
 
 finish:
  
  /* close the converter */
  ucnv_close(converter);
}