]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/umachine.h
f0c314ad3bac28e69318b9f105815d2c8ebced80
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 1999-2015, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
10 * file name: umachine.h
12 * tab size: 8 (not used)
15 * created on: 1999sep13
16 * created by: Markus W. Scherer
18 * This file defines basic types and constants for ICU to be
19 * platform-independent. umachine.h and utf.h are included into
20 * utypes.h to provide all the general definitions for ICU.
21 * All of these definitions used to be in utypes.h before
22 * the UTF-handling macros made this unmaintainable.
25 #ifndef __UMACHINE_H__
26 #define __UMACHINE_H__
31 * \brief Basic types and constants for UTF
33 * <h2> Basic types and constants for UTF </h2>
34 * This file defines basic types and constants for utf.h to be
35 * platform-independent. umachine.h and utf.h are included into
36 * utypes.h to provide all the general definitions for ICU.
37 * All of these definitions used to be in utypes.h before
38 * the UTF-handling macros made this unmaintainable.
41 /*==========================================================================*/
42 /* Include platform-dependent definitions */
43 /* which are contained in the platform-specific file platform.h */
44 /*==========================================================================*/
46 #include "unicode/ptypes.h" /* platform.h is included in ptypes.h */
50 * stddef.h defines wchar_t
54 /*==========================================================================*/
55 /* For C wrappers, we use the symbol U_STABLE. */
56 /* This works properly if the includer is C or C++. */
57 /* Functions are declared U_STABLE return-type U_EXPORT2 function-name()... */
58 /*==========================================================================*/
62 * This is used in a declaration of a library private ICU C function.
68 * This is used to begin a declaration of a library private ICU C API.
74 * This is used to end a declaration of a library private ICU C API
79 # define U_CFUNC extern "C"
80 # define U_CDECL_BEGIN extern "C" {
81 # define U_CDECL_END }
83 # define U_CFUNC extern
84 # define U_CDECL_BEGIN
88 #ifndef U_ATTRIBUTE_DEPRECATED
90 * \def U_ATTRIBUTE_DEPRECATED
91 * This is used for GCC specific attributes
94 #if U_GCC_MAJOR_MINOR >= 302
95 # define U_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated))
97 * \def U_ATTRIBUTE_DEPRECATED
98 * This is used for Visual C++ specific attributes
101 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
102 # define U_ATTRIBUTE_DEPRECATED __declspec(deprecated)
104 # define U_ATTRIBUTE_DEPRECATED
108 /** This is used to declare a function as a public ICU C API @stable ICU 2.0*/
109 #define U_CAPI U_CFUNC U_EXPORT
110 /** This is used to declare a function as a stable public ICU C API*/
111 #define U_STABLE U_CAPI
112 /** This is used to declare a function as a draft public ICU C API */
113 #define U_DRAFT U_CAPI
114 /** This is used to declare a function as a deprecated public ICU C API */
115 #define U_DEPRECATED U_CAPI U_ATTRIBUTE_DEPRECATED
116 /** This is used to declare a function as an obsolete public ICU C API */
117 #define U_OBSOLETE U_CAPI
118 /** This is used to declare a function as an internal ICU C API */
119 #define U_INTERNAL U_CAPI
123 * Defined to the C++11 "override" keyword if available.
124 * Denotes a class or member which is an override of the base class.
125 * May result in an error if it applied to something not an override.
129 #define U_OVERRIDE override
134 * Defined to the C++11 "final" keyword if available.
135 * Denotes a class or member which may not be overridden in subclasses.
136 * May result in an error if subclasses attempt to override.
139 #if !defined(U_FINAL) || defined(U_IN_DOXYGEN)
140 #define U_FINAL final
143 // Before ICU 65, function-like, multi-statement ICU macros were just defined as
144 // series of statements wrapped in { } blocks and the caller could choose to
145 // either treat them as if they were actual functions and end the invocation
146 // with a trailing ; creating an empty statement after the block or else omit
147 // this trailing ; using the knowledge that the macro would expand to { }.
149 // But doing so doesn't work well with macros that look like functions and
150 // compiler warnings about empty statements (ICU-20601) and ICU 65 therefore
151 // switches to the standard solution of wrapping such macros in do { } while.
153 // This will however break existing code that depends on being able to invoke
154 // these macros without a trailing ; so to be able to remain compatible with
155 // such code the wrapper is itself defined as macros so that it's possible to
156 // build ICU 65 and later with the old macro behaviour, like this:
158 // export CPPFLAGS='-DUPRV_BLOCK_MACRO_BEGIN="" -DUPRV_BLOCK_MACRO_END=""'
159 // runConfigureICU ...
163 * \def UPRV_BLOCK_MACRO_BEGIN
164 * Defined as the "do" keyword by default.
167 #ifndef UPRV_BLOCK_MACRO_BEGIN
168 #define UPRV_BLOCK_MACRO_BEGIN do
172 * \def UPRV_BLOCK_MACRO_END
173 * Defined as "while (FALSE)" by default.
176 #ifndef UPRV_BLOCK_MACRO_END
177 #define UPRV_BLOCK_MACRO_END while (FALSE)
180 /*==========================================================================*/
181 /* limits for int32_t etc., like in POSIX inttypes.h */
182 /*==========================================================================*/
185 /** The smallest value an 8 bit signed integer can hold @stable ICU 2.0 */
186 # define INT8_MIN ((int8_t)(-128))
189 /** The smallest value a 16 bit signed integer can hold @stable ICU 2.0 */
190 # define INT16_MIN ((int16_t)(-32767-1))
193 /** The smallest value a 32 bit signed integer can hold @stable ICU 2.0 */
194 # define INT32_MIN ((int32_t)(-2147483647-1))
198 /** The largest value an 8 bit signed integer can hold @stable ICU 2.0 */
199 # define INT8_MAX ((int8_t)(127))
202 /** The largest value a 16 bit signed integer can hold @stable ICU 2.0 */
203 # define INT16_MAX ((int16_t)(32767))
206 /** The largest value a 32 bit signed integer can hold @stable ICU 2.0 */
207 # define INT32_MAX ((int32_t)(2147483647))
211 /** The largest value an 8 bit unsigned integer can hold @stable ICU 2.0 */
212 # define UINT8_MAX ((uint8_t)(255U))
215 /** The largest value a 16 bit unsigned integer can hold @stable ICU 2.0 */
216 # define UINT16_MAX ((uint16_t)(65535U))
219 /** The largest value a 32 bit unsigned integer can hold @stable ICU 2.0 */
220 # define UINT32_MAX ((uint32_t)(4294967295U))
223 #if defined(U_INT64_T_UNAVAILABLE)
224 # error int64_t is required for decimal format and rule-based number format.
228 * Provides a platform independent way to specify a signed 64-bit integer constant.
229 * note: may be wrong for some 64 bit platforms - ensure your compiler provides INT64_C
232 # define INT64_C(c) c ## LL
236 * Provides a platform independent way to specify an unsigned 64-bit integer constant.
237 * note: may be wrong for some 64 bit platforms - ensure your compiler provides UINT64_C
240 # define UINT64_C(c) c ## ULL
243 /** The smallest value a 64 bit signed integer can hold @stable ICU 2.8 */
244 # define U_INT64_MIN ((int64_t)(INT64_C(-9223372036854775807)-1))
247 /** The largest value a 64 bit signed integer can hold @stable ICU 2.8 */
248 # define U_INT64_MAX ((int64_t)(INT64_C(9223372036854775807)))
250 # ifndef U_UINT64_MAX
251 /** The largest value a 64 bit unsigned integer can hold @stable ICU 2.8 */
252 # define U_UINT64_MAX ((uint64_t)(UINT64_C(18446744073709551615)))
256 /*==========================================================================*/
257 /* Boolean data type */
258 /*==========================================================================*/
260 /** The ICU boolean type @stable ICU 2.0 */
261 typedef int8_t UBool
;
264 /** The TRUE value of a UBool @stable ICU 2.0 */
268 /** The FALSE value of a UBool @stable ICU 2.0 */
273 /*==========================================================================*/
274 /* Unicode data types */
275 /*==========================================================================*/
277 /* wchar_t-related definitions -------------------------------------------- */
280 * \def U_WCHAR_IS_UTF16
281 * Defined if wchar_t uses UTF-16.
286 * \def U_WCHAR_IS_UTF32
287 * Defined if wchar_t uses UTF-32.
291 #if !defined(U_WCHAR_IS_UTF16) && !defined(U_WCHAR_IS_UTF32)
292 # ifdef __STDC_ISO_10646__
293 # if (U_SIZEOF_WCHAR_T==2)
294 # define U_WCHAR_IS_UTF16
295 # elif (U_SIZEOF_WCHAR_T==4)
296 # define U_WCHAR_IS_UTF32
298 # elif defined __UCS2__
299 # if (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400) && (U_SIZEOF_WCHAR_T==2)
300 # define U_WCHAR_IS_UTF16
302 # elif defined(__UCS4__) || (U_PLATFORM == U_PF_OS400 && defined(__UTF32__))
303 # if (U_SIZEOF_WCHAR_T==4)
304 # define U_WCHAR_IS_UTF32
306 # elif U_PLATFORM_IS_DARWIN_BASED || (U_SIZEOF_WCHAR_T==4 && U_PLATFORM_IS_LINUX_BASED)
307 # define U_WCHAR_IS_UTF32
308 # elif U_PLATFORM_HAS_WIN32_API
309 # define U_WCHAR_IS_UTF16
313 /* UChar and UChar32 definitions -------------------------------------------- */
315 /** Number of bytes in a UChar. @stable ICU 2.0 */
316 #define U_SIZEOF_UCHAR 2
319 * \def U_CHAR16_IS_TYPEDEF
320 * If 1, then char16_t is a typedef and not a real type (yet)
323 #if (U_PLATFORM == U_PF_AIX) && defined(__cplusplus) &&(U_CPLUSPLUS_VERSION < 11)
324 // for AIX, uchar.h needs to be included
326 # define U_CHAR16_IS_TYPEDEF 1
327 #elif defined(_MSC_VER) && (_MSC_VER < 1900)
328 // Versions of Visual Studio/MSVC below 2015 do not support char16_t as a real type,
329 // and instead use a typedef. https://msdn.microsoft.com/library/bb531344.aspx
330 # define U_CHAR16_IS_TYPEDEF 1
332 # define U_CHAR16_IS_TYPEDEF 0
339 * The base type for UTF-16 code units and pointers.
340 * Unsigned 16-bit integer.
341 * Starting with ICU 59, C++ API uses char16_t directly, while C API continues to use UChar.
343 * UChar is configurable by defining the macro UCHAR_TYPE
344 * on the preprocessor or compiler command line:
345 * -DUCHAR_TYPE=uint16_t or -DUCHAR_TYPE=wchar_t (if U_SIZEOF_WCHAR_T==2) etc.
346 * (The UCHAR_TYPE can also be \#defined earlier in this file, for outside the ICU library code.)
347 * This is for transitional use from application code that uses uint16_t or wchar_t for UTF-16.
349 * The default is UChar=char16_t.
351 * C++11 defines char16_t as bit-compatible with uint16_t, but as a distinct type.
353 * In C, char16_t is a simple typedef of uint_least16_t.
354 * ICU requires uint_least16_t=uint16_t for data memory mapping.
355 * On macOS, char16_t is not available because the uchar.h standard header is missing.
361 // #if 1 is normal. UChar defaults to char16_t in C++.
362 // For configuration testing of UChar=uint16_t temporarily change this to #if 0.
363 // The intltest Makefile #defines UCHAR_TYPE=char16_t,
364 // so we only #define it to uint16_t if it is undefined so far.
365 #elif !defined(UCHAR_TYPE)
366 # define UCHAR_TYPE uint16_t
369 #if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || \
370 defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
371 // Inside the ICU library code, never configurable.
372 typedef char16_t UChar
;
373 #elif defined(UCHAR_TYPE)
374 typedef UCHAR_TYPE UChar
;
375 #elif defined(__cplusplus)
376 typedef char16_t UChar
;
378 typedef uint16_t UChar
;
383 * Default ICU 58 definition of UChar.
384 * A base type for UTF-16 code units and pointers.
385 * Unsigned 16-bit integer.
387 * Define OldUChar to be wchar_t if that is 16 bits wide.
388 * If wchar_t is not 16 bits wide, then define UChar to be uint16_t.
390 * This makes the definition of OldUChar platform-dependent
391 * but allows direct string type compatibility with platforms with
392 * 16-bit wchar_t types.
394 * This is how UChar was defined in ICU 58, for transition convenience.
395 * Exception: ICU 58 UChar was defined to UCHAR_TYPE if that macro was defined.
396 * The current UChar responds to UCHAR_TYPE but OldUChar does not.
400 #if U_SIZEOF_WCHAR_T==2
401 typedef wchar_t OldUChar
;
402 #elif defined(__CHAR16_TYPE__)
403 typedef __CHAR16_TYPE__ OldUChar
;
405 typedef uint16_t OldUChar
;
409 * Define UChar32 as a type for single Unicode code points.
410 * UChar32 is a signed 32-bit integer (same as int32_t).
412 * The Unicode code point range is 0..0x10ffff.
413 * All other values (negative or >=0x110000) are illegal as Unicode code points.
414 * They may be used as sentinel values to indicate "done", "error"
415 * or similar non-code point conditions.
417 * Before ICU 2.4 (Jitterbug 2146), UChar32 was defined
418 * to be wchar_t if that is 32 bits wide (wchar_t may be signed or unsigned)
419 * or else to be uint32_t.
420 * That is, the definition of UChar32 was platform-dependent.
425 typedef int32_t UChar32
;
428 * This value is intended for sentinel values for APIs that
429 * (take or) return single code points (UChar32).
430 * It is outside of the Unicode code point range 0..0x10ffff.
432 * For example, a "done" or "error" value in a new API
433 * could be indicated with U_SENTINEL.
435 * ICU APIs designed before ICU 2.4 usually define service-specific "done"
436 * values, mostly 0xffff.
437 * Those may need to be distinguished from
438 * actual U+ffff text contents by calling functions like
439 * CharacterIterator::hasNext() or UnicodeString::length().
445 #define U_SENTINEL (-1)
447 #include "unicode/urename.h"