umachine.h 15 KB

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