intl/icu/source/io/ufmt_cmn.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 ******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 1998-2011, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 ******************************************************************************
michael@0 8 *
michael@0 9 * File ufmt_cmn.h
michael@0 10 *
michael@0 11 * Modification History:
michael@0 12 *
michael@0 13 * Date Name Description
michael@0 14 * 12/02/98 stephen Creation.
michael@0 15 * 03/12/99 stephen Modified for new C API.
michael@0 16 * 03/15/99 stephen Added defaultCPToUnicode, unicodeToDefaultCP
michael@0 17 ******************************************************************************
michael@0 18 */
michael@0 19
michael@0 20 #ifndef UFMT_CMN_H
michael@0 21 #define UFMT_CMN_H
michael@0 22
michael@0 23 #include "unicode/utypes.h"
michael@0 24 #include "unicode/utf16.h"
michael@0 25
michael@0 26 #define UFMT_DEFAULT_BUFFER_SIZE 128
michael@0 27 #define MAX_UCHAR_BUFFER_SIZE(buffer) (sizeof(buffer)/(U16_MAX_LENGTH*sizeof(UChar)))
michael@0 28 #define MAX_UCHAR_BUFFER_NEEDED(strLen) ((strLen+1)*U16_MAX_LENGTH*sizeof(UChar))
michael@0 29
michael@0 30 /**
michael@0 31 * Enum representing the possible argument types for uprintf/uscanf
michael@0 32 */
michael@0 33 typedef enum ufmt_type_info {
michael@0 34 ufmt_empty = 0,
michael@0 35 ufmt_simple_percent, /* %% do nothing */
michael@0 36 ufmt_count, /* special flag for count */
michael@0 37 ufmt_int, /* int */
michael@0 38 ufmt_char, /* int, cast to char */
michael@0 39 ufmt_string, /* char* */
michael@0 40 ufmt_pointer, /* void* */
michael@0 41 ufmt_float, /* float */
michael@0 42 ufmt_double, /* double */
michael@0 43 ufmt_uchar, /* int, cast to UChar */
michael@0 44 ufmt_ustring /* UChar* */
michael@0 45 /*ufmt_wchar,*/ /* wchar_t */
michael@0 46 /*ufmt_wstring,*/ /* wchar_t* */
michael@0 47 /*ufmt_date,*/ /* Date */
michael@0 48 /*ufmt_last*/
michael@0 49 } ufmt_type_info;
michael@0 50
michael@0 51 /**
michael@0 52 * Union representing a uprintf/uscanf argument
michael@0 53 */
michael@0 54 typedef union ufmt_args {
michael@0 55 int64_t int64Value; /* int, UChar */
michael@0 56 float floatValue; /* float */
michael@0 57 double doubleValue; /* double */
michael@0 58 void *ptrValue; /* any pointer - void*, char*, wchar_t*, UChar* */
michael@0 59 /*wchar_t wcharValue;*/ /* wchar_t */ /* TODO: Should wchar_t be used? */
michael@0 60 /*UDate dateValue;*/ /* Date */
michael@0 61 } ufmt_args;
michael@0 62
michael@0 63 /**
michael@0 64 * Macro for determining the minimum of two numbers.
michael@0 65 * @param a An integer
michael@0 66 * @param b An integer
michael@0 67 * @return <TT>a</TT> if </TT>a < b</TT>, <TT>b</TT> otherwise
michael@0 68 */
michael@0 69 #define ufmt_min(a,b) ((a) < (b) ? (a) : (b))
michael@0 70
michael@0 71 /**
michael@0 72 * Convert a UChar in hex radix to an integer value.
michael@0 73 * @param c The UChar to convert.
michael@0 74 * @return The integer value of <TT>c</TT>.
michael@0 75 */
michael@0 76 int
michael@0 77 ufmt_digitvalue(UChar c);
michael@0 78
michael@0 79 /**
michael@0 80 * Determine if a UChar is a digit for a specified radix.
michael@0 81 * @param c The UChar to check.
michael@0 82 * @param radix The desired radix.
michael@0 83 * @return TRUE if <TT>c</TT> is a digit in <TT>radix</TT>, FALSE otherwise.
michael@0 84 */
michael@0 85 UBool
michael@0 86 ufmt_isdigit(UChar c,
michael@0 87 int32_t radix);
michael@0 88
michael@0 89 /**
michael@0 90 * Convert an int64_t to a UChar* in a specified radix
michael@0 91 * @param buffer The target buffer
michael@0 92 * @param len On input, the size of <TT>buffer</TT>. On output,
michael@0 93 * the number of UChars written to <TT>buffer</TT>.
michael@0 94 * @param value The value to be converted
michael@0 95 * @param radix The desired radix
michael@0 96 * @param uselower TRUE means lower case will be used, FALSE means upper case
michael@0 97 * @param minDigits The minimum number of digits for for the formatted number,
michael@0 98 * which will be padded with zeroes. -1 means do not pad.
michael@0 99 */
michael@0 100 void
michael@0 101 ufmt_64tou(UChar *buffer,
michael@0 102 int32_t *len,
michael@0 103 uint64_t value,
michael@0 104 uint8_t radix,
michael@0 105 UBool uselower,
michael@0 106 int32_t minDigits);
michael@0 107
michael@0 108 /**
michael@0 109 * It's like ufmt_64tou, but with a pointer.
michael@0 110 * This functions avoids size constraints of 64-bit types.
michael@0 111 * Pointers can be at 32-128 bits in size.
michael@0 112 */
michael@0 113 void
michael@0 114 ufmt_ptou(UChar *buffer,
michael@0 115 int32_t *len,
michael@0 116 void *value,
michael@0 117 UBool uselower);
michael@0 118
michael@0 119 /**
michael@0 120 * Convert a UChar* in a specified radix to an int64_t.
michael@0 121 * @param buffer The target buffer
michael@0 122 * @param len On input, the size of <TT>buffer</TT>. On output,
michael@0 123 * the number of UChars read from <TT>buffer</TT>.
michael@0 124 * @param radix The desired radix
michael@0 125 * @return The numeric value.
michael@0 126 */
michael@0 127 int64_t
michael@0 128 ufmt_uto64(const UChar *buffer,
michael@0 129 int32_t *len,
michael@0 130 int8_t radix);
michael@0 131
michael@0 132 /**
michael@0 133 * Convert a UChar* in a specified radix to a pointer,
michael@0 134 * @param buffer The target buffer
michael@0 135 * @param len On input, the size of <TT>buffer</TT>. On output,
michael@0 136 * the number of UChars read from <TT>buffer</TT>.
michael@0 137 * @param radix The desired radix
michael@0 138 * @return The pointer value.
michael@0 139 */
michael@0 140 void *
michael@0 141 ufmt_utop(const UChar *buffer,
michael@0 142 int32_t *len);
michael@0 143
michael@0 144 /**
michael@0 145 * Convert a string from the default codepage to Unicode.
michael@0 146 * @param s The string to convert, in the default codepage.
michael@0 147 * @param sSize The size of s to convert.
michael@0 148 * @param target The buffer to convert to.
michael@0 149 * @param tSize The size of target
michael@0 150 * @return A pointer to a newly allocated converted version of s, or 0
michael@0 151 * on error.
michael@0 152 */
michael@0 153 UChar*
michael@0 154 ufmt_defaultCPToUnicode(const char *s, int32_t sSize,
michael@0 155 UChar *target, int32_t tSize);
michael@0 156
michael@0 157
michael@0 158
michael@0 159 #endif
michael@0 160

mercurial