]> git.saurik.com Git - apple/icu.git/blame - icuSources/io/ufmt_cmn.h
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / io / ufmt_cmn.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/*
4******************************************************************************
5*
4388f060 6* Copyright (C) 1998-2011, International Business Machines
b75a7d8f
A
7* Corporation and others. All Rights Reserved.
8*
9******************************************************************************
10*
11* File ufmt_cmn.h
12*
13* Modification History:
14*
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******************************************************************************
20*/
21
22#ifndef UFMT_CMN_H
23#define UFMT_CMN_H
24
25#include "unicode/utypes.h"
4388f060 26#include "unicode/utf16.h"
b75a7d8f 27
374ca955 28#define UFMT_DEFAULT_BUFFER_SIZE 128
f3c0d7a5 29#define MAX_UCHAR_BUFFER_SIZE(buffer) ((int32_t)(sizeof(buffer)/(U16_MAX_LENGTH*sizeof(UChar))))
4388f060 30#define MAX_UCHAR_BUFFER_NEEDED(strLen) ((strLen+1)*U16_MAX_LENGTH*sizeof(UChar))
b75a7d8f
A
31
32/**
33 * Enum representing the possible argument types for uprintf/uscanf
34 */
374ca955
A
35typedef enum ufmt_type_info {
36 ufmt_empty = 0,
37 ufmt_simple_percent, /* %% do nothing */
38 ufmt_count, /* special flag for count */
39 ufmt_int, /* int */
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 */
50 /*ufmt_last*/
51} ufmt_type_info;
b75a7d8f
A
52
53/**
54 * Union representing a uprintf/uscanf argument
55 */
374ca955
A
56typedef 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 */
63} ufmt_args;
b75a7d8f
A
64
65/**
66 * Macro for determining the minimum of two numbers.
67 * @param a An integer
68 * @param b An integer
69 * @return <TT>a</TT> if </TT>a < b</TT>, <TT>b</TT> otherwise
70 */
71#define ufmt_min(a,b) ((a) < (b) ? (a) : (b))
72
73/**
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>.
77 */
78int
79ufmt_digitvalue(UChar c);
80
81/**
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.
86 */
87UBool
88ufmt_isdigit(UChar c,
89 int32_t radix);
90
91/**
374ca955 92 * Convert an int64_t to a UChar* in a specified radix
b75a7d8f
A
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.
101 */
102void
374ca955 103ufmt_64tou(UChar *buffer,
b75a7d8f 104 int32_t *len,
374ca955
A
105 uint64_t value,
106 uint8_t radix,
b75a7d8f
A
107 UBool uselower,
108 int32_t minDigits);
109
110/**
374ca955
A
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.
114 */
115void
116ufmt_ptou(UChar *buffer,
117 int32_t *len,
118 void *value,
119 UBool uselower);
120
121/**
122 * Convert a UChar* in a specified radix to an int64_t.
b75a7d8f
A
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.
128 */
374ca955
A
129int64_t
130ufmt_uto64(const UChar *buffer,
b75a7d8f 131 int32_t *len,
374ca955
A
132 int8_t radix);
133
134/**
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.
141 */
142void *
143ufmt_utop(const UChar *buffer,
144 int32_t *len);
b75a7d8f
A
145
146/**
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
153 * on error.
154 */
155UChar*
156ufmt_defaultCPToUnicode(const char *s, int32_t sSize,
157 UChar *target, int32_t tSize);
158
159
b75a7d8f
A
160
161#endif
162