intl/icu/source/io/ufmt_cmn.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/io/ufmt_cmn.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,160 @@
     1.4 +/*
     1.5 +******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 1998-2011, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +******************************************************************************
    1.11 +*
    1.12 +* File ufmt_cmn.h
    1.13 +*
    1.14 +* Modification History:
    1.15 +*
    1.16 +*   Date        Name        Description
    1.17 +*   12/02/98    stephen        Creation.
    1.18 +*   03/12/99    stephen     Modified for new C API.
    1.19 +*   03/15/99    stephen     Added defaultCPToUnicode, unicodeToDefaultCP
    1.20 +******************************************************************************
    1.21 +*/
    1.22 +
    1.23 +#ifndef UFMT_CMN_H
    1.24 +#define UFMT_CMN_H
    1.25 +
    1.26 +#include "unicode/utypes.h"
    1.27 +#include "unicode/utf16.h"
    1.28 +
    1.29 +#define UFMT_DEFAULT_BUFFER_SIZE 128
    1.30 +#define MAX_UCHAR_BUFFER_SIZE(buffer) (sizeof(buffer)/(U16_MAX_LENGTH*sizeof(UChar)))
    1.31 +#define MAX_UCHAR_BUFFER_NEEDED(strLen) ((strLen+1)*U16_MAX_LENGTH*sizeof(UChar))
    1.32 +
    1.33 +/** 
    1.34 + * Enum representing the possible argument types for uprintf/uscanf
    1.35 + */
    1.36 +typedef enum ufmt_type_info {
    1.37 +    ufmt_empty = 0,
    1.38 +    ufmt_simple_percent, /* %% do nothing */
    1.39 +    ufmt_count,      /* special flag for count */
    1.40 +    ufmt_int,        /* int */
    1.41 +    ufmt_char,       /* int, cast to char */
    1.42 +    ufmt_string,     /* char* */
    1.43 +    ufmt_pointer,    /* void* */
    1.44 +    ufmt_float,      /* float */
    1.45 +    ufmt_double,     /* double */
    1.46 +    ufmt_uchar,      /* int, cast to UChar */
    1.47 +    ufmt_ustring     /* UChar* */
    1.48 +    /*ufmt_wchar,*/      /* wchar_t */
    1.49 +    /*ufmt_wstring,*/    /* wchar_t* */
    1.50 +    /*ufmt_date,*/       /* Date */
    1.51 +    /*ufmt_last*/
    1.52 +} ufmt_type_info;
    1.53 +
    1.54 +/**
    1.55 + * Union representing a uprintf/uscanf argument
    1.56 + */
    1.57 +typedef union ufmt_args {
    1.58 +    int64_t int64Value;    /* int, UChar */
    1.59 +    float   floatValue;    /* float */
    1.60 +    double  doubleValue;   /* double */
    1.61 +    void    *ptrValue;     /* any pointer - void*, char*, wchar_t*, UChar* */
    1.62 +    /*wchar_t wcharValue;*/    /* wchar_t */    /* TODO: Should wchar_t be used? */
    1.63 +    /*UDate dateValue;*/     /* Date */
    1.64 +} ufmt_args;
    1.65 +
    1.66 +/**
    1.67 + * Macro for determining the minimum of two numbers.
    1.68 + * @param a An integer
    1.69 + * @param b An integer
    1.70 + * @return <TT>a</TT> if </TT>a < b</TT>, <TT>b</TT> otherwise
    1.71 + */
    1.72 +#define ufmt_min(a,b) ((a) < (b) ? (a) : (b))
    1.73 +
    1.74 +/**
    1.75 + * Convert a UChar in hex radix to an integer value.
    1.76 + * @param c The UChar to convert.
    1.77 + * @return The integer value of <TT>c</TT>.
    1.78 + */
    1.79 +int
    1.80 +ufmt_digitvalue(UChar c);
    1.81 +
    1.82 +/**
    1.83 + * Determine if a UChar is a digit for a specified radix.
    1.84 + * @param c The UChar to check.
    1.85 + * @param radix The desired radix.
    1.86 + * @return TRUE if <TT>c</TT> is a digit in <TT>radix</TT>, FALSE otherwise.
    1.87 + */
    1.88 +UBool
    1.89 +ufmt_isdigit(UChar     c,
    1.90 +         int32_t     radix);
    1.91 +
    1.92 +/**
    1.93 + * Convert an int64_t to a UChar* in a specified radix
    1.94 + * @param buffer The target buffer
    1.95 + * @param len On input, the size of <TT>buffer</TT>.  On output,
    1.96 + * the number of UChars written to <TT>buffer</TT>.
    1.97 + * @param value The value to be converted
    1.98 + * @param radix The desired radix
    1.99 + * @param uselower TRUE means lower case will be used, FALSE means upper case
   1.100 + * @param minDigits The minimum number of digits for for the formatted number,
   1.101 + * which will be padded with zeroes. -1 means do not pad.
   1.102 + */
   1.103 +void 
   1.104 +ufmt_64tou(UChar     *buffer, 
   1.105 +      int32_t     *len,
   1.106 +      uint64_t     value, 
   1.107 +      uint8_t     radix,
   1.108 +      UBool    uselower,
   1.109 +      int32_t    minDigits);
   1.110 +
   1.111 +/**
   1.112 + * It's like ufmt_64tou, but with a pointer.
   1.113 + * This functions avoids size constraints of 64-bit types.
   1.114 + * Pointers can be at 32-128 bits in size.
   1.115 + */
   1.116 +void 
   1.117 +ufmt_ptou(UChar    *buffer, 
   1.118 +          int32_t   *len,
   1.119 +          void      *value, 
   1.120 +          UBool     uselower);
   1.121 +
   1.122 +/**
   1.123 + * Convert a UChar* in a specified radix to an int64_t.
   1.124 + * @param buffer The target buffer
   1.125 + * @param len On input, the size of <TT>buffer</TT>.  On output,
   1.126 + * the number of UChars read from <TT>buffer</TT>.
   1.127 + * @param radix The desired radix
   1.128 + * @return The numeric value.
   1.129 + */
   1.130 +int64_t
   1.131 +ufmt_uto64(const UChar     *buffer, 
   1.132 +      int32_t     *len,
   1.133 +      int8_t     radix);
   1.134 +
   1.135 +/**
   1.136 + * Convert a UChar* in a specified radix to a pointer,
   1.137 + * @param buffer The target buffer
   1.138 + * @param len On input, the size of <TT>buffer</TT>.  On output,
   1.139 + * the number of UChars read from <TT>buffer</TT>.
   1.140 + * @param radix The desired radix
   1.141 + * @return The pointer value.
   1.142 + */
   1.143 +void *
   1.144 +ufmt_utop(const UChar     *buffer,
   1.145 +      int32_t     *len);
   1.146 +
   1.147 +/**
   1.148 + * Convert a string from the default codepage to Unicode.
   1.149 + * @param s The string to convert, in the default codepage.
   1.150 + * @param sSize The size of s to convert.
   1.151 + * @param target The buffer to convert to.
   1.152 + * @param tSize The size of target
   1.153 + * @return A pointer to a newly allocated converted version of s, or 0 
   1.154 + * on error.
   1.155 + */
   1.156 +UChar*
   1.157 +ufmt_defaultCPToUnicode(const char *s, int32_t sSize,
   1.158 +                        UChar *target, int32_t tSize);
   1.159 +
   1.160 +
   1.161 +
   1.162 +#endif
   1.163 +

mercurial