| 1 |
// © 2016 and later: Unicode, Inc. and others. |
| 2 |
// License & terms of use: http://www.unicode.org/copyright.html |
| 3 |
/* |
| 4 |
****************************************************************************** |
| 5 |
* |
| 6 |
* Copyright (C) 1999-2015, International Business Machines |
| 7 |
* Corporation and others. All Rights Reserved. |
| 8 |
* |
| 9 |
****************************************************************************** |
| 10 |
* file name: umachine.h |
| 11 |
* encoding: UTF-8 |
| 12 |
* tab size: 8 (not used) |
| 13 |
* indentation:4 |
| 14 |
* |
| 15 |
* created on: 1999sep13 |
| 16 |
* created by: Markus W. Scherer |
| 17 |
* |
| 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. |
| 23 |
*/ |
| 24 |
|
| 25 |
#ifndef __UMACHINE_H__ |
| 26 |
#define __UMACHINE_H__ |
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* \file |
| 31 |
* \brief Basic types and constants for UTF |
| 32 |
* |
| 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. |
| 39 |
* |
| 40 |
*/ |
| 41 |
/*==========================================================================*/ |
| 42 |
/* Include platform-dependent definitions */ |
| 43 |
/* which are contained in the platform-specific file platform.h */ |
| 44 |
/*==========================================================================*/ |
| 45 |
|
| 46 |
#include "unicode/ptypes.h" /* platform.h is included in ptypes.h */ |
| 47 |
|
| 48 |
/* |
| 49 |
* ANSI C headers: |
| 50 |
* stddef.h defines wchar_t |
| 51 |
*/ |
| 52 |
#include <stdbool.h> |
| 53 |
#include <stddef.h> |
| 54 |
|
| 55 |
/*==========================================================================*/ |
| 56 |
/* For C wrappers, we use the symbol U_CAPI. */ |
| 57 |
/* This works properly if the includer is C or C++. */ |
| 58 |
/* Functions are declared U_CAPI return-type U_EXPORT2 function-name()... */ |
| 59 |
/*==========================================================================*/ |
| 60 |
|
| 61 |
/** |
| 62 |
* \def U_CFUNC |
| 63 |
* This is used in a declaration of a library private ICU C function. |
| 64 |
* @stable ICU 2.4 |
| 65 |
*/ |
| 66 |
|
| 67 |
/** |
| 68 |
* \def U_CDECL_BEGIN |
| 69 |
* This is used to begin a declaration of a library private ICU C API. |
| 70 |
* @stable ICU 2.4 |
| 71 |
*/ |
| 72 |
|
| 73 |
/** |
| 74 |
* \def U_CDECL_END |
| 75 |
* This is used to end a declaration of a library private ICU C API |
| 76 |
* @stable ICU 2.4 |
| 77 |
*/ |
| 78 |
|
| 79 |
#ifdef __cplusplus |
| 80 |
# define U_CFUNC extern "C" |
| 81 |
# define U_CDECL_BEGIN extern "C" { |
| 82 |
# define U_CDECL_END } |
| 83 |
#else |
| 84 |
# define U_CFUNC extern |
| 85 |
# define U_CDECL_BEGIN |
| 86 |
# define U_CDECL_END |
| 87 |
#endif |
| 88 |
|
| 89 |
#ifndef U_ATTRIBUTE_DEPRECATED |
| 90 |
/** |
| 91 |
* \def U_ATTRIBUTE_DEPRECATED |
| 92 |
* This is used for GCC specific attributes |
| 93 |
* @internal |
| 94 |
*/ |
| 95 |
#if U_GCC_MAJOR_MINOR >= 302 |
| 96 |
# define U_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated)) |
| 97 |
/** |
| 98 |
* \def U_ATTRIBUTE_DEPRECATED |
| 99 |
* This is used for Visual C++ specific attributes |
| 100 |
* @internal |
| 101 |
*/ |
| 102 |
#elif defined(_MSC_VER) && (_MSC_VER >= 1400) |
| 103 |
# define U_ATTRIBUTE_DEPRECATED __declspec(deprecated) |
| 104 |
#else |
| 105 |
# define U_ATTRIBUTE_DEPRECATED |
| 106 |
#endif |
| 107 |
#endif |
| 108 |
|
| 109 |
/** This is used to declare a function as a public ICU C API @stable ICU 2.0*/ |
| 110 |
#define U_CAPI U_CFUNC U_EXPORT |
| 111 |
/** Obsolete/same as U_CAPI; was used to declare a function as a stable public ICU C API*/ |
| 112 |
#define U_STABLE U_CAPI |
| 113 |
/** Obsolete/same as U_CAPI; was used to declare a function as a draft public ICU C API */ |
| 114 |
#define U_DRAFT U_CAPI |
| 115 |
/** This is used to declare a function as a deprecated public ICU C API */ |
| 116 |
#define U_DEPRECATED U_CAPI U_ATTRIBUTE_DEPRECATED |
| 117 |
/** Obsolete/same as U_CAPI; was used to declare a function as an obsolete public ICU C API */ |
| 118 |
#define U_OBSOLETE U_CAPI |
| 119 |
/** Obsolete/same as U_CAPI; was used to declare a function as an internal ICU C API */ |
| 120 |
#define U_INTERNAL U_CAPI |
| 121 |
|
| 122 |
// Before ICU 65, function-like, multi-statement ICU macros were just defined as |
| 123 |
// series of statements wrapped in { } blocks and the caller could choose to |
| 124 |
// either treat them as if they were actual functions and end the invocation |
| 125 |
// with a trailing ; creating an empty statement after the block or else omit |
| 126 |
// this trailing ; using the knowledge that the macro would expand to { }. |
| 127 |
// |
| 128 |
// But doing so doesn't work well with macros that look like functions and |
| 129 |
// compiler warnings about empty statements (ICU-20601) and ICU 65 therefore |
| 130 |
// switches to the standard solution of wrapping such macros in do { } while. |
| 131 |
// |
| 132 |
// This will however break existing code that depends on being able to invoke |
| 133 |
// these macros without a trailing ; so to be able to remain compatible with |
| 134 |
// such code the wrapper is itself defined as macros so that it's possible to |
| 135 |
// build ICU 65 and later with the old macro behaviour, like this: |
| 136 |
// |
| 137 |
// export CPPFLAGS='-DUPRV_BLOCK_MACRO_BEGIN="" -DUPRV_BLOCK_MACRO_END=""' |
| 138 |
// runConfigureICU ... |
| 139 |
// |
| 140 |
|
| 141 |
/** |
| 142 |
* \def UPRV_BLOCK_MACRO_BEGIN |
| 143 |
* Defined as the "do" keyword by default. |
| 144 |
* @internal |
| 145 |
*/ |
| 146 |
#ifndef UPRV_BLOCK_MACRO_BEGIN |
| 147 |
#define UPRV_BLOCK_MACRO_BEGIN do |
| 148 |
#endif |
| 149 |
|
| 150 |
/** |
| 151 |
* \def UPRV_BLOCK_MACRO_END |
| 152 |
* Defined as "while (false)" by default. |
| 153 |
* @internal |
| 154 |
*/ |
| 155 |
#ifndef UPRV_BLOCK_MACRO_END |
| 156 |
#define UPRV_BLOCK_MACRO_END while (false) |
| 157 |
#endif |
| 158 |
|
| 159 |
/*==========================================================================*/ |
| 160 |
/* limits for int32_t etc., like in POSIX inttypes.h */ |
| 161 |
/*==========================================================================*/ |
| 162 |
|
| 163 |
#ifndef INT8_MIN |
| 164 |
/** The smallest value an 8 bit signed integer can hold @stable ICU 2.0 */ |
| 165 |
# define INT8_MIN ((int8_t)(-128)) |
| 166 |
#endif |
| 167 |
#ifndef INT16_MIN |
| 168 |
/** The smallest value a 16 bit signed integer can hold @stable ICU 2.0 */ |
| 169 |
# define INT16_MIN ((int16_t)(-32767-1)) |
| 170 |
#endif |
| 171 |
#ifndef INT32_MIN |
| 172 |
/** The smallest value a 32 bit signed integer can hold @stable ICU 2.0 */ |
| 173 |
# define INT32_MIN ((int32_t)(-2147483647-1)) |
| 174 |
#endif |
| 175 |
|
| 176 |
#ifndef INT8_MAX |
| 177 |
/** The largest value an 8 bit signed integer can hold @stable ICU 2.0 */ |
| 178 |
# define INT8_MAX ((int8_t)(127)) |
| 179 |
#endif |
| 180 |
#ifndef INT16_MAX |
| 181 |
/** The largest value a 16 bit signed integer can hold @stable ICU 2.0 */ |
| 182 |
# define INT16_MAX ((int16_t)(32767)) |
| 183 |
#endif |
| 184 |
#ifndef INT32_MAX |
| 185 |
/** The largest value a 32 bit signed integer can hold @stable ICU 2.0 */ |
| 186 |
# define INT32_MAX ((int32_t)(2147483647)) |
| 187 |
#endif |
| 188 |
|
| 189 |
#ifndef UINT8_MAX |
| 190 |
/** The largest value an 8 bit unsigned integer can hold @stable ICU 2.0 */ |
| 191 |
# define UINT8_MAX ((uint8_t)(255U)) |
| 192 |
#endif |
| 193 |
#ifndef UINT16_MAX |
| 194 |
/** The largest value a 16 bit unsigned integer can hold @stable ICU 2.0 */ |
| 195 |
# define UINT16_MAX ((uint16_t)(65535U)) |
| 196 |
#endif |
| 197 |
#ifndef UINT32_MAX |
| 198 |
/** The largest value a 32 bit unsigned integer can hold @stable ICU 2.0 */ |
| 199 |
# define UINT32_MAX ((uint32_t)(4294967295U)) |
| 200 |
#endif |
| 201 |
|
| 202 |
#if defined(U_INT64_T_UNAVAILABLE) |
| 203 |
# error int64_t is required for decimal format and rule-based number format. |
| 204 |
#else |
| 205 |
# ifndef INT64_C |
| 206 |
/** |
| 207 |
* Provides a platform independent way to specify a signed 64-bit integer constant. |
| 208 |
* note: may be wrong for some 64 bit platforms - ensure your compiler provides INT64_C |
| 209 |
* @stable ICU 2.8 |
| 210 |
*/ |
| 211 |
# define INT64_C(c) c ## LL |
| 212 |
# endif |
| 213 |
# ifndef UINT64_C |
| 214 |
/** |
| 215 |
* Provides a platform independent way to specify an unsigned 64-bit integer constant. |
| 216 |
* note: may be wrong for some 64 bit platforms - ensure your compiler provides UINT64_C |
| 217 |
* @stable ICU 2.8 |
| 218 |
*/ |
| 219 |
# define UINT64_C(c) c ## ULL |
| 220 |
# endif |
| 221 |
# ifndef U_INT64_MIN |
| 222 |
/** The smallest value a 64 bit signed integer can hold @stable ICU 2.8 */ |
| 223 |
# define U_INT64_MIN ((int64_t)(INT64_C(-9223372036854775807)-1)) |
| 224 |
# endif |
| 225 |
# ifndef U_INT64_MAX |
| 226 |
/** The largest value a 64 bit signed integer can hold @stable ICU 2.8 */ |
| 227 |
# define U_INT64_MAX ((int64_t)(INT64_C(9223372036854775807))) |
| 228 |
# endif |
| 229 |
# ifndef U_UINT64_MAX |
| 230 |
/** The largest value a 64 bit unsigned integer can hold @stable ICU 2.8 */ |
| 231 |
# define U_UINT64_MAX ((uint64_t)(UINT64_C(18446744073709551615))) |
| 232 |
# endif |
| 233 |
#endif |
| 234 |
|
| 235 |
/*==========================================================================*/ |
| 236 |
/* Boolean data type */ |
| 237 |
/*==========================================================================*/ |
| 238 |
|
| 239 |
/** |
| 240 |
* The ICU boolean type, a signed-byte integer. |
| 241 |
* ICU-specific for historical reasons: The C and C++ standards used to not define type bool. |
| 242 |
* Also provides a fixed type definition, as opposed to |
| 243 |
* type bool whose details (e.g., sizeof) may vary by compiler and between C and C++. |
| 244 |
* |
| 245 |
* @stable ICU 2.0 |
| 246 |
*/ |
| 247 |
typedef int8_t UBool; |
| 248 |
|
| 249 |
/** |
| 250 |
* \def U_DEFINE_FALSE_AND_TRUE |
| 251 |
* Normally turns off defining macros FALSE=0 & TRUE=1 in public ICU headers. |
| 252 |
* These obsolete macros sometimes break compilation of other code that |
| 253 |
* defines enum constants or similar with these names. |
| 254 |
* C++ has long defined bool/false/true. |
| 255 |
* C99 also added definitions for these, although as macros; see stdbool.h. |
| 256 |
* |
| 257 |
* You may transitionally define U_DEFINE_FALSE_AND_TRUE=1 if you need time to migrate code. |
| 258 |
* |
| 259 |
* @internal ICU 68 |
| 260 |
*/ |
| 261 |
#ifdef U_DEFINE_FALSE_AND_TRUE |
| 262 |
// Use the predefined value. |
| 263 |
#else |
| 264 |
// Default to avoiding collision with non-macro definitions of FALSE & TRUE. |
| 265 |
# define U_DEFINE_FALSE_AND_TRUE 0 |
| 266 |
#endif |
| 267 |
|
| 268 |
#if U_DEFINE_FALSE_AND_TRUE || defined(U_IN_DOXYGEN) |
| 269 |
#ifndef TRUE |
| 270 |
/** |
| 271 |
* The TRUE value of a UBool. |
| 272 |
* |
| 273 |
* @deprecated ICU 68 Use standard "true" instead. |
| 274 |
*/ |
| 275 |
# define TRUE 1 |
| 276 |
#endif |
| 277 |
#ifndef FALSE |
| 278 |
/** |
| 279 |
* The FALSE value of a UBool. |
| 280 |
* |
| 281 |
* @deprecated ICU 68 Use standard "false" instead. |
| 282 |
*/ |
| 283 |
# define FALSE 0 |
| 284 |
#endif |
| 285 |
#endif // U_DEFINE_FALSE_AND_TRUE |
| 286 |
|
| 287 |
/*==========================================================================*/ |
| 288 |
/* Unicode data types */ |
| 289 |
/*==========================================================================*/ |
| 290 |
|
| 291 |
/* wchar_t-related definitions -------------------------------------------- */ |
| 292 |
|
| 293 |
/* |
| 294 |
* \def U_WCHAR_IS_UTF16 |
| 295 |
* Defined if wchar_t uses UTF-16. |
| 296 |
* |
| 297 |
* @stable ICU 2.0 |
| 298 |
*/ |
| 299 |
/* |
| 300 |
* \def U_WCHAR_IS_UTF32 |
| 301 |
* Defined if wchar_t uses UTF-32. |
| 302 |
* |
| 303 |
* @stable ICU 2.0 |
| 304 |
*/ |
| 305 |
#if !defined(U_WCHAR_IS_UTF16) && !defined(U_WCHAR_IS_UTF32) |
| 306 |
# ifdef __STDC_ISO_10646__ |
| 307 |
# if (U_SIZEOF_WCHAR_T==2) |
| 308 |
# define U_WCHAR_IS_UTF16 |
| 309 |
# elif (U_SIZEOF_WCHAR_T==4) |
| 310 |
# define U_WCHAR_IS_UTF32 |
| 311 |
# endif |
| 312 |
# elif defined __UCS2__ |
| 313 |
# if (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400) && (U_SIZEOF_WCHAR_T==2) |
| 314 |
# define U_WCHAR_IS_UTF16 |
| 315 |
# endif |
| 316 |
# elif defined(__UCS4__) || (U_PLATFORM == U_PF_OS400 && defined(__UTF32__)) |
| 317 |
# if (U_SIZEOF_WCHAR_T==4) |
| 318 |
# define U_WCHAR_IS_UTF32 |
| 319 |
# endif |
| 320 |
# elif U_PLATFORM_IS_DARWIN_BASED || (U_SIZEOF_WCHAR_T==4 && U_PLATFORM_IS_LINUX_BASED) |
| 321 |
# define U_WCHAR_IS_UTF32 |
| 322 |
# elif U_PLATFORM_HAS_WIN32_API |
| 323 |
# define U_WCHAR_IS_UTF16 |
| 324 |
# endif |
| 325 |
#endif |
| 326 |
|
| 327 |
/* UChar and UChar32 definitions -------------------------------------------- */ |
| 328 |
|
| 329 |
/** Number of bytes in a UChar (always 2). @stable ICU 2.0 */ |
| 330 |
#define U_SIZEOF_UCHAR 2 |
| 331 |
|
| 332 |
/** |
| 333 |
* \def U_CHAR16_IS_TYPEDEF |
| 334 |
* If 1, then char16_t is a typedef and not a real type (yet) |
| 335 |
* @internal |
| 336 |
*/ |
| 337 |
#if defined(_MSC_VER) && (_MSC_VER < 1900) |
| 338 |
// Versions of Visual Studio/MSVC below 2015 do not support char16_t as a real type, |
| 339 |
// and instead use a typedef. https://msdn.microsoft.com/library/bb531344.aspx |
| 340 |
# define U_CHAR16_IS_TYPEDEF 1 |
| 341 |
#else |
| 342 |
# define U_CHAR16_IS_TYPEDEF 0 |
| 343 |
#endif |
| 344 |
|
| 345 |
|
| 346 |
/** |
| 347 |
* \var UChar |
| 348 |
* |
| 349 |
* The base type for UTF-16 code units and pointers. |
| 350 |
* Unsigned 16-bit integer. |
| 351 |
* Starting with ICU 59, C++ API uses char16_t directly, while C API continues to use UChar. |
| 352 |
* |
| 353 |
* UChar is configurable by defining the macro UCHAR_TYPE |
| 354 |
* on the preprocessor or compiler command line: |
| 355 |
* -DUCHAR_TYPE=uint16_t or -DUCHAR_TYPE=wchar_t (if U_SIZEOF_WCHAR_T==2) etc. |
| 356 |
* (The UCHAR_TYPE can also be \#defined earlier in this file, for outside the ICU library code.) |
| 357 |
* This is for transitional use from application code that uses uint16_t or wchar_t for UTF-16. |
| 358 |
* |
| 359 |
* The default is UChar=char16_t. |
| 360 |
* |
| 361 |
* C++11 defines char16_t as bit-compatible with uint16_t, but as a distinct type. |
| 362 |
* |
| 363 |
* In C, char16_t is a simple typedef of uint_least16_t. |
| 364 |
* ICU requires uint_least16_t=uint16_t for data memory mapping. |
| 365 |
* On macOS, char16_t is not available because the uchar.h standard header is missing. |
| 366 |
* |
| 367 |
* @stable ICU 4.4 |
| 368 |
*/ |
| 369 |
|
| 370 |
#if 1 |
| 371 |
// #if 1 is normal. UChar defaults to char16_t in C++. |
| 372 |
// For configuration testing of UChar=uint16_t temporarily change this to #if 0. |
| 373 |
#else |
| 374 |
# define UCHAR_TYPE uint16_t |
| 375 |
#endif |
| 376 |
|
| 377 |
#if defined(U_ALL_IMPLEMENTATION) || !defined(UCHAR_TYPE) |
| 378 |
typedef char16_t UChar; |
| 379 |
#else |
| 380 |
typedef UCHAR_TYPE UChar; |
| 381 |
#endif |
| 382 |
|
| 383 |
/** |
| 384 |
* \var OldUChar |
| 385 |
* Default ICU 58 definition of UChar. |
| 386 |
* A base type for UTF-16 code units and pointers. |
| 387 |
* Unsigned 16-bit integer. |
| 388 |
* |
| 389 |
* Define OldUChar to be wchar_t if that is 16 bits wide. |
| 390 |
* If wchar_t is not 16 bits wide, then define UChar to be uint16_t. |
| 391 |
* |
| 392 |
* This makes the definition of OldUChar platform-dependent |
| 393 |
* but allows direct string type compatibility with platforms with |
| 394 |
* 16-bit wchar_t types. |
| 395 |
* |
| 396 |
* This is how UChar was defined in ICU 58, for transition convenience. |
| 397 |
* Exception: ICU 58 UChar was defined to UCHAR_TYPE if that macro was defined. |
| 398 |
* The current UChar responds to UCHAR_TYPE but OldUChar does not. |
| 399 |
* |
| 400 |
* @stable ICU 59 |
| 401 |
*/ |
| 402 |
#if U_SIZEOF_WCHAR_T==2 |
| 403 |
typedef wchar_t OldUChar; |
| 404 |
#elif defined(__CHAR16_TYPE__) |
| 405 |
typedef __CHAR16_TYPE__ OldUChar; |
| 406 |
#else |
| 407 |
typedef uint16_t OldUChar; |
| 408 |
#endif |
| 409 |
|
| 410 |
/** |
| 411 |
* Define UChar32 as a type for single Unicode code points. |
| 412 |
* UChar32 is a signed 32-bit integer (same as int32_t). |
| 413 |
* |
| 414 |
* The Unicode code point range is 0..0x10ffff. |
| 415 |
* All other values (negative or >=0x110000) are illegal as Unicode code points. |
| 416 |
* They may be used as sentinel values to indicate "done", "error" |
| 417 |
* or similar non-code point conditions. |
| 418 |
* |
| 419 |
* Before ICU 2.4 (Jitterbug 2146), UChar32 was defined |
| 420 |
* to be wchar_t if that is 32 bits wide (wchar_t may be signed or unsigned) |
| 421 |
* or else to be uint32_t. |
| 422 |
* That is, the definition of UChar32 was platform-dependent. |
| 423 |
* |
| 424 |
* @see U_SENTINEL |
| 425 |
* @stable ICU 2.4 |
| 426 |
*/ |
| 427 |
typedef int32_t UChar32; |
| 428 |
|
| 429 |
/** |
| 430 |
* This value is intended for sentinel values for APIs that |
| 431 |
* (take or) return single code points (UChar32). |
| 432 |
* It is outside of the Unicode code point range 0..0x10ffff. |
| 433 |
* |
| 434 |
* For example, a "done" or "error" value in a new API |
| 435 |
* could be indicated with U_SENTINEL. |
| 436 |
* |
| 437 |
* ICU APIs designed before ICU 2.4 usually define service-specific "done" |
| 438 |
* values, mostly 0xffff. |
| 439 |
* Those may need to be distinguished from |
| 440 |
* actual U+ffff text contents by calling functions like |
| 441 |
* CharacterIterator::hasNext() or UnicodeString::length(). |
| 442 |
* |
| 443 |
* @return -1 |
| 444 |
* @see UChar32 |
| 445 |
* @stable ICU 2.4 |
| 446 |
*/ |
| 447 |
#define U_SENTINEL (-1) |
| 448 |
|
| 449 |
#include "unicode/urename.h" |
| 450 |
|
| 451 |
#endif |