]>
git.saurik.com Git - apple/icu.git/blob - icuSources/io/ufmt_cmn.h
2 ******************************************************************************
4 * Copyright (C) 1998-2004, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 12/02/98 stephen Creation.
15 * 03/12/99 stephen Modified for new C API.
16 * 03/15/99 stephen Added defaultCPToUnicode, unicodeToDefaultCP
17 ******************************************************************************
23 #include "unicode/utypes.h"
25 #define UFMT_DEFAULT_BUFFER_SIZE 128
26 #define MAX_UCHAR_BUFFER_SIZE(buffer) (sizeof(buffer)/(UTF_MAX_CHAR_LENGTH*sizeof(UChar)))
27 #define MAX_UCHAR_BUFFER_NEEDED(strLen) ((strLen+1)*UTF_MAX_CHAR_LENGTH*sizeof(UChar))
30 * Enum representing the possible argument types for uprintf/uscanf
32 typedef enum ufmt_type_info
{
34 ufmt_simple_percent
, /* %% do nothing */
35 ufmt_count
, /* special flag for count */
37 ufmt_char
, /* int, cast to char */
38 ufmt_string
, /* char* */
39 ufmt_pointer
, /* void* */
40 ufmt_float
, /* float */
41 ufmt_double
, /* double */
42 ufmt_uchar
, /* int, cast to UChar */
43 ufmt_ustring
/* UChar* */
44 /*ufmt_wchar,*/ /* wchar_t */
45 /*ufmt_wstring,*/ /* wchar_t* */
46 /*ufmt_date,*/ /* Date */
51 * Union representing a uprintf/uscanf argument
53 typedef union ufmt_args
{
54 int64_t int64Value
; /* int, UChar */
55 float floatValue
; /* float */
56 double doubleValue
; /* double */
57 void *ptrValue
; /* any pointer - void*, char*, wchar_t*, UChar* */
58 /*wchar_t wcharValue;*/ /* wchar_t */ /* TODO: Should wchar_t be used? */
59 /*UDate dateValue;*/ /* Date */
63 * Macro for determining the minimum of two numbers.
66 * @return <TT>a</TT> if </TT>a < b</TT>, <TT>b</TT> otherwise
68 #define ufmt_min(a,b) ((a) < (b) ? (a) : (b))
71 * Convert a UChar in hex radix to an integer value.
72 * @param c The UChar to convert.
73 * @return The integer value of <TT>c</TT>.
76 ufmt_digitvalue(UChar c
);
79 * Determine if a UChar is a digit for a specified radix.
80 * @param c The UChar to check.
81 * @param radix The desired radix.
82 * @return TRUE if <TT>c</TT> is a digit in <TT>radix</TT>, FALSE otherwise.
89 * Convert an int64_t to a UChar* in a specified radix
90 * @param buffer The target buffer
91 * @param len On input, the size of <TT>buffer</TT>. On output,
92 * the number of UChars written to <TT>buffer</TT>.
93 * @param value The value to be converted
94 * @param radix The desired radix
95 * @param uselower TRUE means lower case will be used, FALSE means upper case
96 * @param minDigits The minimum number of digits for for the formatted number,
97 * which will be padded with zeroes. -1 means do not pad.
100 ufmt_64tou(UChar
*buffer
,
108 * It's like ufmt_64tou, but with a pointer.
109 * This functions avoids size constraints of 64-bit types.
110 * Pointers can be at 32-128 bits in size.
113 ufmt_ptou(UChar
*buffer
,
119 * Convert a UChar* in a specified radix to an int64_t.
120 * @param buffer The target buffer
121 * @param len On input, the size of <TT>buffer</TT>. On output,
122 * the number of UChars read from <TT>buffer</TT>.
123 * @param radix The desired radix
124 * @return The numeric value.
127 ufmt_uto64(const UChar
*buffer
,
132 * Convert a UChar* in a specified radix to a pointer,
133 * @param buffer The target buffer
134 * @param len On input, the size of <TT>buffer</TT>. On output,
135 * the number of UChars read from <TT>buffer</TT>.
136 * @param radix The desired radix
137 * @return The pointer value.
140 ufmt_utop(const UChar
*buffer
,
144 * Convert a string from the default codepage to Unicode.
145 * @param s The string to convert, in the default codepage.
146 * @param sSize The size of s to convert.
147 * @param target The buffer to convert to.
148 * @param tSize The size of target
149 * @return A pointer to a newly allocated converted version of s, or 0
153 ufmt_defaultCPToUnicode(const char *s
, int32_t sSize
,
154 UChar
*target
, int32_t tSize
);