michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1998-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * michael@0: * File ufmt_cmn.h michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 12/02/98 stephen Creation. michael@0: * 03/12/99 stephen Modified for new C API. michael@0: * 03/15/99 stephen Added defaultCPToUnicode, unicodeToDefaultCP michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #ifndef UFMT_CMN_H michael@0: #define UFMT_CMN_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/utf16.h" michael@0: michael@0: #define UFMT_DEFAULT_BUFFER_SIZE 128 michael@0: #define MAX_UCHAR_BUFFER_SIZE(buffer) (sizeof(buffer)/(U16_MAX_LENGTH*sizeof(UChar))) michael@0: #define MAX_UCHAR_BUFFER_NEEDED(strLen) ((strLen+1)*U16_MAX_LENGTH*sizeof(UChar)) michael@0: michael@0: /** michael@0: * Enum representing the possible argument types for uprintf/uscanf michael@0: */ michael@0: typedef enum ufmt_type_info { michael@0: ufmt_empty = 0, michael@0: ufmt_simple_percent, /* %% do nothing */ michael@0: ufmt_count, /* special flag for count */ michael@0: ufmt_int, /* int */ michael@0: ufmt_char, /* int, cast to char */ michael@0: ufmt_string, /* char* */ michael@0: ufmt_pointer, /* void* */ michael@0: ufmt_float, /* float */ michael@0: ufmt_double, /* double */ michael@0: ufmt_uchar, /* int, cast to UChar */ michael@0: ufmt_ustring /* UChar* */ michael@0: /*ufmt_wchar,*/ /* wchar_t */ michael@0: /*ufmt_wstring,*/ /* wchar_t* */ michael@0: /*ufmt_date,*/ /* Date */ michael@0: /*ufmt_last*/ michael@0: } ufmt_type_info; michael@0: michael@0: /** michael@0: * Union representing a uprintf/uscanf argument michael@0: */ michael@0: typedef union ufmt_args { michael@0: int64_t int64Value; /* int, UChar */ michael@0: float floatValue; /* float */ michael@0: double doubleValue; /* double */ michael@0: void *ptrValue; /* any pointer - void*, char*, wchar_t*, UChar* */ michael@0: /*wchar_t wcharValue;*/ /* wchar_t */ /* TODO: Should wchar_t be used? */ michael@0: /*UDate dateValue;*/ /* Date */ michael@0: } ufmt_args; michael@0: michael@0: /** michael@0: * Macro for determining the minimum of two numbers. michael@0: * @param a An integer michael@0: * @param b An integer michael@0: * @return a if a < b, b otherwise michael@0: */ michael@0: #define ufmt_min(a,b) ((a) < (b) ? (a) : (b)) michael@0: michael@0: /** michael@0: * Convert a UChar in hex radix to an integer value. michael@0: * @param c The UChar to convert. michael@0: * @return The integer value of c. michael@0: */ michael@0: int michael@0: ufmt_digitvalue(UChar c); michael@0: michael@0: /** michael@0: * Determine if a UChar is a digit for a specified radix. michael@0: * @param c The UChar to check. michael@0: * @param radix The desired radix. michael@0: * @return TRUE if c is a digit in radix, FALSE otherwise. michael@0: */ michael@0: UBool michael@0: ufmt_isdigit(UChar c, michael@0: int32_t radix); michael@0: michael@0: /** michael@0: * Convert an int64_t to a UChar* in a specified radix michael@0: * @param buffer The target buffer michael@0: * @param len On input, the size of buffer. On output, michael@0: * the number of UChars written to buffer. michael@0: * @param value The value to be converted michael@0: * @param radix The desired radix michael@0: * @param uselower TRUE means lower case will be used, FALSE means upper case michael@0: * @param minDigits The minimum number of digits for for the formatted number, michael@0: * which will be padded with zeroes. -1 means do not pad. michael@0: */ michael@0: void michael@0: ufmt_64tou(UChar *buffer, michael@0: int32_t *len, michael@0: uint64_t value, michael@0: uint8_t radix, michael@0: UBool uselower, michael@0: int32_t minDigits); michael@0: michael@0: /** michael@0: * It's like ufmt_64tou, but with a pointer. michael@0: * This functions avoids size constraints of 64-bit types. michael@0: * Pointers can be at 32-128 bits in size. michael@0: */ michael@0: void michael@0: ufmt_ptou(UChar *buffer, michael@0: int32_t *len, michael@0: void *value, michael@0: UBool uselower); michael@0: michael@0: /** michael@0: * Convert a UChar* in a specified radix to an int64_t. michael@0: * @param buffer The target buffer michael@0: * @param len On input, the size of buffer. On output, michael@0: * the number of UChars read from buffer. michael@0: * @param radix The desired radix michael@0: * @return The numeric value. michael@0: */ michael@0: int64_t michael@0: ufmt_uto64(const UChar *buffer, michael@0: int32_t *len, michael@0: int8_t radix); michael@0: michael@0: /** michael@0: * Convert a UChar* in a specified radix to a pointer, michael@0: * @param buffer The target buffer michael@0: * @param len On input, the size of buffer. On output, michael@0: * the number of UChars read from buffer. michael@0: * @param radix The desired radix michael@0: * @return The pointer value. michael@0: */ michael@0: void * michael@0: ufmt_utop(const UChar *buffer, michael@0: int32_t *len); michael@0: michael@0: /** michael@0: * Convert a string from the default codepage to Unicode. michael@0: * @param s The string to convert, in the default codepage. michael@0: * @param sSize The size of s to convert. michael@0: * @param target The buffer to convert to. michael@0: * @param tSize The size of target michael@0: * @return A pointer to a newly allocated converted version of s, or 0 michael@0: * on error. michael@0: */ michael@0: UChar* michael@0: ufmt_defaultCPToUnicode(const char *s, int32_t sSize, michael@0: UChar *target, int32_t tSize); michael@0: michael@0: michael@0: michael@0: #endif michael@0: