]>
git.saurik.com Git - apple/icu.git/blob - icuSources/io/ufmt_cmn.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 1998-2011, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
13 * Modification History:
15 * Date Name Description
16 * 12/02/98 stephen Creation.
17 * 03/12/99 stephen Modified for new C API.
18 * 03/15/99 stephen Added defaultCPToUnicode, unicodeToDefaultCP
19 ******************************************************************************
25 #include "unicode/utypes.h"
26 #include "unicode/utf16.h"
28 #define UFMT_DEFAULT_BUFFER_SIZE 128
29 #define MAX_UCHAR_BUFFER_SIZE(buffer) ((int32_t)(sizeof(buffer)/(U16_MAX_LENGTH*sizeof(UChar))))
30 #define MAX_UCHAR_BUFFER_NEEDED(strLen) ((strLen+1)*U16_MAX_LENGTH*sizeof(UChar))
33 * Enum representing the possible argument types for uprintf/uscanf
35 typedef enum ufmt_type_info
{
37 ufmt_simple_percent
, /* %% do nothing */
38 ufmt_count
, /* special flag for count */
40 ufmt_char
, /* int, cast to char */
41 ufmt_string
, /* char* */
42 ufmt_pointer
, /* void* */
43 ufmt_float
, /* float */
44 ufmt_double
, /* double */
45 ufmt_uchar
, /* int, cast to UChar */
46 ufmt_ustring
/* UChar* */
47 /*ufmt_wchar,*/ /* wchar_t */
48 /*ufmt_wstring,*/ /* wchar_t* */
49 /*ufmt_date,*/ /* Date */
54 * Union representing a uprintf/uscanf argument
56 typedef union ufmt_args
{
57 int64_t int64Value
; /* int, UChar */
58 float floatValue
; /* float */
59 double doubleValue
; /* double */
60 void *ptrValue
; /* any pointer - void*, char*, wchar_t*, UChar* */
61 /*wchar_t wcharValue;*/ /* wchar_t */ /* TODO: Should wchar_t be used? */
62 /*UDate dateValue;*/ /* Date */
66 * Macro for determining the minimum of two numbers.
69 * @return <TT>a</TT> if </TT>a < b</TT>, <TT>b</TT> otherwise
71 #define ufmt_min(a,b) ((a) < (b) ? (a) : (b))
74 * Convert a UChar in hex radix to an integer value.
75 * @param c The UChar to convert.
76 * @return The integer value of <TT>c</TT>.
79 ufmt_digitvalue(UChar c
);
82 * Determine if a UChar is a digit for a specified radix.
83 * @param c The UChar to check.
84 * @param radix The desired radix.
85 * @return TRUE if <TT>c</TT> is a digit in <TT>radix</TT>, FALSE otherwise.
92 * Convert an int64_t to a UChar* in a specified radix
93 * @param buffer The target buffer
94 * @param len On input, the size of <TT>buffer</TT>. On output,
95 * the number of UChars written to <TT>buffer</TT>.
96 * @param value The value to be converted
97 * @param radix The desired radix
98 * @param uselower TRUE means lower case will be used, FALSE means upper case
99 * @param minDigits The minimum number of digits for for the formatted number,
100 * which will be padded with zeroes. -1 means do not pad.
103 ufmt_64tou(UChar
*buffer
,
111 * It's like ufmt_64tou, but with a pointer.
112 * This functions avoids size constraints of 64-bit types.
113 * Pointers can be at 32-128 bits in size.
116 ufmt_ptou(UChar
*buffer
,
122 * Convert a UChar* in a specified radix to an int64_t.
123 * @param buffer The target buffer
124 * @param len On input, the size of <TT>buffer</TT>. On output,
125 * the number of UChars read from <TT>buffer</TT>.
126 * @param radix The desired radix
127 * @return The numeric value.
130 ufmt_uto64(const UChar
*buffer
,
135 * Convert a UChar* in a specified radix to a pointer,
136 * @param buffer The target buffer
137 * @param len On input, the size of <TT>buffer</TT>. On output,
138 * the number of UChars read from <TT>buffer</TT>.
139 * @param radix The desired radix
140 * @return The pointer value.
143 ufmt_utop(const UChar
*buffer
,
147 * Convert a string from the default codepage to Unicode.
148 * @param s The string to convert, in the default codepage.
149 * @param sSize The size of s to convert.
150 * @param target The buffer to convert to.
151 * @param tSize The size of target
152 * @return A pointer to a newly allocated converted version of s, or 0
156 ufmt_defaultCPToUnicode(const char *s
, int32_t sSize
,
157 UChar
*target
, int32_t tSize
);