|
|
|||
File indexing completed on 2025-12-15 10:31:18
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ****************************************************************************** 0005 * 0006 * Copyright (C) 1999-2015, International Business Machines 0007 * Corporation and others. All Rights Reserved. 0008 * 0009 ****************************************************************************** 0010 * file name: umachine.h 0011 * encoding: UTF-8 0012 * tab size: 8 (not used) 0013 * indentation:4 0014 * 0015 * created on: 1999sep13 0016 * created by: Markus W. Scherer 0017 * 0018 * This file defines basic types and constants for ICU to be 0019 * platform-independent. umachine.h and utf.h are included into 0020 * utypes.h to provide all the general definitions for ICU. 0021 * All of these definitions used to be in utypes.h before 0022 * the UTF-handling macros made this unmaintainable. 0023 */ 0024 0025 #ifndef __UMACHINE_H__ 0026 #define __UMACHINE_H__ 0027 0028 0029 /** 0030 * \file 0031 * \brief Basic types and constants for UTF 0032 * 0033 * <h2> Basic types and constants for UTF </h2> 0034 * This file defines basic types and constants for utf.h to be 0035 * platform-independent. umachine.h and utf.h are included into 0036 * utypes.h to provide all the general definitions for ICU. 0037 * All of these definitions used to be in utypes.h before 0038 * the UTF-handling macros made this unmaintainable. 0039 * 0040 */ 0041 /*==========================================================================*/ 0042 /* Include platform-dependent definitions */ 0043 /* which are contained in the platform-specific file platform.h */ 0044 /*==========================================================================*/ 0045 0046 #include "unicode/ptypes.h" /* platform.h is included in ptypes.h */ 0047 0048 /* 0049 * ANSI C headers: 0050 * stddef.h defines wchar_t 0051 */ 0052 #include <stdbool.h> 0053 #include <stddef.h> 0054 0055 /*==========================================================================*/ 0056 /* For C wrappers, we use the symbol U_CAPI. */ 0057 /* This works properly if the includer is C or C++. */ 0058 /* Functions are declared U_CAPI return-type U_EXPORT2 function-name()... */ 0059 /*==========================================================================*/ 0060 0061 /** 0062 * \def U_CFUNC 0063 * This is used in a declaration of a library private ICU C function. 0064 * @stable ICU 2.4 0065 */ 0066 0067 /** 0068 * \def U_CDECL_BEGIN 0069 * This is used to begin a declaration of a library private ICU C API. 0070 * @stable ICU 2.4 0071 */ 0072 0073 /** 0074 * \def U_CDECL_END 0075 * This is used to end a declaration of a library private ICU C API 0076 * @stable ICU 2.4 0077 */ 0078 0079 #ifdef __cplusplus 0080 # define U_CFUNC extern "C" 0081 # define U_CDECL_BEGIN extern "C" { 0082 # define U_CDECL_END } 0083 #else 0084 # define U_CFUNC extern 0085 # define U_CDECL_BEGIN 0086 # define U_CDECL_END 0087 #endif 0088 0089 #ifndef U_ATTRIBUTE_DEPRECATED 0090 /** 0091 * \def U_ATTRIBUTE_DEPRECATED 0092 * This is used for GCC specific attributes 0093 * @internal 0094 */ 0095 #if U_GCC_MAJOR_MINOR >= 302 0096 # define U_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated)) 0097 /** 0098 * \def U_ATTRIBUTE_DEPRECATED 0099 * This is used for Visual C++ specific attributes 0100 * @internal 0101 */ 0102 #elif defined(_MSC_VER) && (_MSC_VER >= 1400) 0103 # define U_ATTRIBUTE_DEPRECATED __declspec(deprecated) 0104 #else 0105 # define U_ATTRIBUTE_DEPRECATED 0106 #endif 0107 #endif 0108 0109 /** This is used to declare a function as a public ICU C API @stable ICU 2.0*/ 0110 #define U_CAPI U_CFUNC U_EXPORT 0111 /** Obsolete/same as U_CAPI; was used to declare a function as a stable public ICU C API*/ 0112 #define U_STABLE U_CAPI 0113 /** Obsolete/same as U_CAPI; was used to declare a function as a draft public ICU C API */ 0114 #define U_DRAFT U_CAPI 0115 /** This is used to declare a function as a deprecated public ICU C API */ 0116 #define U_DEPRECATED U_CAPI U_ATTRIBUTE_DEPRECATED 0117 /** Obsolete/same as U_CAPI; was used to declare a function as an obsolete public ICU C API */ 0118 #define U_OBSOLETE U_CAPI 0119 /** Obsolete/same as U_CAPI; was used to declare a function as an internal ICU C API */ 0120 #define U_INTERNAL U_CAPI 0121 0122 // Before ICU 65, function-like, multi-statement ICU macros were just defined as 0123 // series of statements wrapped in { } blocks and the caller could choose to 0124 // either treat them as if they were actual functions and end the invocation 0125 // with a trailing ; creating an empty statement after the block or else omit 0126 // this trailing ; using the knowledge that the macro would expand to { }. 0127 // 0128 // But doing so doesn't work well with macros that look like functions and 0129 // compiler warnings about empty statements (ICU-20601) and ICU 65 therefore 0130 // switches to the standard solution of wrapping such macros in do { } while. 0131 // 0132 // This will however break existing code that depends on being able to invoke 0133 // these macros without a trailing ; so to be able to remain compatible with 0134 // such code the wrapper is itself defined as macros so that it's possible to 0135 // build ICU 65 and later with the old macro behaviour, like this: 0136 // 0137 // export CPPFLAGS='-DUPRV_BLOCK_MACRO_BEGIN="" -DUPRV_BLOCK_MACRO_END=""' 0138 // runConfigureICU ... 0139 // 0140 0141 /** 0142 * \def UPRV_BLOCK_MACRO_BEGIN 0143 * Defined as the "do" keyword by default. 0144 * @internal 0145 */ 0146 #ifndef UPRV_BLOCK_MACRO_BEGIN 0147 #define UPRV_BLOCK_MACRO_BEGIN do 0148 #endif 0149 0150 /** 0151 * \def UPRV_BLOCK_MACRO_END 0152 * Defined as "while (false)" by default. 0153 * @internal 0154 */ 0155 #ifndef UPRV_BLOCK_MACRO_END 0156 #define UPRV_BLOCK_MACRO_END while (false) 0157 #endif 0158 0159 /*==========================================================================*/ 0160 /* limits for int32_t etc., like in POSIX inttypes.h */ 0161 /*==========================================================================*/ 0162 0163 #ifndef INT8_MIN 0164 /** The smallest value an 8 bit signed integer can hold @stable ICU 2.0 */ 0165 # define INT8_MIN ((int8_t)(-128)) 0166 #endif 0167 #ifndef INT16_MIN 0168 /** The smallest value a 16 bit signed integer can hold @stable ICU 2.0 */ 0169 # define INT16_MIN ((int16_t)(-32767-1)) 0170 #endif 0171 #ifndef INT32_MIN 0172 /** The smallest value a 32 bit signed integer can hold @stable ICU 2.0 */ 0173 # define INT32_MIN ((int32_t)(-2147483647-1)) 0174 #endif 0175 0176 #ifndef INT8_MAX 0177 /** The largest value an 8 bit signed integer can hold @stable ICU 2.0 */ 0178 # define INT8_MAX ((int8_t)(127)) 0179 #endif 0180 #ifndef INT16_MAX 0181 /** The largest value a 16 bit signed integer can hold @stable ICU 2.0 */ 0182 # define INT16_MAX ((int16_t)(32767)) 0183 #endif 0184 #ifndef INT32_MAX 0185 /** The largest value a 32 bit signed integer can hold @stable ICU 2.0 */ 0186 # define INT32_MAX ((int32_t)(2147483647)) 0187 #endif 0188 0189 #ifndef UINT8_MAX 0190 /** The largest value an 8 bit unsigned integer can hold @stable ICU 2.0 */ 0191 # define UINT8_MAX ((uint8_t)(255U)) 0192 #endif 0193 #ifndef UINT16_MAX 0194 /** The largest value a 16 bit unsigned integer can hold @stable ICU 2.0 */ 0195 # define UINT16_MAX ((uint16_t)(65535U)) 0196 #endif 0197 #ifndef UINT32_MAX 0198 /** The largest value a 32 bit unsigned integer can hold @stable ICU 2.0 */ 0199 # define UINT32_MAX ((uint32_t)(4294967295U)) 0200 #endif 0201 0202 #if defined(U_INT64_T_UNAVAILABLE) 0203 # error int64_t is required for decimal format and rule-based number format. 0204 #else 0205 # ifndef INT64_C 0206 /** 0207 * Provides a platform independent way to specify a signed 64-bit integer constant. 0208 * note: may be wrong for some 64 bit platforms - ensure your compiler provides INT64_C 0209 * @stable ICU 2.8 0210 */ 0211 # define INT64_C(c) c ## LL 0212 # endif 0213 # ifndef UINT64_C 0214 /** 0215 * Provides a platform independent way to specify an unsigned 64-bit integer constant. 0216 * note: may be wrong for some 64 bit platforms - ensure your compiler provides UINT64_C 0217 * @stable ICU 2.8 0218 */ 0219 # define UINT64_C(c) c ## ULL 0220 # endif 0221 # ifndef U_INT64_MIN 0222 /** The smallest value a 64 bit signed integer can hold @stable ICU 2.8 */ 0223 # define U_INT64_MIN ((int64_t)(INT64_C(-9223372036854775807)-1)) 0224 # endif 0225 # ifndef U_INT64_MAX 0226 /** The largest value a 64 bit signed integer can hold @stable ICU 2.8 */ 0227 # define U_INT64_MAX ((int64_t)(INT64_C(9223372036854775807))) 0228 # endif 0229 # ifndef U_UINT64_MAX 0230 /** The largest value a 64 bit unsigned integer can hold @stable ICU 2.8 */ 0231 # define U_UINT64_MAX ((uint64_t)(UINT64_C(18446744073709551615))) 0232 # endif 0233 #endif 0234 0235 /*==========================================================================*/ 0236 /* Boolean data type */ 0237 /*==========================================================================*/ 0238 0239 /** 0240 * The ICU boolean type, a signed-byte integer. 0241 * ICU-specific for historical reasons: The C and C++ standards used to not define type bool. 0242 * Also provides a fixed type definition, as opposed to 0243 * type bool whose details (e.g., sizeof) may vary by compiler and between C and C++. 0244 * 0245 * @stable ICU 2.0 0246 */ 0247 typedef int8_t UBool; 0248 0249 /** 0250 * \def U_DEFINE_FALSE_AND_TRUE 0251 * Normally turns off defining macros FALSE=0 & TRUE=1 in public ICU headers. 0252 * These obsolete macros sometimes break compilation of other code that 0253 * defines enum constants or similar with these names. 0254 * C++ has long defined bool/false/true. 0255 * C99 also added definitions for these, although as macros; see stdbool.h. 0256 * 0257 * You may transitionally define U_DEFINE_FALSE_AND_TRUE=1 if you need time to migrate code. 0258 * 0259 * @internal ICU 68 0260 */ 0261 #ifdef U_DEFINE_FALSE_AND_TRUE 0262 // Use the predefined value. 0263 #else 0264 // Default to avoiding collision with non-macro definitions of FALSE & TRUE. 0265 # define U_DEFINE_FALSE_AND_TRUE 0 0266 #endif 0267 0268 #if U_DEFINE_FALSE_AND_TRUE || defined(U_IN_DOXYGEN) 0269 #ifndef TRUE 0270 /** 0271 * The TRUE value of a UBool. 0272 * 0273 * @deprecated ICU 68 Use standard "true" instead. 0274 */ 0275 # define TRUE 1 0276 #endif 0277 #ifndef FALSE 0278 /** 0279 * The FALSE value of a UBool. 0280 * 0281 * @deprecated ICU 68 Use standard "false" instead. 0282 */ 0283 # define FALSE 0 0284 #endif 0285 #endif // U_DEFINE_FALSE_AND_TRUE 0286 0287 /*==========================================================================*/ 0288 /* Unicode data types */ 0289 /*==========================================================================*/ 0290 0291 /* wchar_t-related definitions -------------------------------------------- */ 0292 0293 /* 0294 * \def U_WCHAR_IS_UTF16 0295 * Defined if wchar_t uses UTF-16. 0296 * 0297 * @stable ICU 2.0 0298 */ 0299 /* 0300 * \def U_WCHAR_IS_UTF32 0301 * Defined if wchar_t uses UTF-32. 0302 * 0303 * @stable ICU 2.0 0304 */ 0305 #if !defined(U_WCHAR_IS_UTF16) && !defined(U_WCHAR_IS_UTF32) 0306 # ifdef __STDC_ISO_10646__ 0307 # if (U_SIZEOF_WCHAR_T==2) 0308 # define U_WCHAR_IS_UTF16 0309 # elif (U_SIZEOF_WCHAR_T==4) 0310 # define U_WCHAR_IS_UTF32 0311 # endif 0312 # elif defined __UCS2__ 0313 # if (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400) && (U_SIZEOF_WCHAR_T==2) 0314 # define U_WCHAR_IS_UTF16 0315 # endif 0316 # elif defined(__UCS4__) || (U_PLATFORM == U_PF_OS400 && defined(__UTF32__)) 0317 # if (U_SIZEOF_WCHAR_T==4) 0318 # define U_WCHAR_IS_UTF32 0319 # endif 0320 # elif U_PLATFORM_IS_DARWIN_BASED || (U_SIZEOF_WCHAR_T==4 && U_PLATFORM_IS_LINUX_BASED) 0321 # define U_WCHAR_IS_UTF32 0322 # elif U_PLATFORM_HAS_WIN32_API 0323 # define U_WCHAR_IS_UTF16 0324 # endif 0325 #endif 0326 0327 /* UChar and UChar32 definitions -------------------------------------------- */ 0328 0329 /** Number of bytes in a UChar (always 2). @stable ICU 2.0 */ 0330 #define U_SIZEOF_UCHAR 2 0331 0332 /** 0333 * \def U_CHAR16_IS_TYPEDEF 0334 * If 1, then char16_t is a typedef and not a real type (yet) 0335 * @internal 0336 */ 0337 #if defined(_MSC_VER) && (_MSC_VER < 1900) 0338 // Versions of Visual Studio/MSVC below 2015 do not support char16_t as a real type, 0339 // and instead use a typedef. https://msdn.microsoft.com/library/bb531344.aspx 0340 # define U_CHAR16_IS_TYPEDEF 1 0341 #else 0342 # define U_CHAR16_IS_TYPEDEF 0 0343 #endif 0344 0345 0346 /** 0347 * \var UChar 0348 * 0349 * The base type for UTF-16 code units and pointers. 0350 * Unsigned 16-bit integer. 0351 * Starting with ICU 59, C++ API uses char16_t directly, while C API continues to use UChar. 0352 * 0353 * UChar is configurable by defining the macro UCHAR_TYPE 0354 * on the preprocessor or compiler command line: 0355 * -DUCHAR_TYPE=uint16_t or -DUCHAR_TYPE=wchar_t (if U_SIZEOF_WCHAR_T==2) etc. 0356 * (The UCHAR_TYPE can also be \#defined earlier in this file, for outside the ICU library code.) 0357 * This is for transitional use from application code that uses uint16_t or wchar_t for UTF-16. 0358 * 0359 * The default is UChar=char16_t. 0360 * 0361 * C++11 defines char16_t as bit-compatible with uint16_t, but as a distinct type. 0362 * 0363 * In C, char16_t is a simple typedef of uint_least16_t. 0364 * ICU requires uint_least16_t=uint16_t for data memory mapping. 0365 * On macOS, char16_t is not available because the uchar.h standard header is missing. 0366 * 0367 * @stable ICU 4.4 0368 */ 0369 0370 #if 1 0371 // #if 1 is normal. UChar defaults to char16_t in C++. 0372 // For configuration testing of UChar=uint16_t temporarily change this to #if 0. 0373 // The intltest Makefile #defines UCHAR_TYPE=char16_t, 0374 // so we only #define it to uint16_t if it is undefined so far. 0375 #elif !defined(UCHAR_TYPE) 0376 # define UCHAR_TYPE uint16_t 0377 #endif 0378 0379 #if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || \ 0380 defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) 0381 // Inside the ICU library code, never configurable. 0382 typedef char16_t UChar; 0383 #elif defined(UCHAR_TYPE) 0384 typedef UCHAR_TYPE UChar; 0385 #elif U_CPLUSPLUS_VERSION != 0 0386 typedef char16_t UChar; // C++ 0387 #else 0388 typedef uint16_t UChar; // C 0389 #endif 0390 0391 /** 0392 * \var OldUChar 0393 * Default ICU 58 definition of UChar. 0394 * A base type for UTF-16 code units and pointers. 0395 * Unsigned 16-bit integer. 0396 * 0397 * Define OldUChar to be wchar_t if that is 16 bits wide. 0398 * If wchar_t is not 16 bits wide, then define UChar to be uint16_t. 0399 * 0400 * This makes the definition of OldUChar platform-dependent 0401 * but allows direct string type compatibility with platforms with 0402 * 16-bit wchar_t types. 0403 * 0404 * This is how UChar was defined in ICU 58, for transition convenience. 0405 * Exception: ICU 58 UChar was defined to UCHAR_TYPE if that macro was defined. 0406 * The current UChar responds to UCHAR_TYPE but OldUChar does not. 0407 * 0408 * @stable ICU 59 0409 */ 0410 #if U_SIZEOF_WCHAR_T==2 0411 typedef wchar_t OldUChar; 0412 #elif defined(__CHAR16_TYPE__) 0413 typedef __CHAR16_TYPE__ OldUChar; 0414 #else 0415 typedef uint16_t OldUChar; 0416 #endif 0417 0418 /** 0419 * Define UChar32 as a type for single Unicode code points. 0420 * UChar32 is a signed 32-bit integer (same as int32_t). 0421 * 0422 * The Unicode code point range is 0..0x10ffff. 0423 * All other values (negative or >=0x110000) are illegal as Unicode code points. 0424 * They may be used as sentinel values to indicate "done", "error" 0425 * or similar non-code point conditions. 0426 * 0427 * Before ICU 2.4 (Jitterbug 2146), UChar32 was defined 0428 * to be wchar_t if that is 32 bits wide (wchar_t may be signed or unsigned) 0429 * or else to be uint32_t. 0430 * That is, the definition of UChar32 was platform-dependent. 0431 * 0432 * @see U_SENTINEL 0433 * @stable ICU 2.4 0434 */ 0435 typedef int32_t UChar32; 0436 0437 /** 0438 * This value is intended for sentinel values for APIs that 0439 * (take or) return single code points (UChar32). 0440 * It is outside of the Unicode code point range 0..0x10ffff. 0441 * 0442 * For example, a "done" or "error" value in a new API 0443 * could be indicated with U_SENTINEL. 0444 * 0445 * ICU APIs designed before ICU 2.4 usually define service-specific "done" 0446 * values, mostly 0xffff. 0447 * Those may need to be distinguished from 0448 * actual U+ffff text contents by calling functions like 0449 * CharacterIterator::hasNext() or UnicodeString::length(). 0450 * 0451 * @return -1 0452 * @see UChar32 0453 * @stable ICU 2.4 0454 */ 0455 #define U_SENTINEL (-1) 0456 0457 #include "unicode/urename.h" 0458 0459 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|