~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/common/unicode/putil.h

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
******************************************************************************
3
 
*
4
 
*   Copyright (C) 1997-2001, International Business Machines
5
 
*   Corporation and others.  All Rights Reserved.
6
 
*
7
 
******************************************************************************
8
 
*
9
 
*  FILE NAME : putil.h
10
 
*
11
 
*   Date        Name        Description
12
 
*   05/14/98    nos         Creation (content moved here from utypes.h).
13
 
*   06/17/99    erm         Added IEEE_754
14
 
*   07/22/98    stephen     Added IEEEremainder, max, min, trunc
15
 
*   08/13/98    stephen     Added isNegativeInfinity, isPositiveInfinity
16
 
*   08/24/98    stephen     Added longBitsFromDouble
17
 
*   03/02/99    stephen     Removed openFile().  Added AS400 support.
18
 
*   04/15/99    stephen     Converted to C
19
 
*   11/15/99    helena      Integrated S/390 changes for IEEE support.
20
 
*   01/11/00    helena      Added u_getVersion.
21
 
******************************************************************************
22
 
*/
23
 
 
24
 
#ifndef PUTIL_H
25
 
#define PUTIL_H
26
 
 
27
 
#include "unicode/utypes.h"
28
 
 
29
 
/* Define this to 1 if your platform supports IEEE 754 floating point,
30
 
   to 0 if it does not. */
31
 
#ifndef IEEE_754
32
 
#   define IEEE_754 1
33
 
#endif
34
 
 
35
 
/*==========================================================================*/
36
 
/* Platform utilities                                                       */
37
 
/*==========================================================================*/
38
 
 
39
 
/**
40
 
 * Platform utilities isolates the platform dependencies of the
41
 
 * libarary.  For each platform which this code is ported to, these
42
 
 * functions may have to be re-implemented.
43
 
 */
44
 
 
45
 
/* Floating point utilities 
46
 
 */
47
 
U_CAPI UBool   U_EXPORT2 uprv_isNaN(double);
48
 
U_CAPI UBool   U_EXPORT2 uprv_isInfinite(double);
49
 
U_CAPI UBool   U_EXPORT2 uprv_isPositiveInfinity(double);
50
 
U_CAPI UBool   U_EXPORT2 uprv_isNegativeInfinity(double);
51
 
U_CAPI double  U_EXPORT2 uprv_getNaN(void);
52
 
U_CAPI double  U_EXPORT2 uprv_getInfinity(void);
53
 
 
54
 
U_CAPI double  U_EXPORT2 uprv_trunc(double d);
55
 
U_CAPI double  U_EXPORT2 uprv_floor(double x);
56
 
U_CAPI double  U_EXPORT2 uprv_ceil(double x);
57
 
U_CAPI double  U_EXPORT2 uprv_fabs(double x);
58
 
U_CAPI double  U_EXPORT2 uprv_modf(double x, double* y);
59
 
U_CAPI double  U_EXPORT2 uprv_fmod(double x, double y);
60
 
U_CAPI double  U_EXPORT2 uprv_pow(double x, double y);
61
 
U_CAPI double  U_EXPORT2 uprv_pow10(int32_t x);
62
 
U_CAPI double  U_EXPORT2 uprv_fmax(double x, double y);
63
 
U_CAPI double  U_EXPORT2 uprv_fmin(double x, double y);
64
 
U_CAPI int32_t U_EXPORT2 uprv_max(int32_t x, int32_t y);
65
 
U_CAPI int32_t U_EXPORT2 uprv_min(int32_t x, int32_t y);
66
 
 
67
 
#if U_IS_BIG_ENDIAN
68
 
#   define uprv_isNegative(number) (*((signed char *)&(number))<0)
69
 
#else
70
 
#   define uprv_isNegative(number) (*((signed char *)&(number)+sizeof(number)-1)<0)
71
 
#endif
72
 
 
73
 
/**
74
 
 * Return the largest positive number that can be represented by an integer
75
 
 * type of arbitrary bit length.
76
 
 */
77
 
U_CAPI double  U_EXPORT2 uprv_maxMantissa(void);
78
 
 
79
 
