umachine.h 15 KB

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