]>
git.saurik.com Git - apple/icu.git/blob - icuSources/io/ufmt_cmn.h
2 ******************************************************************************
4 * Copyright (C) 1998-2011, 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"
24 #include "unicode/utf16.h"
26 #define UFMT_DEFAULT_BUFFER_SIZE 128
27 #define MAX_UCHAR_BUFFER_SIZE(buffer) (sizeof(buffer)/(U16_MAX_LENGTH*sizeof(UChar)))
28 #define MAX_UCHAR_BUFFER_NEEDED(strLen) ((strLen+1)*U16_MAX_LENGTH*sizeof(UChar))
31 * Enum representing the possible argument types for uprintf/uscanf
33 typedef enum ufmt_type_info
{
35 ufmt_simple_percent
, /* %% do nothing */
36 ufmt_count
, /* special flag for count */
38 ufmt_char
, /* int, cast to char */
39 ufmt_string
, /* char* */
40 ufmt_pointer
, /* void* */
41 ufmt_float
, /* float */
42 ufmt_double
, /* double */
43 ufmt_uchar
, /* int, cast to UChar */
44 ufmt_ustring
/* UChar* */
45 /*ufmt_wchar,*/ /* wchar_t */
46 /*ufmt_wstring,*/ /* wchar_t* */
47 /*ufmt_date,*/ /* Date */
52 * Union representing a uprintf/uscanf argument
54 typedef union ufmt_args
{
55 int64_t int64Value
; /* int, UChar */
56 float floatValue
; /* float */
57 double doubleValue
; /* double */
58 void *ptrValue
; /* any pointer - void*, char*, wchar_t*, UChar* */
59 /*wchar_t wcharValue;*/ /* wchar_t */ /* TODO: Should wchar_t be used? */
60 /*UDate dateValue;*/ /* Date */
64 * Macro for determining the minimum of two numbers.
67 * @return <TT>a</TT> if </TT>a < b</TT>, <TT>b</TT> otherwise
69 #define ufmt_min(a,b) ((a) < (b) ? (a) : (b))
72 * Convert a UChar in hex radix to an integer value.
73 * @param c The UChar to convert.
74 * @return The integer value of <TT>c</TT>.
77 ufmt_digitvalue(UChar c
);
80 * Determine if a UChar is a digit for a specified radix.
81 * @param c The UChar to check.
82 * @param radix The desired radix.
83 * @return TRUE if <TT>c</TT> is a digit in <TT>radix</TT>, FALSE otherwise.
90 * Convert an int64_t to a UChar* in a specified radix
91 * @param buffer The target buffer
92 * @param len On input, the size of <TT>buffer</TT>. On output,
93 * the number of UChars written to <TT>buffer</TT>.
94 * @param value The value to be converted
95 * @param radix The desired radix
96 * @param uselower TRUE means lower case will be used, FALSE means upper case
97 * @param minDigits The minimum number of digits for for the formatted number,
98 * which will be padded with zeroes. -1 means do not pad.
101 ufmt_64tou(UChar
*buffer
,
109 * It's like ufmt_64tou, but with a pointer.
110 * This functions avoids size constraints of 64-bit types.
111 * Pointers can be at 32-128 bits in size.
114 ufmt_ptou(UChar
*buffer
,
120 * Convert a UChar* in a specified radix to an int64_t.
121 * @param buffer The target buffer
122 * @param len On input, the size of <TT>buffer</TT>. On output,
123 * the number of UChars read from <TT>buffer</TT>.
124 * @param radix The desired radix
125 * @return The numeric value.
128 ufmt_uto64(const UChar
*buffer
,
133 * Convert a UChar* in a specified radix to a pointer,
134 * @param buffer The target buffer
135 * @param len On input, the size of <TT>buffer</TT>. On output,
136 * the number of UChars read from <TT>buffer</TT>.
137 * @param radix The desired radix
138 * @return The pointer value.
141 ufmt_utop(const UChar
*buffer
,
145 * Convert a string from the default codepage to Unicode.
146 * @param s The string to convert, in the default codepage.
147 * @param sSize The size of s to convert.
148 * @param target The buffer to convert to.
149 * @param tSize The size of target
150 * @return A pointer to a newly allocated converted version of s, or 0
154 ufmt_defaultCPToUnicode(const char *s
, int32_t sSize
,
155 UChar
*target
, int32_t tSize
);