]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/unicode/umachine.h
ICU-57166.0.1.tar.gz
[apple/icu.git] / icuSources / common / unicode / umachine.h
CommitLineData
b75a7d8f
A
1/*
2******************************************************************************
3*
2ca993e8 4* Copyright (C) 1999-2015, International Business Machines
b75a7d8f
A
5* Corporation and others. All Rights Reserved.
6*
7******************************************************************************
8* file name: umachine.h
9* encoding: US-ASCII
10* tab size: 8 (not used)
11* indentation:4
12*
13* created on: 1999sep13
14* created by: Markus W. Scherer
15*
b331163b 16* This file defines basic types and constants for ICU to be
b75a7d8f
A
17* platform-independent. umachine.h and utf.h are included into
18* utypes.h to provide all the general definitions for ICU.
19* All of these definitions used to be in utypes.h before
20* the UTF-handling macros made this unmaintainable.
21*/
22
23#ifndef __UMACHINE_H__
24#define __UMACHINE_H__
25
26
27/**
28 * \file
729e4ab9
A
29 * \brief Basic types and constants for UTF
30 *
b75a7d8f
A
31 * <h2> Basic types and constants for UTF </h2>
32 * This file defines basic types and constants for utf.h to be
33 * platform-independent. umachine.h and utf.h are included into
34 * utypes.h to provide all the general definitions for ICU.
35 * All of these definitions used to be in utypes.h before
36 * the UTF-handling macros made this unmaintainable.
729e4ab9 37 *
b75a7d8f
A
38 */
39/*==========================================================================*/
40/* Include platform-dependent definitions */
41/* which are contained in the platform-specific file platform.h */
42/*==========================================================================*/
43
4388f060 44#include "unicode/ptypes.h" /* platform.h is included in ptypes.h */
b75a7d8f 45
374ca955
A
46/*
47 * ANSI C headers:
48 * stddef.h defines wchar_t
49 */
50#include <stddef.h>
51
b75a7d8f 52/*==========================================================================*/
374ca955 53/* For C wrappers, we use the symbol U_STABLE. */
b75a7d8f 54/* This works properly if the includer is C or C++. */
374ca955 55/* Functions are declared U_STABLE return-type U_EXPORT2 function-name()... */
b75a7d8f
A
56/*==========================================================================*/
57
58/**
59 * \def U_CFUNC
60 * This is used in a declaration of a library private ICU C function.
61 * @stable ICU 2.4
62 */
63
64/**
65 * \def U_CDECL_BEGIN
66 * This is used to begin a declaration of a library private ICU C API.
67 * @stable ICU 2.4
68 */
69
70/**
71 * \def U_CDECL_END
729e4ab9 72 * This is used to end a declaration of a library private ICU C API
b75a7d8f
A
73 * @stable ICU 2.4
74 */
75
4388f060 76#ifdef __cplusplus
b75a7d8f
A
77# define U_CFUNC extern "C"
78# define U_CDECL_BEGIN extern "C" {
79# define U_CDECL_END }
80#else
81# define U_CFUNC extern
82# define U_CDECL_BEGIN
83# define U_CDECL_END
84#endif
85
4388f060 86#ifndef U_ATTRIBUTE_DEPRECATED
729e4ab9
A
87/**
88 * \def U_ATTRIBUTE_DEPRECATED
89 * This is used for GCC specific attributes
90 * @internal
91 */
51004dcb 92#if U_GCC_MAJOR_MINOR >= 302
729e4ab9
A
93# define U_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated))
94/**
95 * \def U_ATTRIBUTE_DEPRECATED
96 * This is used for Visual C++ specific attributes
97 * @internal
98 */
4388f060 99#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
729e4ab9
A
100# define U_ATTRIBUTE_DEPRECATED __declspec(deprecated)
101#else
102# define U_ATTRIBUTE_DEPRECATED
103#endif
4388f060
A
104#endif
105
b75a7d8f
A
106/** This is used to declare a function as a public ICU C API @stable ICU 2.0*/
107#define U_CAPI U_CFUNC U_EXPORT
729e4ab9 108/** This is used to declare a function as a stable public ICU C API*/
374ca955 109#define U_STABLE U_CAPI
729e4ab9 110/** This is used to declare a function as a draft public ICU C API */
374ca955 111#define U_DRAFT U_CAPI
729e4ab9
A
112/** This is used to declare a function as a deprecated public ICU C API */
113#define U_DEPRECATED U_CAPI U_ATTRIBUTE_DEPRECATED
114/** This is used to declare a function as an obsolete public ICU C API */
374ca955 115#define U_OBSOLETE U_CAPI
729e4ab9 116/** This is used to declare a function as an internal ICU C API */
374ca955 117#define U_INTERNAL U_CAPI
b75a7d8f 118
b331163b
A
119/**
120 * \def U_OVERRIDE
121 * Defined to the C++11 "override" keyword if available.
122 * Denotes a class or member which is an override of the base class.
123 * May result in an error if it applied to something not an override.
124 * @internal
125 */
126
127/**
128 * \def U_FINAL
129 * Defined to the C++11 "final" keyword if available.
130 * Denotes a class or member which may not be overridden in subclasses.
131 * May result in an error if subclasses attempt to override.
132 * @internal
133 */
134
2ca993e8 135#if U_CPLUSPLUS_VERSION >= 11
b331163b
A
136/* C++11 */
137#ifndef U_OVERRIDE
138#define U_OVERRIDE override
139#endif
140#ifndef U_FINAL
141#define U_FINAL final
142#endif
143#else
144/* not C++11 - define to nothing */
145#ifndef U_OVERRIDE
146#define U_OVERRIDE
147#endif
148#ifndef U_FINAL
149#define U_FINAL
150#endif
151#endif
152
b75a7d8f
A
153/*==========================================================================*/
154/* limits for int32_t etc., like in POSIX inttypes.h */
155/*==========================================================================*/
156
157#ifndef INT8_MIN
158/** The smallest value an 8 bit signed integer can hold @stable ICU 2.0 */
159# define INT8_MIN ((int8_t)(-128))
160#endif
161#ifndef INT16_MIN
162/** The smallest value a 16 bit signed integer can hold @stable ICU 2.0 */
163# define INT16_MIN ((int16_t)(-32767-1))
164#endif
165#ifndef INT32_MIN
166/** The smallest value a 32 bit signed integer can hold @stable ICU 2.0 */
167# define INT32_MIN ((int32_t)(-2147483647-1))
168#endif
169
170#ifndef INT8_MAX
171/** The largest value an 8 bit signed integer can hold @stable ICU 2.0 */
172# define INT8_MAX ((int8_t)(127))
173#endif
174#ifndef INT16_MAX
175/** The largest value a 16 bit signed integer can hold @stable ICU 2.0 */
176# define INT16_MAX ((int16_t)(32767))
177#endif
178#ifndef INT32_MAX
179/** The largest value a 32 bit signed integer can hold @stable ICU 2.0 */
180# define INT32_MAX ((int32_t)(2147483647))
181#endif
182
183#ifndef UINT8_MAX
184/** The largest value an 8 bit unsigned integer can hold @stable ICU 2.0 */
185# define UINT8_MAX ((uint8_t)(255U))
186#endif
187#ifndef UINT16_MAX
188/** The largest value a 16 bit unsigned integer can hold @stable ICU 2.0 */
189# define UINT16_MAX ((uint16_t)(65535U))
190#endif
191#ifndef UINT32_MAX
192/** The largest value a 32 bit unsigned integer can hold @stable ICU 2.0 */
193# define UINT32_MAX ((uint32_t)(4294967295U))
194#endif
195
196#if defined(U_INT64_T_UNAVAILABLE)
374ca955 197# error int64_t is required for decimal format and rule-based number format.
b75a7d8f 198#else
374ca955
A
199# ifndef INT64_C
200/**
201 * Provides a platform independent way to specify a signed 64-bit integer constant.
202 * note: may be wrong for some 64 bit platforms - ensure your compiler provides INT64_C
73c04bcf 203 * @stable ICU 2.8
374ca955
A
204 */
205# define INT64_C(c) c ## LL
206# endif
207# ifndef UINT64_C
208/**
209 * Provides a platform independent way to specify an unsigned 64-bit integer constant.
210 * note: may be wrong for some 64 bit platforms - ensure your compiler provides UINT64_C
73c04bcf 211 * @stable ICU 2.8
374ca955
A
212 */
213# define UINT64_C(c) c ## ULL
214# endif
215# ifndef U_INT64_MIN
216/** The smallest value a 64 bit signed integer can hold @stable ICU 2.8 */
217# define U_INT64_MIN ((int64_t)(INT64_C(-9223372036854775807)-1))
218# endif
219# ifndef U_INT64_MAX
220/** The largest value a 64 bit signed integer can hold @stable ICU 2.8 */
221# define U_INT64_MAX ((int64_t)(INT64_C(9223372036854775807)))
222# endif
223# ifndef U_UINT64_MAX
224/** The largest value a 64 bit unsigned integer can hold @stable ICU 2.8 */
225# define U_UINT64_MAX ((uint64_t)(UINT64_C(18446744073709551615)))
226# endif
b75a7d8f
A
227#endif
228
229/*==========================================================================*/
230/* Boolean data type */
231/*==========================================================================*/
232
233/** The ICU boolean type @stable ICU 2.0 */
234typedef int8_t UBool;
235
236#ifndef TRUE
237/** The TRUE value of a UBool @stable ICU 2.0 */
238# define TRUE 1
239#endif
240#ifndef FALSE
241/** The FALSE value of a UBool @stable ICU 2.0 */
242# define FALSE 0
243#endif
244
245
374ca955
A
246/*==========================================================================*/
247/* Unicode data types */
248/*==========================================================================*/
249
250/* wchar_t-related definitions -------------------------------------------- */
251
374ca955
A
252/*
253 * \def U_WCHAR_IS_UTF16
254 * Defined if wchar_t uses UTF-16.
255 *
256 * @stable ICU 2.0
257 */
258/*
259 * \def U_WCHAR_IS_UTF32
260 * Defined if wchar_t uses UTF-32.
261 *
262 * @stable ICU 2.0
263 */
264#if !defined(U_WCHAR_IS_UTF16) && !defined(U_WCHAR_IS_UTF32)
729e4ab9 265# ifdef __STDC_ISO_10646__
374ca955
A
266# if (U_SIZEOF_WCHAR_T==2)
267# define U_WCHAR_IS_UTF16
268# elif (U_SIZEOF_WCHAR_T==4)
269# define U_WCHAR_IS_UTF32
270# endif
271# elif defined __UCS2__
4388f060 272# if (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400) && (U_SIZEOF_WCHAR_T==2)
374ca955
A
273# define U_WCHAR_IS_UTF16
274# endif
4388f060 275# elif defined(__UCS4__) || (U_PLATFORM == U_PF_OS400 && defined(__UTF32__))
374ca955
A
276# if (U_SIZEOF_WCHAR_T==4)
277# define U_WCHAR_IS_UTF32
278# endif
4388f060
A
279# elif U_PLATFORM_IS_DARWIN_BASED || (U_SIZEOF_WCHAR_T==4 && U_PLATFORM_IS_LINUX_BASED)
280# define U_WCHAR_IS_UTF32
281# elif U_PLATFORM_HAS_WIN32_API
729e4ab9 282# define U_WCHAR_IS_UTF16
374ca955
A
283# endif
284#endif
285
286/* UChar and UChar32 definitions -------------------------------------------- */
287
288/** Number of bytes in a UChar. @stable ICU 2.0 */
289#define U_SIZEOF_UCHAR 2
290
291/**
292 * \var UChar
51004dcb 293 * Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t),
4388f060
A
294 * or wchar_t if that is 16 bits wide; always assumed to be unsigned.
295 * If neither is available, then define UChar to be uint16_t.
296 *
374ca955
A
297 * This makes the definition of UChar platform-dependent
298 * but allows direct string type compatibility with platforms with
299 * 16-bit wchar_t types.
300 *
4388f060 301 * @stable ICU 4.4
374ca955 302 */
51004dcb
A
303#if defined(UCHAR_TYPE)
304 typedef UCHAR_TYPE UChar;
305/* Not #elif U_HAVE_CHAR16_T -- because that is type-incompatible with pre-C++11 callers
306 typedef char16_t UChar; */
4388f060
A
307#elif U_SIZEOF_WCHAR_T==2
308 typedef wchar_t UChar;
309#elif defined(__CHAR16_TYPE__)
310 typedef __CHAR16_TYPE__ UChar;
374ca955
A
311#else
312 typedef uint16_t UChar;
313#endif
314
315/**
316 * Define UChar32 as a type for single Unicode code points.
317 * UChar32 is a signed 32-bit integer (same as int32_t).
318 *
319 * The Unicode code point range is 0..0x10ffff.
320 * All other values (negative or >=0x110000) are illegal as Unicode code points.
321 * They may be used as sentinel values to indicate "done", "error"
322 * or similar non-code point conditions.
323 *
324 * Before ICU 2.4 (Jitterbug 2146), UChar32 was defined
325 * to be wchar_t if that is 32 bits wide (wchar_t may be signed or unsigned)
326 * or else to be uint32_t.
327 * That is, the definition of UChar32 was platform-dependent.
328 *
329 * @see U_SENTINEL
330 * @stable ICU 2.4
331 */
332typedef int32_t UChar32;
333
b75a7d8f 334/**
4388f060
A
335 * This value is intended for sentinel values for APIs that
336 * (take or) return single code points (UChar32).
337 * It is outside of the Unicode code point range 0..0x10ffff.
338 *
339 * For example, a "done" or "error" value in a new API
340 * could be indicated with U_SENTINEL.
341 *
342 * ICU APIs designed before ICU 2.4 usually define service-specific "done"
343 * values, mostly 0xffff.
344 * Those may need to be distinguished from
345 * actual U+ffff text contents by calling functions like
346 * CharacterIterator::hasNext() or UnicodeString::length().
347 *
348 * @return -1
349 * @see UChar32
350 * @stable ICU 2.4
729e4ab9 351 */
4388f060 352#define U_SENTINEL (-1)
b75a7d8f
A
353
354#include "unicode/urename.h"
355
356#endif