From: Markus Scherer Date: Wed, 1 Mar 2017 23:05:52 +0000 (+0000) Subject: ICU-12992 UChar=char16_t inside ICU, configurable, defaults to char16_t/C++ uint16_t/C X-Git-Tag: release-59-rc~119^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5df9572e9a850addde1e579e0778b6d0625833bc;p=icu ICU-12992 UChar=char16_t inside ICU, configurable, defaults to char16_t/C++ uint16_t/C X-SVN-Rev: 39720 --- diff --git a/icu4c/source/common/unicode/umachine.h b/icu4c/source/common/unicode/umachine.h index 3dab79a825f..e0fedfe9579 100644 --- a/icu4c/source/common/unicode/umachine.h +++ b/icu4c/source/common/unicode/umachine.h @@ -293,28 +293,34 @@ typedef int8_t UBool; /** * \var UChar * - * For C++, UChar is always defined to be char16_t. + * The base type for UTF-16 code units and pointers. + * Unsigned 16-bit integer. + * Starting with ICU 59, C++ API uses char16_t directly, while C API continues to use UChar. * - * For plain C, define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), - * or wchar_t if that is 16 bits wide; always assumed to be unsigned. - * If neither is available, then define UChar to be uint16_t. + * UChar is configurable by defining the macro UCHAR_TYPE + * on the preprocessor or compiler command line: + * -DUCHAR_TYPE=uint16_t or -DUCHAR_TYPE=wchar_t (if U_SIZEOF_WCHAR_T==2) etc. + * (The UCHAR_TYPE can also be #defined earlier in this file, for outside the ICU library code.) + * This is for transitional use from application code that uses uint16_t or wchar_t for UTF-16. * - * This makes the definition of UChar platform-dependent - * but allows direct string type compatibility with platforms with - * 16-bit wchar_t types. + * The default is UChar=char16_t. + * + * C++11 defines char16_t as bit-compatible with uint16_t, but as a distinct type. + * + * In C, char16_t is a simple typedef of uint_least16_t. + * ICU requires uint_least16_t=uint16_t for data memory mapping. + * On macOS, char16_t is not available because the uchar.h standard header is missing. * * @stable ICU 4.4 */ -#ifdef __cplusplus +#if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || \ + defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) + // Inside the ICU library code, never configurable. typedef char16_t UChar; #elif defined(UCHAR_TYPE) typedef UCHAR_TYPE UChar; -#elif U_SIZEOF_WCHAR_T==2 - typedef wchar_t UChar; -#elif U_HAVE_CHAR16_T +#elif defined(__cplusplus) typedef char16_t UChar; -#elif defined(__CHAR16_TYPE__) - typedef __CHAR16_TYPE__ UChar; #else typedef uint16_t UChar; #endif diff --git a/icu4c/source/common/unicode/utypes.h b/icu4c/source/common/unicode/utypes.h index 6b61c4c1646..d60450b5a56 100644 --- a/icu4c/source/common/unicode/utypes.h +++ b/icu4c/source/common/unicode/utypes.h @@ -178,12 +178,12 @@ /** * \def NULL - * Define NULL if necessary, to 0 for C++ and to ((void *)0) for C. + * Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C. * @stable ICU 2.0 */ #ifndef NULL #ifdef __cplusplus -#define NULL 0 +#define NULL nullptr #else #define NULL ((void *)0) #endif diff --git a/icu4c/source/test/intltest/Makefile.in b/icu4c/source/test/intltest/Makefile.in index 073935fcd9f..d040871ebea 100644 --- a/icu4c/source/test/intltest/Makefile.in +++ b/icu4c/source/test/intltest/Makefile.in @@ -35,7 +35,7 @@ BUILDDIR := $(BUILDDIR:test\\intltest/../../=) BUILDDIR := $(BUILDDIR:TEST\\INTLTEST/../../=) CPPFLAGS += -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(top_srcdir)/tools/toolutil -I$(top_srcdir)/tools/ctestfw -CPPFLAGS += -DUNISTR_FROM_CHAR_EXPLICIT= -DUNISTR_FROM_STRING_EXPLICIT= +CPPFLAGS += -DUNISTR_FROM_CHAR_EXPLICIT= -DUNISTR_FROM_STRING_EXPLICIT= -DUCHAR_TYPE=char16_t DEFS += -D'U_TOPSRCDIR="$(top_srcdir)/"' -D'U_TOPBUILDDIR="$(BUILDDIR)"' LIBS = $(LIBCTESTFW) $(LIBICUI18N) $(LIBICUUC) $(LIBICUTOOLUTIL) $(DEFAULT_LIBS) $(LIB_M) $(LIB_THREAD) diff --git a/icu4c/source/test/intltest/intltest.vcxproj b/icu4c/source/test/intltest/intltest.vcxproj index 3779ffa2e22..315adfd51f4 100644 --- a/icu4c/source/test/intltest/intltest.vcxproj +++ b/icu4c/source/test/intltest/intltest.vcxproj @@ -368,7 +368,7 @@ - + false diff --git a/icu4c/source/test/intltest/intltest.vcxproj.filters b/icu4c/source/test/intltest/intltest.vcxproj.filters index c490d90fdfb..39a3e4ef251 100644 --- a/icu4c/source/test/intltest/intltest.vcxproj.filters +++ b/icu4c/source/test/intltest/intltest.vcxproj.filters @@ -352,7 +352,7 @@ idna - + idna diff --git a/icu4c/source/test/intltest/punyref.c b/icu4c/source/test/intltest/punyref.cpp similarity index 99% rename from icu4c/source/test/intltest/punyref.c rename to icu4c/source/test/intltest/punyref.cpp index 5e0f8422cf4..77c3e27fa6e 100644 --- a/icu4c/source/test/intltest/punyref.c +++ b/icu4c/source/test/intltest/punyref.cpp @@ -7,7 +7,7 @@ * Corporation and others. All Rights Reserved. * ******************************************************************************* - * file name: punyref.h + * file name: punyref.cpp * encoding: UTF-8 * tab size: 8 (not used) * indentation:4