umachine.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. // Copyright (C) 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: US-ASCII
  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 "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. #ifndef U_HIDE_INTERNAL_API
  49. /*
  50. * U_USE_CHAR16_T
  51. * When defined, force use of char16_t for UChar.
  52. * Note: char16_t is expected to become the default and required in the future,
  53. * and this option will be removed.
  54. * @internal
  55. */
  56. #ifdef U_USE_CHAR16_T
  57. #ifdef UCHAR_TYPE
  58. #undef UCHAR_TYPE
  59. #endif
  60. #define UCHAR_TYPE char16_t
  61. /*
  62. * In plain C, <uchar.h> is needed for the definition of char16_t
  63. */
  64. #ifndef __cplusplus
  65. #include <uchar.h>
  66. #endif
  67. #endif
  68. #endif /* U_HIDE_INTERNAL_API */
  69. /*==========================================================================*/
  70. /* For C wrappers, we use the symbol U_STABLE. */
  71. /* This works properly if the includer is C or C++. */
  72. /* Functions are declared U_STABLE return-type U_EXPORT2 function-name()... */
  73. /*==========================================================================*/
  74. /**
  75. * \def U_CFUNC
  76. * This is used in a declaration of a library private ICU C function.
  77. * @stable ICU 2.4
  78. */
  79. /**
  80. * \def U_CDECL_BEGIN
  81. * This is used to begin a declaration of a library private ICU C API.
  82. * @stable ICU 2.4
  83. */
  84. /**
  85. * \def U_CDECL_END
  86. * This is used to end a declaration of a library private ICU C API
  87. * @stable ICU 2.4
  88. */
  89. #ifdef __cplusplus
  90. # define U_CFUNC extern "C"
  91. # define U_CDECL_BEGIN extern "C" {
  92. # define U_CDECL_END }
  93. #else
  94. # define U_CFUNC extern
  95. # define U_CDECL_BEGIN
  96. # define U_CDECL_END
  97. #endif
  98. #ifndef U_ATTRIBUTE_DEPRECATED
  99. /**
  100. * \def U_ATTRIBUTE_DEPRECATED
  101. * This is used for GCC specific attributes
  102. * @internal
  103. */
  104. #if U_GCC_MAJOR_MINOR >= 302
  105. # define U_ATTRIBUTE_DEPRECATED __attribute__ ((deprecated))
  106. /**
  107. * \def U_ATTRIBUTE_DEPRECATED
  108. * This is used for Visual C++ specific attributes
  109. * @internal
  110. */
  111. #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
  112. # define U_ATTRIBUTE_DEPRECATED __declspec(deprecated)
  113. #else
  114. # define U_ATTRIBUTE_DEPRECATED
  115. #endif
  116. #endif
  117. /** This is used to declare a function as a public ICU C API @stable ICU 2.0*/
  118. #define U_CAPI U_CFUNC U_EXPORT
  119. /** This is used to declare a function as a stable public ICU C API*/
  120. #define U_STABLE U_CAPI
  121. /** This is used to declare a function as a draft public ICU C API */
  122. #define U_DRAFT U_CAPI
  123. /** This is used to declare a function as a deprecated public ICU C API */
  124. #define U_DEPRECATED U_CAPI U_ATTRIBUTE_DEPRECATED
  125. /** This is used to declare a function as an obsolete public ICU C API */
  126. #define U_OBSOLETE U_CAPI
  127. /** This is used to declare a function as an internal ICU C API */
  128. #define U_INTERNAL U_CAPI
  129. /**
  130. * \def U_OVERRIDE
  131. * Defined to the C++11 "override" keyword if available.
  132. * Denotes a class or member which is an override of the base class.
  133. * May result in an error if it applied to something not an override.
  134. * @internal
  135. */
  136. /**
  137. * \def U_FINAL
  138. * Defined to the C++11 "final" keyword if available.
  139. * Denotes a class or member which may not be overridden in subclasses.
  140. * May result in an error if subclasses attempt to override.
  141. * @internal
  142. */
  143. #if U_CPLUSPLUS_VERSION >= 11
  144. /* C++11 */
  145. #ifndef U_OVERRIDE
  146. #define U_OVERRIDE override
  147. #endif
  148. #ifndef U_FINAL
  149. #define U_FINAL final
  150. #endif
  151. #else
  152. /* not C++11 - define to nothing */
  153. #ifndef U_OVERRIDE
  154. #define U_OVERRIDE
  155. #endif
  156. #ifndef U_FINAL
  157. #define U_FINAL
  158. #endif
  159. #endif
  160. /*==========================================================================*/
  161. /* limits for int32_t etc., like in POSIX inttypes.h */
  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. #ifndef INT8_MAX
  176. /** The largest value an 8 bit signed integer can hold @stable ICU 2.0 */
  177. # define INT8_MAX ((int8_t)(127))
  178. #endif
  179. #ifndef INT16_MAX
  180. /** The largest value a 16 bit signed integer can hold @stable ICU 2.0 */
  181. # define INT16_MAX ((int16_t)(32767))
  182. #endif
  183. #ifndef INT32_MAX
  184. /** The largest value a 32 bit signed integer can hold @stable ICU 2.0 */
  185. # define INT32_MAX ((int32_t)(2147483647))
  186. #endif
  187. #ifndef UINT8_MAX
  188. /** The largest value an 8 bit unsigned integer can hold @stable ICU 2.0 */
  189. # define UINT8_MAX ((uint8_t)(255U))
  190. #endif
  191. #ifndef UINT16_MAX
  192. /** The largest value a 16 bit unsigned integer can hold @stable ICU 2.0 */
  193. # define UINT16_MAX ((uint16_t)(65535U))
  194. #endif
  195. #ifndef UINT32_MAX
  196. /** The largest value a 32 bit unsigned integer can hold @stable ICU 2.0 */
  197. # define UINT32_MAX ((uint32_t)(4294967295U))
  198. #endif
  199. #if defined(U_INT64_T_UNAVAILABLE)
  200. # error int64_t is required for decimal format and rule-based number format.
  201. #else
  202. # ifndef INT64_C
  203. /**
  204. * Provides a platform independent way to specify a signed 64-bit integer constant.
  205. * note: may be wrong for some 64 bit platforms - ensure your compiler provides INT64_C
  206. * @stable ICU 2.8
  207. */
  208. # define INT64_C(c) c ## LL
  209. # endif
  210. # ifndef UINT64_C
  211. /**
  212. * Provides a platform independent way to specify an unsigned 64-bit integer constant.
  213. * note: may be wrong for some 64 bit platforms - ensure your compiler provides UINT64_C
  214. * @stable ICU 2.8
  215. */
  216. # define UINT64_C(c) c ## ULL
  217. # endif
  218. # ifndef U_INT64_MIN
  219. /** The smallest value a 64 bit signed integer can hold @stable ICU 2.8 */
  220. # define U_INT64_MIN ((int64_t)(INT64_C(-9223372036854775807)-1))
  221. # endif
  222. # ifndef U_INT64_MAX
  223. /** The largest value a 64 bit signed integer can hold @stable ICU 2.8 */
  224. # define U_INT64_MAX ((int64_t)(INT64_C(9223372036854775807)))
  225. # endif
  226. # ifndef U_UINT64_MAX
  227. /** The largest value a 64 bit unsigned integer can hold @stable ICU 2.8 */
  228. # define U_UINT64_MAX ((uint64_t)(UINT64_C(18446744073709551615)))
  229. # endif
  230. #endif
  231. /*==========================================================================*/
  232. /* Boolean data type */
  233. /*==========================================================================*/
  234. /** The ICU boolean type @stable ICU 2.0 */
  235. typedef int8_t UBool;
  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. /* Unicode data types */
  246. /*==========================================================================*/
  247. /* wchar_t-related definitions -------------------------------------------- */
  248. /*
  249. * \def U_WCHAR_IS_UTF16
  250. * Defined if wchar_t uses UTF-16.
  251. *
  252. * @stable ICU 2.0
  253. */
  254. /*
  255. * \def U_WCHAR_IS_UTF32
  256. * Defined if wchar_t uses UTF-32.
  257. *
  258. * @stable ICU 2.0
  259. */
  260. #if !defined(U_WCHAR_IS_UTF16) && !defined(U_WCHAR_IS_UTF32)
  261. # ifdef __STDC_ISO_10646__
  262. # if (U_SIZEOF_WCHAR_T==2)
  263. # define U_WCHAR_IS_UTF16
  264. # elif (U_SIZEOF_WCHAR_T==4)
  265. # define U_WCHAR_IS_UTF32
  266. # endif
  267. # elif defined __UCS2__
  268. # if (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400) && (U_SIZEOF_WCHAR_T==2)
  269. # define U_WCHAR_IS_UTF16
  270. # endif
  271. # elif defined(__UCS4__) || (U_PLATFORM == U_PF_OS400 && defined(__UTF32__))
  272. # if (U_SIZEOF_WCHAR_T==4)
  273. # define U_WCHAR_IS_UTF32
  274. # endif
  275. # elif U_PLATFORM_IS_DARWIN_BASED || (U_SIZEOF_WCHAR_T==4 && U_PLATFORM_IS_LINUX_BASED)
  276. # define U_WCHAR_IS_UTF32
  277. # elif U_PLATFORM_HAS_WIN32_API
  278. # define U_WCHAR_IS_UTF16
  279. # endif
  280. #endif
  281. /* UChar and UChar32 definitions -------------------------------------------- */
  282. /** Number of bytes in a UChar. @stable ICU 2.0 */
  283. #define U_SIZEOF_UCHAR 2
  284. /**
  285. * \var UChar
  286. * Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t),
  287. * or wchar_t if that is 16 bits wide; always assumed to be unsigned.
  288. * If neither is available, then define UChar to be uint16_t.
  289. *
  290. * This makes the definition of UChar platform-dependent
  291. * but allows direct string type compatibility with platforms with
  292. * 16-bit wchar_t types.
  293. *
  294. * @stable ICU 4.4
  295. */
  296. #if defined(UCHAR_TYPE)
  297. typedef UCHAR_TYPE UChar;
  298. /* Not #elif U_HAVE_CHAR16_T -- because that is type-incompatible with pre-C++11 callers
  299. typedef char16_t UChar; */
  300. #elif U_SIZEOF_WCHAR_T==2
  301. typedef wchar_t UChar;
  302. #elif defined(__CHAR16_TYPE__)
  303. typedef __CHAR16_TYPE__ UChar;
  304. #else
  305. typedef uint16_t UChar;
  306. #endif
  307. /**
  308. * Define UChar32 as a type for single Unicode code points.
  309. * UChar32 is a signed 32-bit integer (same as int32_t).
  310. *
  311. * The Unicode code point range is 0..0x10ffff.
  312. * All other values (negative or >=0x110000) are illegal as Unicode code points.
  313. * They may be used as sentinel values to indicate "done", "error"
  314. * or similar non-code point conditions.
  315. *
  316. * Before ICU 2.4 (Jitterbug 2146), UChar32 was defined
  317. * to be wchar_t if that is 32 bits wide (wchar_t may be signed or unsigned)
  318. * or else to be uint32_t.
  319. * That is, the definition of UChar32 was platform-dependent.
  320. *
  321. * @see U_SENTINEL
  322. * @stable ICU 2.4
  323. */
  324. typedef int32_t UChar32;
  325. /**
  326. * This value is intended for sentinel values for APIs that
  327. * (take or) return single code points (UChar32).
  328. * It is outside of the Unicode code point range 0..0x10ffff.
  329. *
  330. * For example, a "done" or "error" value in a new API
  331. * could be indicated with U_SENTINEL.
  332. *
  333. * ICU APIs designed before ICU 2.4 usually define service-specific "done"
  334. * values, mostly 0xffff.
  335. * Those may need to be distinguished from
  336. * actual U+ffff text contents by calling functions like
  337. * CharacterIterator::hasNext() or UnicodeString::length().
  338. *
  339. * @return -1
  340. * @see UChar32
  341. * @stable ICU 2.4
  342. */
  343. #define U_SENTINEL (-1)
  344. #include "urename.h"
  345. #endif