home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / extra / ustdio / ufmt_cmn.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  4.6 KB  |  158 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998           *
  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 ufmt_cmn.h
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *   12/02/98    stephen        Creation.
  18. *   03/12/99    stephen     Modified for new C API.
  19. *   03/15/99    stephen     Added defaultCPToUnicode, unicodeToDefaultCP
  20. *******************************************************************************
  21. */
  22.  
  23. #ifndef UFMT_CMN_H
  24. #define UFMT_CMN_H
  25.  
  26. #include "utypes.h"
  27.  
  28. /** 
  29.  * Enum representing the possible argument types for uprintf/uscanf
  30.  */
  31. enum
  32. {
  33.   ufmt_count,      /* special flag for count */
  34.   ufmt_int,        /* int */
  35.   ufmt_char,       /* int, cast to char */
  36.   ufmt_wchar,      /* wchar_t */
  37.   ufmt_string,     /* char* */
  38.   ufmt_wstring,    /* wchar_t* */
  39.   ufmt_pointer,    /* void* */
  40.   ufmt_float,      /* float */
  41.   ufmt_double,     /* double */
  42.   ufmt_date,       /* Date */
  43.   ufmt_uchar,      /* int, cast to UChar */
  44.   ufmt_ustring,    /* UChar* */
  45.   ufmt_last
  46. };
  47.  
  48. /**
  49.  * Union representing a uprintf/uscanf argument
  50.  */
  51. union ufmt_args {
  52.   int     intValue;      /* int, UChar */
  53.   float   floatValue;    /* float */
  54.   double  doubleValue;   /* double */
  55.   void    *ptrValue;     /* any pointer - void*, char*, wchar_t*, UChar* */
  56.   wchar_t wcharValue;    /* wchar_t */
  57.   UDate   dateValue;     /* Date */
  58. };
  59. typedef union ufmt_args ufmt_args;
  60.  
  61. /**
  62.  * Macro for determining the minimum of two numbers.
  63.  * @param a An integer
  64.  * @param b An integer
  65.  * @return <TT>a</TT> if </TT>a < b</TT>, <TT>b</TT> otherwise
  66.  */
  67. #define ufmt_min(a,b) (a) < (b) ? (a) : (b)
  68.  
  69. /**
  70.  * Convert a UChar in a some radix to an integer value.
  71.  * @param c The UChar to convert.
  72.  * @return The integer value of <TT>c</TT>.
  73.  */
  74. int
  75. ufmt_digitvalue(UChar c);
  76.  
  77. /**
  78.  * Determine if a UChar is a digit for a specified radix.
  79.  * @param c The UChar to check.
  80.  * @param radix The desired radix.
  81.  * @return TRUE if <TT>c</TT> is a digit in <TT>radix</TT>, FALSE otherwise.
  82.  */
  83. bool_t
  84. ufmt_isdigit(UChar     c,
  85.          int32_t     radix);
  86.  
  87. /**
  88.  * Convert a long to a UChar* in a specified radix
  89.  * @param buffer The target buffer
  90.  * @param len On input, the size of <TT>buffer</TT>.  On output,
  91.  * the number of UChars written to <TT>buffer</TT>.
  92.  * @param value The value to be converted
  93.  * @param radix The desired radix
  94.  * @param uselower TRUE means lower case will be used, FALSE means upper case
  95.  * @param minDigits The minimum number of digits for for the formatted number,
  96.  * which will be padded with zeroes. -1 means do not pad.
  97.  */
  98. void 
  99. ufmt_ltou(UChar     *buffer, 
  100.       int32_t     *len,
  101.       long         value, 
  102.       int32_t     radix,
  103.       bool_t    uselower,
  104.       int32_t    minDigits);
  105.  
  106. /**
  107.  * Convert a UChar* in a specified radix to a long.
  108.  * @param buffer The target buffer
  109.  * @param len On input, the size of <TT>buffer</TT>.  On output,
  110.  * the number of UChars read from <TT>buffer</TT>.
  111.  * @param radix The desired radix
  112.  * @return The numeric value.
  113.  */
  114. long
  115. ufmt_utol(const UChar     *buffer, 
  116.       int32_t     *len,
  117.       int32_t     radix);
  118.  
  119. /**
  120.  * Determine if a UChar is a whitespace character.
  121.  * @param c The UChar to test.
  122.  * @return TRUE if the UChar is a space (U+0020), tab (U+0009), 
  123.  * carriage-return (U+000D), newline (U+000A), vertical-tab (U+000B),
  124.  * form-feed (U+000C), or any other Unicode-defined space, line, or paragraph
  125.  * separator.
  126.  */
  127. bool_t
  128. ufmt_isws(UChar c);
  129.  
  130. /**
  131.  * Convert a string from the default codepage to Unicode.
  132.  * @param s The string to convert, in the default codepage.
  133.  * @param len The number of characters in s.
  134.  * @return A pointer to a newly allocated converted version of s, or 0 
  135.  * on error.
  136.  */
  137. UChar*
  138. ufmt_defaultCPToUnicode(const char *s,
  139.             int32_t len);
  140.  
  141.  
  142. /**
  143.  * Convert a string from the Unicode to the default codepage.
  144.  * @param s The string to convert.
  145.  * @param len The number of characters in s.
  146.  * @return A pointer to a newly allocated converted version of s, or 0 
  147.  * on error.
  148.  */
  149. char*
  150. ufmt_unicodeToDefaultCP(const UChar *s,
  151.             int32_t len);
  152.  
  153. #endif
  154.  
  155.  
  156.  
  157.  
  158.