/**
80
 
 * Return the floor of the log base 10 of a given double.
81
 
 * This method compensates for inaccuracies which arise naturally when
82
 
 * computing logs, and always gives the correct value.  The parameter
83
 
 * must be positive and finite.
84
 
 * (Thanks to Alan Liu for supplying this function.)
85
 
 *
86
 
 * @param d the double value to apply the common log function for.
87
 
 * @return the log of value d.
88
 
 */
89
 
U_CAPI int16_t  U_EXPORT2 uprv_log10(double d);
90
 
 
91
 
U_CAPI double  U_EXPORT2 uprv_log(double d);
92
 
 
93
 
/** Does common notion of rounding e.g. uprv_floor(x + 0.5); */
94
 
U_CAPI double  U_EXPORT2 uprv_round(double x);
95
 
 
96
 
/**
97
 
 * Returns the number of digits after the decimal point in a double number x.
98
 
 *
99
 
 * @param x the double number
100
 
 */
101
 
U_CAPI int32_t  U_EXPORT2 uprv_digitsAfterDecimal(double x);
102
 
 
103
 
/**
104
 
 * Time zone utilities
105
 
 *
106
 
 * Wrappers for C runtime library functions relating to timezones.
107
 
 * The t_tzset() function (similar to tzset) uses the current setting 
108
 
 * of the environment variable TZ to assign values to three global 
109
 
 * variables: daylight, timezone, and tzname. These variables have the 
110
 
 * following meanings, and are declared in &lt;time.h&gt;.
111
 
 *
112
 
 *   daylight   Nonzero if daylight-saving-time zone (DST) is specified
113
 
 *              in TZ; otherwise, 0. Default value is 1.
114
 
 *   timezone   Difference in seconds between coordinated universal
115
 
 *              time and local time. E.g., -28,800 for PST (GMT-8hrs)
116
 
 *   tzname(0)  Three-letter time-zone name derived from TZ environment
117
 
 *              variable. E.g., "PST".
118
 
 *   tzname(1)  Three-letter DST zone name derived from TZ environment
119
 
 *              variable.  E.g., "PDT". If DST zone is omitted from TZ,
120
 
 *              tzname(1) is an empty string.
121
 
 *
122
 
 * Notes: For example, to set the TZ environment variable to correspond
123
 
 * to the current time zone in Germany, you can use one of the
124
 
 * following statements:
125
 
 *
126
 
 *   set TZ=GST1GDT
127
 
 *   set TZ=GST+1GDT
128
 
 *
129
 
 * If the TZ value is not set, t_tzset() attempts to use the time zone
130
 
 * information specified by the operating system. Under Windows NT
131
 
 * and Windows 95, this information is specified in the Control Panel�s
132
 
 * Date/Time application.
133
 
 * @stable
134
 
 */
135
 
U_CAPI void     U_EXPORT2 uprv_tzset(void);
136
 
 
137
 
/**
138
 
 * Difference in seconds between coordinated universal
139
 
 * time and local time. E.g., -28,800 for PST (GMT-8hrs)
140
 
 */
141
 
U_CAPI int32_t  U_EXPORT2 uprv_timezone(void);
142
 
 
143
 
/**
144
 
 *   tzname(0)  Three-letter time-zone name derived from TZ environment
145
 
 *              variable. E.g., "PST".
146
 
 *   tzname(1)  Three-letter DST zone name derived from TZ environment
147
 
 *              variable.  E.g., "PDT". If DST zone is omitted from TZ,
148
 
 *              tzname(1) is an empty string.
149
 
 */
150
 
U_CAPI char*    U_EXPORT2 uprv_tzname(int n);
151
 
 
152
 
/**
153
 
 * Get UTC (GMT) time measured in seconds since 0:00 on 1/1/70. 
154
 
 * @stable
155
 
 */
156
 
U_CAPI int32_t  U_EXPORT2 uprv_getUTCtime(void);
157
 
 
158
 
