]> git.saurik.com Git - apple/icu.git/blame - icuSources/io/ufmt_cmn.h
ICU-8.11.4.tar.gz
[apple/icu.git] / icuSources / io / ufmt_cmn.h
CommitLineData
b75a7d8f
A
1/*
2******************************************************************************
3*
374ca955 4* Copyright (C) 1998-2004, International Business Machines
b75a7d8f
A
5* Corporation and others. All Rights Reserved.
6*
7******************************************************************************
8*
9* File ufmt_cmn.h
10*
11* Modification History:
12*
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******************************************************************************
18*/
19
20#ifndef UFMT_CMN_H
21#define UFMT_CMN_H
22
23#include "unicode/utypes.h"
24
374ca955 25#define UFMT_DEFAULT_BUFFER_SIZE 128
b75a7d8f
A
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))
28
29/**
30 * Enum representing the possible argument types for uprintf/uscanf
31 */
374ca955
A
32typedef enum ufmt_type_info {
33 ufmt_empty = 0,
34 ufmt_simple_percent, /* %% do nothing */
35 ufmt_count, /* special flag for count */
36 ufmt_int, /* int */
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 */
47 /*ufmt_last*/
48} ufmt_type_info;
b75a7d8f
A
49
50/**
51 * Union representing a uprintf/uscanf argument
52 */
374ca955
A
53typedef 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 */
60} ufmt_args;
b75a7d8f
A
61
62/**
63 * Macro for determining the minimum of two numbers.
64 * @param a An integer
65 * @param b An integer
66 * @return <TT>a</TT> if </TT>a < b</TT>, <TT>b</TT> otherwise
67 */
68#define ufmt_min(a,b) ((a) < (b) ? (a) : (b))
69
70/**
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>.
74 */
75int
76ufmt_digitvalue(UChar c);
77
78/**
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.
83 */
84UBool
85ufmt_isdigit(UChar c,
86 int32_t radix);
87
88/**
374ca955 89 * Convert an int64_t to a UChar* in a specified radix
b75a7d8f
A
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.
98 */
99void
374ca955 100ufmt_64tou(UChar *buffer,
b75a7d8f 101 int32_t *len,
374ca955
A
102 uint64_t value,
103 uint8_t radix,
b75a7d8f
A
104 UBool uselower,
105 int32_t minDigits);
106
107/**
374ca955
A
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.
111 */
112void
113ufmt_ptou(UChar *buffer,
114 int32_t *len,
115 void *value,
116 UBool uselower);
117
118/**
119 * Convert a UChar* in a specified radix to an int64_t.
b75a7d8f
A
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.
125 */
374ca955
A
126int64_t
127ufmt_uto64(const UChar *buffer,
b75a7d8f 128 int32_t *len,
374ca955
A
129 int8_t radix);
130
131/**
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.
138 */
139void *
140ufmt_utop(const UChar *buffer,
141 int32_t *len);
b75a7d8f
A
142
143/**
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
150 * on error.
151 */
152UChar*
153ufmt_defaultCPToUnicode(const char *s, int32_t sSize,
154 UChar *target, int32_t tSize);
155
156
b75a7d8f
A
157
158#endif
159