home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / samples / cal / uprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  2.2 KB  |  80 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998, 1999     *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. *
  12. * File date.c
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *   06/14/99    stephen     Creation.
  18. *******************************************************************************
  19. */
  20.  
  21. #include "uprint.h"
  22. #include "ucnv.h"
  23.  
  24. #define BUF_SIZE 128
  25.  
  26. /* Print a ustring to the specified FILE* in the default codepage */
  27. void
  28. uprint(const UChar *s,
  29.        FILE *f,
  30.        UErrorCode *status)
  31. {
  32.   /* converter */
  33.   UConverter *converter;
  34.   char buf [BUF_SIZE];
  35.   int32_t sourceLen;
  36.   const UChar *mySource;
  37.   const UChar *mySourceEnd;
  38.   char *myTarget;
  39.   int32_t arraySize;
  40.  
  41.   if(s == 0) return;
  42.  
  43.   /* set up the conversion parameters */
  44.   sourceLen    = u_strlen(s);
  45.   mySource     = s;
  46.   mySourceEnd  = mySource + sourceLen;
  47.   myTarget     = buf;
  48.   arraySize    = BUF_SIZE;
  49.  
  50.   /* open a default converter */
  51.   converter = ucnv_open(0, status);
  52.   
  53.   /* if we failed, clean up and exit */
  54.   if(U_FAILURE(*status)) goto finish;
  55.   
  56.   /* perform the conversion */
  57.   do {
  58.     /* reset the error code */
  59.     *status = U_ZERO_ERROR;
  60.  
  61.     /* perform the conversion */
  62.     ucnv_fromUnicode(converter, &myTarget,  myTarget + arraySize,
  63.              &mySource, mySourceEnd, NULL,
  64.              TRUE, status);
  65.  
  66.     /* Write the converted data to the FILE* */
  67.     fwrite(buf, sizeof(char), myTarget - buf, f);
  68.  
  69.     /* update the conversion parameters*/
  70.     myTarget     = buf;
  71.     arraySize    = BUF_SIZE;
  72.   }
  73.   while(*status == U_INDEX_OUTOFBOUNDS_ERROR); 
  74.  
  75.  finish:
  76.   
  77.   /* close the converter */
  78.   ucnv_close(converter);
  79. }
  80.