/**
159
 
 * Return the ICU data directory. 
160
 
 * The data directory is where common format ICU data files (.dat files)
161
 
 *   are loaded from.  Note that normal use of the built-in ICU
162
 
 *   facilities does not require loading of an external data file;
163
 
 *   unless you are adding custom data to ICU, the data directory
164
 
 *   does not need to be set.
165
 
 *
166
 
 * The data directory is determined as follows:
167
 
 *    If u_setDataDirectory() has been called, that is it, otherwise
168
 
 *    if the ICU_DATA environment variable is set, use that, otherwise
169
 
 *    On Windows, if the SOFTWARE\ICU\Unicode\Data registry entry exists, use that
170
 
 *           (use of the registry in this way is not recommended.)  otherwise
171
 
 *    If a data directory was specifed at ICU build time, use that
172
 
 *    otherwise no data directory is available.
173
 
 *
174
 
 * @return the data directory, or an empty string ("") if no data directory has
175
 
 *         been specified.
176
 
 *   
177
 
 * @stable
178
 
 */
179
 
U_CAPI const char* U_EXPORT2 u_getDataDirectory(void);
180
 
 
181
 
/** 
182
 
 * Set the ICU data directory. 
183
 
 * The data directory is where common format ICU data files (.dat files)
184
 
 *   are loaded from.  Note that normal use of the built-in ICU
185
 
 *   facilities does not require loading of an external data file;
186
 
 *   unless you are adding custom data to ICU, the data directory
187
 
 *   does not need to be set.
188
 
 *
189
 
 * This function should be called at most once in a process, before the
190
 
 * first ICU operation that will require the loading of an ICU data file.
191
 
 *
192
 
 * @stable
193
 
 */
194
 
U_CAPI void U_EXPORT2 u_setDataDirectory(const char *directory);
195
 
 
196
 
/**
197
 
 * Return the default codepage for this platform and locale 
198
 
 * @stable
199
 
 */
200
 
U_CAPI const char*  U_EXPORT2 uprv_getDefaultCodepage(void);
201
 
 
202
 
/**
203
 
 * Return the default locale ID string by querying ths system, or
204
 
 *     zero if one cannot be found. 
205
 
 * @stable
206
 
 */
207
 
U_CAPI const char*  U_EXPORT2 uprv_getDefaultLocaleID(void);
208
 
 
209
 
/*
210
 
 * Finds the least double greater than d (if positive == true),
211
 
 * or the greatest double less than d (if positive == false).
212
 
 *
213
 
 * This is a special purpose function defined by the ChoiceFormat API
214
 
 * documentation.
215
 
 * It is not a general purpose function and not defined for NaN or Infinity
216
 
 * @deprecated This will be removed after 2002-Jun-30. Use the ChoiceFormat closures API instead.
217
 
 */
218
 
U_CAPI double       U_EXPORT2 uprv_nextDouble(double d, UBool positive);
219
 
 
220
 
/**
221
 
 * Filesystem file and path separator characters.
222
 
 * Example: '/' and ':' on Unix, '\\' and ';' on Windows.
223
 
 * @stable
224
 
 */
225
 
#ifdef XP_MAC
226
 
#   define U_FILE_SEP_CHAR ':'
227
 
#   define U_PATH_SEP_CHAR ';'
228
 
#   define U_FILE_SEP_STRING ":"
229
 
#   define U_PATH_SEP_STRING ";"
230
 
#elif defined(WIN32) || defined(OS2)
231
 
#   define U_FILE_SEP_CHAR '\\'
232
 
#   define U_PATH_SEP_CHAR ';'
233
 
#   define U_FILE_SEP_STRING "\\"
234
 
#   define U_PATH_SEP_STRING ";"
235
 
#else
236
 
#   define U_FILE_SEP_CHAR '/'
237
 
#   define U_PATH_SEP_CHAR ':'
238
 
#   define U_FILE_SEP_STRING "/"
239
 
#   define U_PATH_SEP_STRING ":"
240
 
#endif
241
 
 
242
 
