]> granicus.if.org Git - icu/commitdiff
ICU-12992 UChar=char16_t inside ICU, configurable, defaults to char16_t/C++ uint16_t/C
authorMarkus Scherer <markus.icu@gmail.com>
Wed, 1 Mar 2017 23:05:52 +0000 (23:05 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Wed, 1 Mar 2017 23:05:52 +0000 (23:05 +0000)
X-SVN-Rev: 39720

icu4c/source/common/unicode/umachine.h
icu4c/source/common/unicode/utypes.h
icu4c/source/test/intltest/Makefile.in
icu4c/source/test/intltest/intltest.vcxproj
icu4c/source/test/intltest/intltest.vcxproj.filters
icu4c/source/test/intltest/punyref.cpp [moved from icu4c/source/test/intltest/punyref.c with 99% similarity]

index 3dab79a825fd9d4e132facda5f9b927d6e9fac45..e0fedfe95790a421b4d05634ca0d948f713d04da 100644 (file)
@@ -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
index 6b61c4c164601ad80d5bc14d06136d133faf8129..d60450b5a563d06cbf728497c31e5e437fa72c41 100644 (file)
 
 /**
  * \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
index 073935fcd9f3fcee4b042ce7e7a609f84fd57e82..d040871ebea66438badc57b63bb55ca981d7259d 100644 (file)
@@ -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)
 
index 3779ffa2e224548945d99061993e710ec8d91d9c..315adfd51f4b45a146cfb680c732c0bff59a1ed7 100644 (file)
     <ClCompile Include="idnaconf.cpp" />
     <ClCompile Include="idnaref.cpp" />
     <ClCompile Include="nptrans.cpp" />
-    <ClCompile Include="punyref.c" />
+    <ClCompile Include="punyref.cpp" />
     <ClCompile Include="testidn.cpp">
       <DisableLanguageExtensions>false</DisableLanguageExtensions>
     </ClCompile>
index c490d90fdfb749bfb09e185ccddb7fc3d46cafea..39a3e4ef25162b66b4491f20265fa024c6cefdcb 100644 (file)
     <ClCompile Include="nptrans.cpp">
       <Filter>idna</Filter>
     </ClCompile>
-    <ClCompile Include="punyref.c">
+    <ClCompile Include="punyref.cpp">
       <Filter>idna</Filter>
     </ClCompile>
     <ClCompile Include="testidn.cpp">
similarity index 99%
rename from icu4c/source/test/intltest/punyref.c
rename to icu4c/source/test/intltest/punyref.cpp
index 5e0f8422cf45246664c2c74df8cc94ff7eb0c390..77c3e27fa6e8e1e9a19c7cf5d152e329b04ffdfd 100644 (file)
@@ -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