/**
243
 
 * Convert char characters to UChar characters.
244
 
 * This utility function is useful only for "invariant characters"
245
 
 * that are encoded in the platform default encoding.
246
 
 * They are a small, constant subset of the encoding and include
247
 
 * just the latin letters, digits, and some punctuation.
248
 
 * For details, see utypes.h .
249
 
 *
250
 
 * @param cs Input string, points to <code>length</code>
251
 
 *           character bytes from a subset of the platform encoding.
252
 
 * @param us Output string, points to memory for <code>length</code>
253
 
 *           Unicode characters.
254
 
 * @param length The number of characters to convert; this may
255
 
 *               include the terminating <code>NUL</code>.
256
 
 * @stable
257
 
 */
258
 
U_CAPI void U_EXPORT2
259
 
u_charsToUChars(const char *cs, UChar *us, int32_t length);
260
 
 
261
 
/**
262
 
 * Convert UChar characters to char characters.
263
 
 * This utility function is useful only for "invariant characters"
264
 
 * that can be encoded in the platform default encoding.
265
 
 * They are a small, constant subset of the encoding and include
266
 
 * just the latin letters, digits, and some punctuation.
267
 
 * For details, see utypes.h .
268
 
 *
269
 
 * @param us Input string, points to <code>length</code>
270
 
 *           Unicode characters that can be encoded with the
271
 
 *           codepage-invariant subset of the platform encoding.
272
 
 * @param cs Output string, points to memory for <code>length</code>
273
 
 *           character bytes.
274
 
 * @param length The number of characters to convert; this may
275
 
 *               include the terminating <code>NUL</code>.
276
 
 * @stable
277
 
 */
278
 
U_CAPI void U_EXPORT2
279
 
u_UCharsToChars(const UChar *us, char *cs, int32_t length);
280
 
 
281
 
/* Define U_UPPER_ORDINAL */
282
 
#if U_CHARSET_FAMILY==U_ASCII_FAMILY
283
 
#   define U_UPPER_ORDINAL(x) ((x)-'A')
284
 
#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
285
 
#   define U_UPPER_ORDINAL(x) (((x) < 'J') ? ((x)-'A') : \
286
 
                              (((x) < 'S') ? ((x)-'J'+9) : \
287
 
                               ((x)-'S'+18)))
288
 
#else
289
 
#   error Unknown charset family!
290
 
#endif
291
 
 
292
 
/**
293
 
 * Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffer.
294
 
 * In fact, buffer sizes must not exceed 2GB so that the difference between
295
 
 * the buffer limit and the buffer start can be expressed in an int32_t.
296
 
 *
297
 
 * The definition of U_MAX_PTR must fulfill the following conditions:
298
 
 * - return the largest possible pointer greater than base
299
 
 * - return a valid pointer according to the machine architecture (AS/400, 64-bit, etc.)
300
 
 * - avoid wrapping around at high addresses
301
 
 * - make sure that the returned pointer is not farther from base than 0x7fffffff
302
 
 *
303
 
 * @param base The beginning of a buffer to find the maximum offset from
304
 
 * @internal
305
 
 */
306
 
#ifndef U_MAX_PTR
307
 
#  ifdef OS390
308
 
#    define U_MAX_PTR(base) ((void *)0x7fffffff)
309
 
#  elif defined(OS400)
310
 
/*
311
 
 * With the provided macro we should never be out of range of a given segment
312
 
 * (a traditional/typical segment that is).  Our segments have 5 bytes for the id
313
 
 * and 3 bytes for the offset.  The key is that the casting takes care of only
314
 
 * retrieving the offset portion minus x1000.  Hence, the smallest offset seen in
315
 
 * a program is x001000 and when casted to an int would be 0.  That's why we can
316
 
 * only add 0xffefff.  Otherwise, we would exceed the segment.
317
 
 *
318
 
 * Currently, 16MB is the current addressing limitation on as/400.  This macro
319
 
 * may eventually be changed to use 2GB addressability for the newer version of
320
 
 * as/400 machines.
321
 
 */
322
 
#    define U_MAX_PTR(base) ((void *)(((char *)base)-((int32_t)(base))+((int32_t)0xffefff)))
323
 
#  else
324
 
#    define U_MAX_PTR(base) ((void *)(((char *)(base)+0x7fffffff) > (char *)(base) ? ((char *)(base)+0x7fffffff) : (char *)-1))
325
 
#  endif
326
 
#endif
327
 
 
328
 
#endif