]> granicus.if.org Git - icu/commitdiff
ICU-12992 move Char16Ptr to new char16ptr.h; change non-UnicodeString C++ functions...
authorMarkus Scherer <markus.icu@gmail.com>
Wed, 1 Mar 2017 05:52:24 +0000 (05:52 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Wed, 1 Mar 2017 05:52:24 +0000 (05:52 +0000)
X-SVN-Rev: 39716

33 files changed:
icu4c/source/common/Makefile.in
icu4c/source/common/char16ptr.cpp [new file with mode: 0644]
icu4c/source/common/common.vcxproj
icu4c/source/common/common.vcxproj.filters
icu4c/source/common/normlzr.cpp
icu4c/source/common/ucharstrie.cpp
icu4c/source/common/ucharstrieiterator.cpp
icu4c/source/common/uchriter.cpp
icu4c/source/common/unicode/casemap.h
icu4c/source/common/unicode/char16ptr.h [new file with mode: 0644]
icu4c/source/common/unicode/normlzr.h
icu4c/source/common/unicode/ucharstrie.h
icu4c/source/common/unicode/uchriter.h
icu4c/source/common/unicode/unistr.h
icu4c/source/common/unistr.cpp
icu4c/source/common/ustr_titlecase_brkiter.cpp
icu4c/source/common/ustrcase.cpp
icu4c/source/common/ustrcase_locale.cpp
icu4c/source/i18n/curramt.cpp
icu4c/source/i18n/currunit.cpp
icu4c/source/i18n/dtfmtsym.cpp
icu4c/source/i18n/numfmt.cpp
icu4c/source/i18n/smpdtfmt.cpp
icu4c/source/i18n/unicode/curramt.h
icu4c/source/i18n/unicode/currunit.h
icu4c/source/i18n/unicode/dtfmtsym.h
icu4c/source/i18n/unicode/numfmt.h
icu4c/source/i18n/unum.cpp
icu4c/source/test/intltest/dtfmttst.cpp
icu4c/source/test/intltest/intltest.cpp
icu4c/source/test/intltest/measfmttest.cpp
icu4c/source/test/intltest/numfmtst.cpp
icu4c/source/test/intltest/tsmthred.cpp

index 10fa8de38ebe642594469d0564e7305fb261cfec..5a82fbf72622ab0c5439d6396ebe5b9c577c6014 100644 (file)
@@ -95,7 +95,7 @@ bytestrie.o bytestrieiterator.o \
 ucharstrie.o ucharstriebuilder.o ucharstrieiterator.o \
 dictionarydata.o \
 edits.o \
-appendable.o ustr_cnv.o unistr_cnv.o unistr.o unistr_case.o unistr_props.o \
+char16ptr.o appendable.o ustr_cnv.o unistr_cnv.o unistr.o unistr_case.o unistr_props.o \
 utf_impl.o ustring.o ustrcase.o ucasemap.o ucasemap_titlecase_brkiter.o cstring.o ustrfmt.o ustrtrns.o ustr_wcs.o utext.o \
 unistr_case_locale.o ustrcase_locale.o unistr_titlecase_brkiter.o ustr_titlecase_brkiter.o \
 normalizer2impl.o normalizer2.o filterednormalizer2.o normlzr.o unorm.o unormcmp.o loadednormalizer2impl.o \
diff --git a/icu4c/source/common/char16ptr.cpp b/icu4c/source/common/char16ptr.cpp
new file mode 100644 (file)
index 0000000..1da9cd8
--- /dev/null
@@ -0,0 +1,55 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+// char16ptr.cpp
+// created: 2017feb28 Markus W. Scherer
+
+#include "unicode/utypes.h"
+#include "unicode/char16ptr.h"
+#include "uassert.h"
+
+U_NAMESPACE_BEGIN
+
+#ifdef U_ALIASING_BARRIER
+
+Char16Ptr::Char16Ptr(int null) : p(nullptr) {
+    U_ASSERT(null == 0);
+    if (null != 0) {
+        // Try to provoke a crash.
+        p = reinterpret_cast<char16_t *>(1);
+    }
+}
+
+ConstChar16Ptr::ConstChar16Ptr(int null) : p(nullptr) {
+    U_ASSERT(null == 0);
+    if (null != 0) {
+        // Try to provoke a crash.
+        p = reinterpret_cast<char16_t *>(1);
+    }
+}
+
+#else
+
+Char16Ptr::Char16Ptr(int null) {
+    U_ASSERT(null == 0);
+    if (null == 0) {
+        u.cp = nullptr;
+    } else {
+        // Try to provoke a crash.
+        u.cp = reinterpret_cast<char16_t *>(1);
+    }
+}
+
+ConstChar16Ptr::ConstChar16Ptr(int null) {
+    U_ASSERT(null == 0);
+    if (null == 0) {
+        u.cp = nullptr;
+    } else {
+        // Try to provoke a crash.
+        u.cp = reinterpret_cast<char16_t *>(1);
+    }
+}
+
+#endif
+
+U_NAMESPACE_END
index b735ee9398ec5b575699879e92fe5867e0dde417..9e760180666c41f2d2f30ee251c096a20106289f 100644 (file)
     <ClCompile Include="bytestrie.cpp" />
     <ClCompile Include="bytestriebuilder.cpp" />
     <ClCompile Include="bytestrieiterator.cpp" />
+    <ClCompile Include="char16ptr.cpp" />
     <ClCompile Include="chariter.cpp" />
     <ClCompile Include="charstr.cpp" />
     <ClCompile Include="cstring.cpp" />
 </Command>
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
       <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
+</Command>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
+    </CustomBuild>
+    <CustomBuild Include="unicode\char16ptr.h">
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
+</Command>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
+</Command>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
+</Command>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
 </Command>
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
     </CustomBuild>
index 21387cd75087a1526447dc67e786e36dfccdd0e3..b29fe2fc4f265b3bc496263e10dd1e8d466095c8 100644 (file)
     <ClCompile Include="bytestream.cpp">
       <Filter>strings</Filter>
     </ClCompile>
+    <ClCompile Include="char16ptr.cpp">
+      <Filter>strings</Filter>
+    </ClCompile>
     <ClCompile Include="chariter.cpp">
       <Filter>strings</Filter>
     </ClCompile>
     <CustomBuild Include="unicode\casemap.h">
       <Filter>strings</Filter>
     </CustomBuild>
+    <CustomBuild Include="unicode\char16ptr.h">
+      <Filter>strings</Filter>
+    </CustomBuild>
     <CustomBuild Include="unicode\chariter.h">
       <Filter>strings</Filter>
     </CustomBuild>
index 4569d742e2df1ab2c65802821069476a326b93d7..a1a4949d30aa788e5e761aef4e6642f0c4db3087 100644 (file)
@@ -40,7 +40,7 @@ Normalizer::Normalizer(const UnicodeString& str, UNormalizationMode mode) :
     init();
 }
 
-Normalizer::Normalizer(const UChar *str, int32_t length, UNormalizationMode mode) :
+Normalizer::Normalizer(ConstChar16Ptr str, int32_t length, UNormalizationMode mode) :
     UObject(), fFilteredNorm2(NULL), fNorm2(NULL), fUMode(mode), fOptions(0),
     text(new UCharCharacterIterator(str, length)),
     currentIndex(0), nextIndex(0),
@@ -435,7 +435,7 @@ Normalizer::setText(const CharacterIterator& newText,
 }
 
 void
-Normalizer::setText(const UChar* newText,
+Normalizer::setText(ConstChar16Ptr newText,
                     int32_t length,
                     UErrorCode &status)
 {
index b83aec51b2cecf8e5e8a2780cb498d23b37b746f..e0b33af5194393e488bcfdfff1f8e8bb986033be 100644 (file)
@@ -175,7 +175,8 @@ UCharsTrie::next(int32_t uchar) {
 }
 
 UStringTrieResult
-UCharsTrie::next(const UChar *s, int32_t sLength) {
+UCharsTrie::next(ConstChar16Ptr ptr, int32_t sLength) {
+    const UChar *s=ptr;
     if(sLength<0 ? *s==0 : sLength==0) {
         // Empty input.
         return current();
index 56729951b40550085d0f9a9e1fd2fb620b442e49..b3132241fe2b7ab33961807c5e4f142a6dd60f74 100644 (file)
@@ -21,7 +21,7 @@
 
 U_NAMESPACE_BEGIN
 
-UCharsTrie::Iterator::Iterator(const UChar *trieUChars, int32_t maxStringLength,
+UCharsTrie::Iterator::Iterator(ConstChar16Ptr trieUChars, int32_t maxStringLength,
                                UErrorCode &errorCode)
         : uchars_(trieUChars),
           pos_(uchars_), initialPos_(uchars_),
index 0b3868e67d79ec374daf10e0f30e217c8072bb2c..822168f5c8e600ea58d52d94d792949c195b4319 100644 (file)
@@ -25,14 +25,14 @@ UCharCharacterIterator::UCharCharacterIterator()
     // never default construct!
 }
 
-UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+UCharCharacterIterator::UCharCharacterIterator(ConstChar16Ptr textPtr,
                                                int32_t length)
   : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0),
   text(textPtr)
 {
 }
 
-UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+UCharCharacterIterator::UCharCharacterIterator(ConstChar16Ptr textPtr,
                                                int32_t length,
                                                int32_t position)
   : CharacterIterator(textPtr != 0 ? (length>=0 ? length : u_strlen(textPtr)) : 0, position),
@@ -40,7 +40,7 @@ UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
 {
 }
 
-UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+UCharCharacterIterator::UCharCharacterIterator(ConstChar16Ptr textPtr,
                                                int32_t length,
                                                int32_t textBegin,
                                                int32_t textEnd,
@@ -349,7 +349,7 @@ UCharCharacterIterator::move32(int32_t delta, CharacterIterator::EOrigin origin)
     return pos;
 }
 
-void UCharCharacterIterator::setText(const UChar* newText,
+void UCharCharacterIterator::setText(ConstChar16Ptr newText,
                                      int32_t      newTextLength) {
     text = newText;
     if(newText == 0 || newTextLength < 0) {
index 2224172118c06a74cc97d515d6a1ac382ea8b5de..1050f52d7e83152b4e6eb64d605cc693b5206245 100644 (file)
@@ -8,6 +8,7 @@
 #define __CASEMAP_H__
 
 #include "unicode/utypes.h"
+#include "unicode/char16ptr.h"
 #include "unicode/uobject.h"
 
 /**
@@ -59,8 +60,8 @@ public:
      */
      static int32_t toLower(
             const char *locale, uint32_t options,
-            const UChar *src, int32_t srcLength,
-            UChar *dest, int32_t destCapacity, Edits *edits,
+            ConstChar16Ptr src, int32_t srcLength,
+            Char16Ptr dest, int32_t destCapacity, Edits *edits,
             UErrorCode &errorCode);
 
     /**
@@ -93,8 +94,8 @@ public:
      */
     static int32_t toUpper(
             const char *locale, uint32_t options,
-            const UChar *src, int32_t srcLength,
-            UChar *dest, int32_t destCapacity, Edits *edits,
+            ConstChar16Ptr src, int32_t srcLength,
+            Char16Ptr dest, int32_t destCapacity, Edits *edits,
             UErrorCode &errorCode);
 
 #if !UCONFIG_NO_BREAK_ITERATION
@@ -140,8 +141,8 @@ public:
      */
     static int32_t toTitle(
             const char *locale, uint32_t options, BreakIterator *iter,
-            const UChar *src, int32_t srcLength,
-            UChar *dest, int32_t destCapacity, Edits *edits,
+            ConstChar16Ptr src, int32_t srcLength,
+            Char16Ptr dest, int32_t destCapacity, Edits *edits,
             UErrorCode &errorCode);
 
 #endif  // UCONFIG_NO_BREAK_ITERATION
@@ -180,8 +181,8 @@ public:
      */
     static int32_t fold(
             uint32_t options,
-            const UChar *src, int32_t srcLength,
-            UChar *dest, int32_t destCapacity, Edits *edits,
+            ConstChar16Ptr src, int32_t srcLength,
+            Char16Ptr dest, int32_t destCapacity, Edits *edits,
             UErrorCode &errorCode);
 
 private:
diff --git a/icu4c/source/common/unicode/char16ptr.h b/icu4c/source/common/unicode/char16ptr.h
new file mode 100644 (file)
index 0000000..a949b7d
--- /dev/null
@@ -0,0 +1,350 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
+
+// char16ptr.h
+// created: 2017feb28 Markus W. Scherer
+
+#ifndef __CHAR16PTR_H__
+#define __CHAR16PTR_H__
+
+#include <cstddef>
+#include "unicode/utypes.h"
+
+/**
+ * \file
+ * \brief C++ API: char16_t pointer wrappers with
+ *        implicit conversion to/from bit-compatible raw pointer types.
+ */
+
+U_NAMESPACE_BEGIN
+
+/**
+ * \def U_ALIASING_BARRIER
+ * Barrier for pointer anti-aliasing optimizations even across function boundaries.
+ * @internal
+ */
+#ifdef U_ALIASING_BARRIER
+    // Use the predefined value.
+#elif defined(__clang__) || defined(__GNUC__)
+#   define U_ALIASING_BARRIER(ptr) asm volatile("" : "+rm"(ptr))
+#endif
+
+/**
+ * char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types,
+ * and from NULL.
+ * @draft ICU 59
+ */
+class U_COMMON_API Char16Ptr final {
+public:
+    /**
+     * Copies the pointer.
+     * TODO: @param p ...
+     * @draft ICU 59
+     */
+    inline Char16Ptr(char16_t *p);
+    /**
+     * Converts the pointer to char16_t *.
+     * @draft ICU 59
+     */
+    inline Char16Ptr(uint16_t *p);
+#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
+    /**
+     * Converts the pointer to char16_t *.
+     * (Only defined if U_SIZEOF_WCHAR_T==2.)
+     * @draft ICU 59
+     */
+    inline Char16Ptr(wchar_t *p);
+#endif
+    /**
+     * nullptr constructor.
+     * @draft ICU 59
+     */
+    inline Char16Ptr(std::nullptr_t p);
+    /**
+     * NULL constructor.
+     * Must only be used for 0 which is usually the value of NULL.
+     * @draft ICU 59
+     */
+    Char16Ptr(int null);
+    /**
+     * Destructor.
+     * @draft ICU 59
+     */
+    inline ~Char16Ptr();
+
+    /**
+     * Pointer access.
+     * TODO @return ...
+     * @draft ICU 59
+     */
+    inline char16_t *get() const;
+    /**
+     * char16_t pointer access via type conversion (e.g., static_cast).
+     * @draft ICU 59
+     */
+    operator char16_t *() const { return get(); }
+    /**
+     * uint16_t pointer access via type conversion (e.g., static_cast).
+     * @draft ICU 59
+     */
+    inline operator uint16_t *() const;
+#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
+    /**
+     * wchar_t pointer access via type conversion (e.g., static_cast).
+     * @draft ICU 59
+     */
+    inline operator wchar_t *() const;
+#endif
+    operator void *() const { return get(); }
+
+    char16_t operator[](size_t offset) const { return get()[offset]; }
+
+    UBool operator==(const Char16Ptr &other) const { return get() == other.get(); }
+    UBool operator!=(const Char16Ptr &other) const { return !operator==(other); }
+    UBool operator==(const char16_t *other) const { return get() == other; }
+    UBool operator!=(const char16_t *other) const { return !operator==(other); }
+    UBool operator==(const uint16_t *other) const { return static_cast<uint16_t *>(*this) == other; }
+    UBool operator!=(const uint16_t *other) const { return !operator==(other); }
+#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
+    UBool operator==(const wchar_t *other) const { return static_cast<wchar_t *>(*this) == other; }
+    UBool operator!=(const wchar_t *other) const { return !operator==(other); }
+#endif
+    UBool operator==(const std::nullptr_t null) const { return get() == null; }
+    UBool operator!=(const std::nullptr_t null) const { return !operator==(null); }
+    /**
+     * Comparison with NULL.
+     * @return TRUE if the pointer is nullptr and null==0
+     * @draft ICU 59
+     */
+    UBool operator==(int null) const { return get() == nullptr && null == 0; }
+    /**
+     * Comparison with NULL.
+     * @return TRUE if the pointer is not nullptr and null==0
+     * @draft ICU 59
+     */
+    UBool operator!=(int null) const { return get() != nullptr && null == 0; }
+
+    Char16Ptr operator+(size_t offset) const { return Char16Ptr(get() + offset); }
+
+private:
+    Char16Ptr() = delete;
+
+#ifdef U_ALIASING_BARRIER
+    template<typename T> static char16_t *cast(T *t) {
+        U_ALIASING_BARRIER(t);
+        return reinterpret_cast<char16_t *>(t);
+    }
+
+    char16_t *p;
+#else
+    union {
+        char16_t *cp;
+        uint16_t *up;
+        wchar_t *wp;
+    } u;
+#endif
+};
+
+#ifdef U_ALIASING_BARRIER
+
+Char16Ptr::Char16Ptr(char16_t *p) : p(p) {}
+Char16Ptr::Char16Ptr(uint16_t *p) : p(cast(p)) {}
+#if U_SIZEOF_WCHAR_T==2
+Char16Ptr::Char16Ptr(wchar_t *p) : p(cast(p)) {}
+#endif
+Char16Ptr::Char16Ptr(std::nullptr_t p) : p(p) {}
+Char16Ptr::~Char16Ptr() {
+    U_ALIASING_BARRIER(p);
+}
+
+char16_t *Char16Ptr::get() const { return p; }
+
+Char16Ptr::operator uint16_t *() const {
+    U_ALIASING_BARRIER(p);
+    return reinterpret_cast<uint16_t *>(p);
+}
+#if U_SIZEOF_WCHAR_T==2
+Char16Ptr::operator wchar_t *() const {
+    U_ALIASING_BARRIER(p);
+    return reinterpret_cast<wchar_t *>(p);
+}
+#endif
+
+#else
+
+Char16Ptr::Char16Ptr(char16_t *p) { u.cp = p; }
+Char16Ptr::Char16Ptr(uint16_t *p) { u.up = p; }
+#if U_SIZEOF_WCHAR_T==2
+Char16Ptr::Char16Ptr(wchar_t *p) { u.wp = p; }
+#endif
+Char16Ptr::Char16Ptr(std::nullptr_t p) { u.cp = p; }
+Char16Ptr::~Char16Ptr() {}
+
+char16_t *Char16Ptr::get() const { return u.cp; }
+
+Char16Ptr::operator uint16_t *() const {
+    return u.up;
+}
+#if U_SIZEOF_WCHAR_T==2
+Char16Ptr::operator wchar_t *() const {
+    return u.wp;
+}
+#endif
+
+#endif
+
+/**
+ * const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types,
+ * and from NULL.
+ * @draft ICU 59
+ */
+class U_COMMON_API ConstChar16Ptr final {
+public:
+    /**
+     * Copies the pointer.
+     * @draft ICU 59
+     */
+    inline ConstChar16Ptr(const char16_t *p);
+    /**
+     * Converts the pointer to char16_t *.
+     * @draft ICU 59
+     */
+    inline ConstChar16Ptr(const uint16_t *p);
+#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
+    /**
+     * Converts the pointer to char16_t *.
+     * (Only defined if U_SIZEOF_WCHAR_T==2.)
+     * @draft ICU 59
+     */
+    inline ConstChar16Ptr(const wchar_t *p);
+#endif
+    /**
+     * nullptr constructor.
+     * @draft ICU 59
+     */
+    inline ConstChar16Ptr(const std::nullptr_t p);
+    /**
+     * NULL constructor.
+     * Must only be used for 0 which is usually the value of NULL.
+     * @draft ICU 59
+     */
+    ConstChar16Ptr(int null);
+    /**
+     * Destructor.
+     * @draft ICU 59
+     */
+    inline ~ConstChar16Ptr();
+
+    /**
+     * Pointer access.
+     * @draft ICU 59
+     */
+    inline const char16_t *get() const;
+    /**
+     * char16_t pointer access via type conversion (e.g., static_cast).
+     * @draft ICU 59
+     */
+    operator const char16_t *() const { return get(); }
+    /**
+     * uint16_t pointer access via type conversion (e.g., static_cast).
+     * @draft ICU 59
+     */
+    inline operator const uint16_t *() const;
+#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
+    /**
+     * wchar_t pointer access via type conversion (e.g., static_cast).
+     * @draft ICU 59
+     */
+    inline operator const wchar_t *() const;
+#endif
+    operator const void *() const { return get(); }
+
+    char16_t operator[](size_t offset) const { return get()[offset]; }
+
+    UBool operator==(const ConstChar16Ptr &other) const { return get() == other.get(); }
+    UBool operator!=(const ConstChar16Ptr &other) const { return !operator==(other); }
+    UBool operator==(const char16_t *other) const { return get() == other; }
+    UBool operator!=(const char16_t *other) const { return !operator==(other); }
+    UBool operator==(const uint16_t *other) const { return static_cast<const uint16_t *>(*this) == other; }
+    UBool operator!=(const uint16_t *other) const { return !operator==(other); }
+#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
+    UBool operator==(const wchar_t *other) const { return static_cast<const wchar_t *>(*this) == other; }
+    UBool operator!=(const wchar_t *other) const { return !operator==(other); }
+#endif
+    UBool operator==(const std::nullptr_t null) const { return get() == null; }
+    UBool operator!=(const std::nullptr_t null) const { return !operator==(null); }
+    UBool operator==(int null) const { return get() == nullptr && null == 0; }
+    UBool operator!=(int null) const { return get() != nullptr && null == 0; }
+
+    ConstChar16Ptr operator+(size_t offset) { return ConstChar16Ptr(get() + offset); }
+
+private:
+    ConstChar16Ptr() = delete;
+
+#ifdef U_ALIASING_BARRIER
+    template<typename T> static const char16_t *cast(const T *t) {
+        U_ALIASING_BARRIER(t);
+        return reinterpret_cast<const char16_t *>(t);
+    }
+
+    const char16_t *p;
+#else
+    union {
+        const char16_t *cp;
+        const uint16_t *up;
+        const wchar_t *wp;
+    } u;
+#endif
+};
+
+#ifdef U_ALIASING_BARRIER
+
+ConstChar16Ptr::ConstChar16Ptr(const char16_t *p) : p(p) {}
+ConstChar16Ptr::ConstChar16Ptr(const uint16_t *p) : p(cast(p)) {}
+#if U_SIZEOF_WCHAR_T==2
+ConstChar16Ptr::ConstChar16Ptr(const wchar_t *p) : p(cast(p)) {}
+#endif
+ConstChar16Ptr::ConstChar16Ptr(const std::nullptr_t p) : p(p) {}
+ConstChar16Ptr::~ConstChar16Ptr() {
+    U_ALIASING_BARRIER(p);
+}
+
+const char16_t *ConstChar16Ptr::get() const { return p; }
+
+ConstChar16Ptr::operator const uint16_t *() const {
+    U_ALIASING_BARRIER(p);
+    return reinterpret_cast<const uint16_t *>(p);
+}
+#if U_SIZEOF_WCHAR_T==2
+ConstChar16Ptr::operator const wchar_t *() const {
+    U_ALIASING_BARRIER(p);
+    return reinterpret_cast<const wchar_t *>(p);
+}
+#endif
+
+#else
+
+ConstChar16Ptr::ConstChar16Ptr(const char16_t *p) { u.cp = p; }
+ConstChar16Ptr::ConstChar16Ptr(const uint16_t *p) { u.up = p; }
+#if U_SIZEOF_WCHAR_T==2
+ConstChar16Ptr::ConstChar16Ptr(const wchar_t *p) { u.wp = p; }
+#endif
+ConstChar16Ptr::ConstChar16Ptr(const std::nullptr_t p) { u.cp = p; }
+ConstChar16Ptr::~ConstChar16Ptr() {}
+
+const char16_t *ConstChar16Ptr::get() const { return u.cp; }
+
+ConstChar16Ptr::operator const uint16_t *() const {
+    return u.up;
+}
+#if U_SIZEOF_WCHAR_T==2
+ConstChar16Ptr::operator const wchar_t *() const {
+    return u.wp;
+}
+#endif
+
+#endif
+
+U_NAMESPACE_END
+
+#endif  // __CHAR16PTR_H__
index 53665e978429f8967c971dd6d7d0e605e62b85b5..31af07b7cc1060c0001cc692aba637e3c2d1e074 100644 (file)
@@ -168,7 +168,7 @@ public:
    * @param mode  The normalization mode.
    * @deprecated ICU 56 Use Normalizer2 instead.
    */
-  Normalizer(const UChar* str, int32_t length, UNormalizationMode mode);
+  Normalizer(ConstChar16Ptr str, int32_t length, UNormalizationMode mode);
 
   /**
    * Creates a new <code>Normalizer</code> object for iterating over the
@@ -704,7 +704,7 @@ public:
    * @param status a UErrorCode
    * @deprecated ICU 56 Use Normalizer2 instead.
    */
-  void setText(const UChar* newText,
+  void setText(ConstChar16Ptr newText,
                     int32_t length,
             UErrorCode &status);
   /**
index 91c5ba1c2c264162b4df1c256ea55d763fe5f52b..fdff53f4d33bab4c0574c93d1cc86dd095749d8b 100644 (file)
@@ -63,7 +63,7 @@ public:
      * @param trieUChars The UChar array that contains the serialized trie.
      * @stable ICU 4.8
      */
-    UCharsTrie(const UChar *trieUChars)
+    UCharsTrie(ConstChar16Ptr trieUChars)
             : ownedArray_(NULL), uchars_(trieUChars),
               pos_(uchars_), remainingMatchLength_(-1) {}
 
@@ -208,7 +208,7 @@ public:
      * @return The match/value Result.
      * @stable ICU 4.8
      */
-    UStringTrieResult next(const UChar *s, int32_t length);
+    UStringTrieResult next(ConstChar16Ptr s, int32_t length);
 
     /**
      * Returns a matching string's value if called immediately after
@@ -268,7 +268,7 @@ public:
          *                  function chaining. (See User Guide for details.)
          * @stable ICU 4.8
          */
-        Iterator(const UChar *trieUChars, int32_t maxStringLength, UErrorCode &errorCode);
+        Iterator(ConstChar16Ptr trieUChars, int32_t maxStringLength, UErrorCode &errorCode);
 
         /**
          * Iterates from the current state of the specified UCharsTrie.
index 3408a555071bac0c8db380906a51e7dbd842e340..644fbd8a2a9151fcce894db3a054d92f3e71a803 100644 (file)
@@ -43,7 +43,7 @@ public:
    * @param length The length of the UChar array
    * @stable ICU 2.0
    */
-  UCharCharacterIterator(const UChar* textPtr, int32_t length);
+  UCharCharacterIterator(ConstChar16Ptr textPtr, int32_t length);
 
   /**
    * Create an iterator over the UChar array referred to by "textPtr".
@@ -58,7 +58,7 @@ public:
    * @param position The starting position of the iteration
    * @stable ICU 2.0
    */
-  UCharCharacterIterator(const UChar* textPtr, int32_t length,
+  UCharCharacterIterator(ConstChar16Ptr textPtr, int32_t length,
                          int32_t position);
 
   /**
@@ -77,7 +77,7 @@ public:
    * @param position    The starting position of the iteration
    * @stable ICU 2.0
    */
-  UCharCharacterIterator(const UChar* textPtr, int32_t length,
+  UCharCharacterIterator(ConstChar16Ptr textPtr, int32_t length,
                          int32_t textBegin,
                          int32_t textEnd,
                          int32_t position);
@@ -340,7 +340,7 @@ public:
    * Sets the iterator to iterate over a new range of text
    * @stable ICU 2.0
    */
-  void setText(const UChar* newText, int32_t newTextLength);
+  void setText(ConstChar16Ptr newText, int32_t newTextLength);
 
   /**
    * Copies the UChar array under iteration into the UnicodeString
index 3ed6b7f41cc2c00b7a1e1c4c92b63b297b6735f1..331b01281add64dad57929942e8ba9c56d5f4b91 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <cstddef>
 #include "unicode/utypes.h"
+#include "unicode/char16ptr.h"
 #include "unicode/rep.h"
 #include "unicode/std_string.h"
 #include "unicode/stringpiece.h"
@@ -57,337 +58,6 @@ u_strlen(const UChar *s);
 
 U_NAMESPACE_BEGIN
 
-// TODO begin experiment ---------------
-
-/**
- * \def U_ALIASING_BARRIER
- * Barrier for pointer anti-aliasing optimizations even across function boundaries.
- * @internal
- */
-#ifdef U_ALIASING_BARRIER
-    // Use the predefined value.
-#elif defined(__clang__) || defined(__GNUC__)
-#   define U_ALIASING_BARRIER(ptr) asm volatile("" : "+rm"(ptr))
-#endif
-
-/**
- * char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types,
- * and from NULL.
- * @draft ICU 59
- */
-class U_COMMON_API Char16Ptr final {
-public:
-    /**
-     * Copies the pointer.
-     * TODO: @param p ...
-     * @draft ICU 59
-     */
-    inline Char16Ptr(char16_t *p);
-    /**
-     * Converts the pointer to char16_t *.
-     * @draft ICU 59
-     */
-    inline Char16Ptr(uint16_t *p);
-#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
-    /**
-     * Converts the pointer to char16_t *.
-     * (Only defined if U_SIZEOF_WCHAR_T==2.)
-     * @draft ICU 59
-     */
-    inline Char16Ptr(wchar_t *p);
-#endif
-    /**
-     * nullptr constructor.
-     * @draft ICU 59
-     */
-    inline Char16Ptr(std::nullptr_t p);
-    /**
-     * NULL constructor.
-     * Must only be used for 0 which is usually the value of NULL.
-     * @draft ICU 59
-     */
-    Char16Ptr(int null);
-    /**
-     * Destructor.
-     * @draft ICU 59
-     */
-    inline ~Char16Ptr();
-
-    /**
-     * Pointer access.
-     * TODO @return ...
-     * @draft ICU 59
-     */
-    inline char16_t *get() const;
-    /**
-     * char16_t pointer access via type conversion (e.g., static_cast).
-     * @draft ICU 59
-     */
-    operator char16_t *() const { return get(); }
-    /**
-     * uint16_t pointer access via type conversion (e.g., static_cast).
-     * @draft ICU 59
-     */
-    inline operator uint16_t *() const;
-#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
-    /**
-     * wchar_t pointer access via type conversion (e.g., static_cast).
-     * @draft ICU 59
-     */
-    inline operator wchar_t *() const;
-#endif
-    operator void *() const { return get(); }
-
-    char16_t operator[](size_t offset) const { return get()[offset]; }
-
-    UBool operator==(const Char16Ptr &other) const { return get() == other.get(); }
-    UBool operator!=(const Char16Ptr &other) const { return !operator==(other); }
-    UBool operator==(const char16_t *other) const { return get() == other; }
-    UBool operator!=(const char16_t *other) const { return !operator==(other); }
-    UBool operator==(const uint16_t *other) const { return static_cast<uint16_t *>(*this) == other; }
-    UBool operator!=(const uint16_t *other) const { return !operator==(other); }
-#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
-    UBool operator==(const wchar_t *other) const { return static_cast<wchar_t *>(*this) == other; }
-    UBool operator!=(const wchar_t *other) const { return !operator==(other); }
-#endif
-    UBool operator==(const std::nullptr_t null) const { return get() == null; }
-    UBool operator!=(const std::nullptr_t null) const { return !operator==(null); }
-    /**
-     * Comparison with NULL.
-     * @return TRUE if the pointer is nullptr and null==0
-     * @draft ICU 59
-     */
-    UBool operator==(int null) const { return get() == nullptr && null == 0; }
-    /**
-     * Comparison with NULL.
-     * @return TRUE if the pointer is not nullptr and null==0
-     * @draft ICU 59
-     */
-    UBool operator!=(int null) const { return get() != nullptr && null == 0; }
-
-    Char16Ptr operator+(size_t offset) const { return Char16Ptr(get() + offset); }
-
-private:
-    Char16Ptr() = delete;
-
-#ifdef U_ALIASING_BARRIER
-    template<typename T> static char16_t *cast(T *t) {
-        U_ALIASING_BARRIER(t);
-        return reinterpret_cast<char16_t *>(t);
-    }
-
-    char16_t *p;
-#else
-    union {
-        char16_t *cp;
-        uint16_t *up;
-        wchar_t *wp;
-    } u;
-#endif
-};
-
-#ifdef U_ALIASING_BARRIER
-
-Char16Ptr::Char16Ptr(char16_t *p) : p(p) {}
-Char16Ptr::Char16Ptr(uint16_t *p) : p(cast(p)) {}
-#if U_SIZEOF_WCHAR_T==2
-Char16Ptr::Char16Ptr(wchar_t *p) : p(cast(p)) {}
-#endif
-Char16Ptr::Char16Ptr(std::nullptr_t p) : p(p) {}
-Char16Ptr::~Char16Ptr() {
-    U_ALIASING_BARRIER(p);
-}
-
-char16_t *Char16Ptr::get() const { return p; }
-
-Char16Ptr::operator uint16_t *() const {
-    U_ALIASING_BARRIER(p);
-    return reinterpret_cast<uint16_t *>(p);
-}
-#if U_SIZEOF_WCHAR_T==2
-Char16Ptr::operator wchar_t *() const {
-    U_ALIASING_BARRIER(p);
-    return reinterpret_cast<wchar_t *>(p);
-}
-#endif
-
-#else
-
-Char16Ptr::Char16Ptr(char16_t *p) { u.cp = p; }
-Char16Ptr::Char16Ptr(uint16_t *p) { u.up = p; }
-#if U_SIZEOF_WCHAR_T==2
-Char16Ptr::Char16Ptr(wchar_t *p) { u.wp = p; }
-#endif
-Char16Ptr::Char16Ptr(std::nullptr_t p) { u.cp = p; }
-Char16Ptr::~Char16Ptr() {}
-
-char16_t *Char16Ptr::get() const { return u.cp; }
-
-Char16Ptr::operator uint16_t *() const {
-    return u.up;
-}
-#if U_SIZEOF_WCHAR_T==2
-Char16Ptr::operator wchar_t *() const {
-    return u.wp;
-}
-#endif
-
-#endif
-
-/**
- * const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types,
- * and from NULL.
- * @draft ICU 59
- */
-class U_COMMON_API ConstChar16Ptr final {
-public:
-    /**
-     * Copies the pointer.
-     * @draft ICU 59
-     */
-    inline ConstChar16Ptr(const char16_t *p);
-    /**
-     * Converts the pointer to char16_t *.
-     * @draft ICU 59
-     */
-    inline ConstChar16Ptr(const uint16_t *p);
-#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
-    /**
-     * Converts the pointer to char16_t *.
-     * (Only defined if U_SIZEOF_WCHAR_T==2.)
-     * @draft ICU 59
-     */
-    inline ConstChar16Ptr(const wchar_t *p);
-#endif
-    /**
-     * nullptr constructor.
-     * @draft ICU 59
-     */
-    inline ConstChar16Ptr(const std::nullptr_t p);
-    /**
-     * NULL constructor.
-     * Must only be used for 0 which is usually the value of NULL.
-     * @draft ICU 59
-     */
-    ConstChar16Ptr(int null);
-    /**
-     * Destructor.
-     * @draft ICU 59
-     */
-    inline ~ConstChar16Ptr();
-
-    /**
-     * Pointer access.
-     * @draft ICU 59
-     */
-    inline const char16_t *get() const;
-    /**
-     * char16_t pointer access via type conversion (e.g., static_cast).
-     * @draft ICU 59
-     */
-    operator const char16_t *() const { return get(); }
-    /**
-     * uint16_t pointer access via type conversion (e.g., static_cast).
-     * @draft ICU 59
-     */
-    inline operator const uint16_t *() const;
-#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
-    /**
-     * wchar_t pointer access via type conversion (e.g., static_cast).
-     * @draft ICU 59
-     */
-    inline operator const wchar_t *() const;
-#endif
-    operator const void *() const { return get(); }
-
-    char16_t operator[](size_t offset) const { return get()[offset]; }
-
-    UBool operator==(const ConstChar16Ptr &other) const { return get() == other.get(); }
-    UBool operator!=(const ConstChar16Ptr &other) const { return !operator==(other); }
-    UBool operator==(const char16_t *other) const { return get() == other; }
-    UBool operator!=(const char16_t *other) const { return !operator==(other); }
-    UBool operator==(const uint16_t *other) const { return static_cast<const uint16_t *>(*this) == other; }
-    UBool operator!=(const uint16_t *other) const { return !operator==(other); }
-#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
-    UBool operator==(const wchar_t *other) const { return static_cast<const wchar_t *>(*this) == other; }
-    UBool operator!=(const wchar_t *other) const { return !operator==(other); }
-#endif
-    UBool operator==(const std::nullptr_t null) const { return get() == null; }
-    UBool operator!=(const std::nullptr_t null) const { return !operator==(null); }
-    UBool operator==(int null) const { return get() == nullptr && null == 0; }
-    UBool operator!=(int null) const { return get() != nullptr && null == 0; }
-
-    ConstChar16Ptr operator+(size_t offset) { return ConstChar16Ptr(get() + offset); }
-
-private:
-    ConstChar16Ptr() = delete;
-
-#ifdef U_ALIASING_BARRIER
-    template<typename T> static const char16_t *cast(const T *t) {
-        U_ALIASING_BARRIER(t);
-        return reinterpret_cast<const char16_t *>(t);
-    }
-
-    const char16_t *p;
-#else
-    union {
-        const char16_t *cp;
-        const uint16_t *up;
-        const wchar_t *wp;
-    } u;
-#endif
-};
-
-#ifdef U_ALIASING_BARRIER
-
-ConstChar16Ptr::ConstChar16Ptr(const char16_t *p) : p(p) {}
-ConstChar16Ptr::ConstChar16Ptr(const uint16_t *p) : p(cast(p)) {}
-#if U_SIZEOF_WCHAR_T==2
-ConstChar16Ptr::ConstChar16Ptr(const wchar_t *p) : p(cast(p)) {}
-#endif
-ConstChar16Ptr::ConstChar16Ptr(const std::nullptr_t p) : p(p) {}
-ConstChar16Ptr::~ConstChar16Ptr() {
-    U_ALIASING_BARRIER(p);
-}
-
-const char16_t *ConstChar16Ptr::get() const { return p; }
-
-ConstChar16Ptr::operator const uint16_t *() const {
-    U_ALIASING_BARRIER(p);
-    return reinterpret_cast<const uint16_t *>(p);
-}
-#if U_SIZEOF_WCHAR_T==2
-ConstChar16Ptr::operator const wchar_t *() const {
-    U_ALIASING_BARRIER(p);
-    return reinterpret_cast<const wchar_t *>(p);
-}
-#endif
-
-#else
-
-ConstChar16Ptr::ConstChar16Ptr(const char16_t *p) { u.cp = p; }
-ConstChar16Ptr::ConstChar16Ptr(const uint16_t *p) { u.up = p; }
-#if U_SIZEOF_WCHAR_T==2
-ConstChar16Ptr::ConstChar16Ptr(const wchar_t *p) { u.wp = p; }
-#endif
-ConstChar16Ptr::ConstChar16Ptr(const std::nullptr_t p) { u.cp = p; }
-ConstChar16Ptr::~ConstChar16Ptr() {}
-
-const char16_t *ConstChar16Ptr::get() const { return u.cp; }
-
-ConstChar16Ptr::operator const uint16_t *() const {
-    return u.up;
-}
-#if U_SIZEOF_WCHAR_T==2
-ConstChar16Ptr::operator const wchar_t *() const {
-    return u.wp;
-}
-#endif
-
-#endif
-
-// TODO end experiment -----------------
-
 #if !UCONFIG_NO_BREAK_ITERATION
 class BreakIterator;        // unicode/brkiter.h
 #endif
index a891dec799bb7369b77705a3896ed20a71979e05..10c781746e1dfff13854ea898674f57d774e033e 100644 (file)
@@ -98,48 +98,6 @@ U_CDECL_END
 
 U_NAMESPACE_BEGIN
 
-#ifdef U_ALIASING_BARRIER
-
-Char16Ptr::Char16Ptr(int null) : p(nullptr) {
-    U_ASSERT(null == 0);
-    if (null != 0) {
-        // Try to provoke a crash.
-        p = reinterpret_cast<char16_t *>(1);
-    }
-}
-
-ConstChar16Ptr::ConstChar16Ptr(int null) : p(nullptr) {
-    U_ASSERT(null == 0);
-    if (null != 0) {
-        // Try to provoke a crash.
-        p = reinterpret_cast<char16_t *>(1);
-    }
-}
-
-#else
-
-Char16Ptr::Char16Ptr(int null) {
-    U_ASSERT(null == 0);
-    if (null == 0) {
-        u.cp = nullptr;
-    } else {
-        // Try to provoke a crash.
-        u.cp = reinterpret_cast<char16_t *>(1);
-    }
-}
-
-ConstChar16Ptr::ConstChar16Ptr(int null) {
-    U_ASSERT(null == 0);
-    if (null == 0) {
-        u.cp = nullptr;
-    } else {
-        // Try to provoke a crash.
-        u.cp = reinterpret_cast<char16_t *>(1);
-    }
-}
-
-#endif
-
 /* The Replaceable virtual destructor can't be defined in the header
    due to how AIX works with multiple definitions of virtual functions.
 */
index 0b2ba02064b3249c72783411d6ad3d064b45513d..ac46bc9359f4e9ed09e813499a98225fe0398435 100644 (file)
@@ -66,8 +66,8 @@ U_NAMESPACE_BEGIN
 
 int32_t CaseMap::toTitle(
         const char *locale, uint32_t options, BreakIterator *iter,
-        const UChar *src, int32_t srcLength,
-        UChar *dest, int32_t destCapacity, Edits *edits,
+        ConstChar16Ptr src, int32_t srcLength,
+        Char16Ptr dest, int32_t destCapacity, Edits *edits,
         UErrorCode &errorCode) {
     LocalPointer<BreakIterator> ownedIter;
     if(iter==NULL) {
index 0e38a42e1032c78afc44a94e2ea57f68d1d3678c..d0bdd1511aba52dd112740dc028739ee81f95019 100644 (file)
@@ -1198,8 +1198,8 @@ U_NAMESPACE_BEGIN
 
 int32_t CaseMap::fold(
         uint32_t options,
-        const UChar *src, int32_t srcLength,
-        UChar *dest, int32_t destCapacity, Edits *edits,
+        ConstChar16Ptr src, int32_t srcLength,
+        Char16Ptr dest, int32_t destCapacity, Edits *edits,
         UErrorCode &errorCode) {
     return ustrcase_map(
         UCASE_LOC_ROOT, options, UCASEMAP_BREAK_ITERATOR_NULL
index 2ecd24f03ec02ef43607187c4da5be9b7d4bd416..0c6d095d367558bca0fea894102d0fbda98eab75 100644 (file)
@@ -69,8 +69,8 @@ U_NAMESPACE_BEGIN
 
 int32_t CaseMap::toLower(
         const char *locale, uint32_t options,
-        const UChar *src, int32_t srcLength,
-        UChar *dest, int32_t destCapacity, Edits *edits,
+        ConstChar16Ptr src, int32_t srcLength,
+        Char16Ptr dest, int32_t destCapacity, Edits *edits,
         UErrorCode &errorCode) {
     return ustrcase_map(
         ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
@@ -81,8 +81,8 @@ int32_t CaseMap::toLower(
 
 int32_t CaseMap::toUpper(
         const char *locale, uint32_t options,
-        const UChar *src, int32_t srcLength,
-        UChar *dest, int32_t destCapacity, Edits *edits,
+        ConstChar16Ptr src, int32_t srcLength,
+        Char16Ptr dest, int32_t destCapacity, Edits *edits,
         UErrorCode &errorCode) {
     return ustrcase_map(
         ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
index 51f23b437abc8177c8e8e690bc01947ea30f2bee..d2242707a1e3415f970a31d7904daf61412cea2e 100644 (file)
 
 U_NAMESPACE_BEGIN
 
-CurrencyAmount::CurrencyAmount(const Formattable& amount, const UChar* isoCode,
+CurrencyAmount::CurrencyAmount(const Formattable& amount, ConstChar16Ptr isoCode,
                                UErrorCode& ec) :
     Measure(amount, new CurrencyUnit(isoCode, ec), ec) {
 }
 
-CurrencyAmount::CurrencyAmount(double amount, const UChar* isoCode,
+CurrencyAmount::CurrencyAmount(double amount, ConstChar16Ptr isoCode,
                                UErrorCode& ec) :
     Measure(Formattable(amount), new CurrencyUnit(isoCode, ec), ec) {
 }
index 3c74c1c1d996310e1ec64bd255e8eefb17afee88..197885452f5e181b0dd9410c597c6a8bc844b922 100644 (file)
 
 U_NAMESPACE_BEGIN
 
-CurrencyUnit::CurrencyUnit(const UChar* _isoCode, UErrorCode& ec) {
+CurrencyUnit::CurrencyUnit(ConstChar16Ptr _isoCode, UErrorCode& ec) {
     *isoCode = 0;
     if (U_SUCCESS(ec)) {
-        if (_isoCode && u_strlen(_isoCode)==3) {
+        if (_isoCode != nullptr && u_strlen(_isoCode)==3) {
             u_strcpy(isoCode, _isoCode);
             char simpleIsoCode[4];
             u_UCharsToChars(isoCode, simpleIsoCode, 4);
index 333c85c8fe0c641d960ed37cf9d6cfccb1e9d7cd..960971980bc0a46004874ddb63ab3df85c9ef9f5 100644 (file)
@@ -1368,7 +1368,7 @@ DateFormatSymbols::setZoneStrings(const UnicodeString* const *strings, int32_t r
 
 //------------------------------------------------------
 
-const UChar * U_EXPORT2
+ConstChar16Ptr U_EXPORT2
 DateFormatSymbols::getPatternUChars(void)
 {
     return gPatternChars;
index 951146725af3f83b8586d0e48ac01f7bdf186cc6..e84f9fdd8d289a4d079fc10d432757f6069ccaaa 100644 (file)
@@ -1188,7 +1188,7 @@ void NumberFormat::setCurrency(const UChar* theCurrency, UErrorCode& ec) {
     }
 }
 
-const UChar* NumberFormat::getCurrency() const {
+ConstChar16Ptr NumberFormat::getCurrency() const {
     return fCurrency;
 }
 
index 3c0670446b38769957ac9623473ba77f2f7653ef..69a13450a684270fd4f663ad109778657574b3d8 100644 (file)
@@ -3789,7 +3789,7 @@ SimpleDateFormat::toLocalizedPattern(UnicodeString& result,
                                      UErrorCode& status) const
 {
     translatePattern(fPattern, result,
-                     UnicodeString(DateFormatSymbols::getPatternUChars()),
+                     UnicodeString(DateFormatSymbols::getPatternUChars().get()),
                      fSymbols->fLocalPatternChars, status);
     return result;
 }
@@ -3811,7 +3811,7 @@ SimpleDateFormat::applyLocalizedPattern(const UnicodeString& pattern,
 {
     translatePattern(pattern, fPattern,
                      fSymbols->fLocalPatternChars,
-                     UnicodeString(DateFormatSymbols::getPatternUChars()), status);
+                     UnicodeString(DateFormatSymbols::getPatternUChars().get()), status);
 }
 
 //----------------------------------------------------------------------
index 9071f11bd1028f29c3b8f2b0f0a452a82b7e58c7..a645667d9d0c436dc6ef074f0f42e6e99abd5c34 100644 (file)
@@ -46,7 +46,7 @@ class U_I18N_API CurrencyAmount: public Measure {
      * is invalid, then this will be set to a failing value.
      * @stable ICU 3.0
      */
-    CurrencyAmount(const Formattable& amount, const UChar* isoCode,
+    CurrencyAmount(const Formattable& amount, ConstChar16Ptr isoCode,
                    UErrorCode &ec);
 
     /**
@@ -59,7 +59,7 @@ class U_I18N_API CurrencyAmount: public Measure {
      * then this will be set to a failing value.
      * @stable ICU 3.0
      */
-    CurrencyAmount(double amount, const UChar* isoCode,
+    CurrencyAmount(double amount, ConstChar16Ptr isoCode,
                    UErrorCode &ec);
 
     /**
@@ -115,14 +115,14 @@ class U_I18N_API CurrencyAmount: public Measure {
      * Return the ISO currency code of this object.
      * @stable ICU 3.0
      */
-    inline const UChar* getISOCurrency() const;
+    inline ConstChar16Ptr getISOCurrency() const;
 };
 
 inline const CurrencyUnit& CurrencyAmount::getCurrency() const {
     return (const CurrencyUnit&) getUnit();
 }
 
-inline const UChar* CurrencyAmount::getISOCurrency() const {
+inline ConstChar16Ptr CurrencyAmount::getISOCurrency() const {
     return getCurrency().getISOCurrency();
 }
 
index 61f9201ebb264dc1abd881f517b04818c73f97dd..857d9ceafe015e90287860f65e55e5ee0536721d 100644 (file)
@@ -44,7 +44,7 @@ class U_I18N_API CurrencyUnit: public MeasureUnit {
      * then this will be set to a failing value.
      * @stable ICU 3.0
      */
-    CurrencyUnit(const UChar* isoCode, UErrorCode &ec);
+    CurrencyUnit(ConstChar16Ptr isoCode, UErrorCode &ec);
 
     /**
      * Copy constructor
@@ -93,7 +93,7 @@ class U_I18N_API CurrencyUnit: public MeasureUnit {
      * Return the ISO currency code of this object.
      * @stable ICU 3.0
      */
-    inline const UChar* getISOCurrency() const;
+    inline ConstChar16Ptr getISOCurrency() const;
 
  private:
     /**
@@ -102,7 +102,7 @@ class U_I18N_API CurrencyUnit: public MeasureUnit {
     UChar isoCode[4];
 };
 
-inline const UChar* CurrencyUnit::getISOCurrency() const {
+inline ConstChar16Ptr CurrencyUnit::getISOCurrency() const {
     return isoCode;
 }
 
index 512ebb8351f4e1a945a89ee2c4b36b5db27a9626..8374de3c2070526f5c116cafb311acaef4a2d26d 100644 (file)
@@ -566,7 +566,7 @@ public:
      * @return    the non-localized date-time pattern characters
      * @stable ICU 2.0
      */
-    static const UChar * U_EXPORT2 getPatternUChars(void);
+    static ConstChar16Ptr U_EXPORT2 getPatternUChars(void);
 
     /**
      * Gets localized date-time pattern characters. For example: 'u', 't', etc.
index 1907476ff30730e568f8c7fc9103764080128fd8..009d59f0916492bde6044e50b59aefff53fee373 100644 (file)
@@ -940,7 +940,7 @@ public:
      * the currency in use, or a pointer to the empty string.
      * @stable ICU 2.6
      */
-    const UChar* getCurrency() const;
+    ConstChar16Ptr getCurrency() const;
        
     /**
      * Set a particular UDisplayContext value in the formatter, such as
index b8d26612ff2f96c5c4c90b577e7e020f8b393648..458a79c7fdec85b870ac913604b711cf4a35360d 100644 (file)
@@ -609,7 +609,7 @@ unum_getTextAttribute(const UNumberFormat*  fmt,
             break;
 
         case UNUM_CURRENCY_CODE:
-            res = UnicodeString(df->getCurrency());
+            res = UnicodeString(df->getCurrency().get());
             break;
 
         default:
index 63d127346dae960926b6255577a59e169f0dc865..f9461739257c3b51e612d050a0525eac141c16ec 100644 (file)
@@ -514,7 +514,7 @@ void DateFormatTest::TestFieldPosition() {
     // local pattern chars data is not longer loaded
     // from icu locale bundle
     assertEquals("patternChars", PATTERN_CHARS, rootSyms.getLocalPatternChars(buf));
-    assertEquals("patternChars", PATTERN_CHARS, DateFormatSymbols::getPatternUChars());
+    assertEquals("patternChars", PATTERN_CHARS, DateFormatSymbols::getPatternUChars().get());
     assertTrue("DATEFORMAT_FIELD_NAMES", DATEFORMAT_FIELD_NAMES_LENGTH == UDAT_FIELD_COUNT);
 #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
     assertTrue("Data", UDAT_FIELD_COUNT == uprv_strlen(PATTERN_CHARS));
index ab5ce8c1272ca130354baa43bb81565f3b3bfd5f..bfefe3f857093ee88e4c3679da32f28d0ea9d621 100644 (file)
@@ -187,7 +187,7 @@ UnicodeString _toString(const Formattable& f) {
     case Formattable::kObject: {
         const CurrencyAmount* c = dynamic_cast<const CurrencyAmount*>(f.getObject());
         if (c != NULL) {
-            s = _toString(c->getNumber()) + " " + UnicodeString(c->getISOCurrency());
+            s = _toString(c->getNumber()) + " " + UnicodeString(c->getISOCurrency().get());
         } else {
             s = UnicodeString("Unknown UObject");
         }
index f34d8397c016d32a0f747101f9d33c8429aaab67..10fa1c749504d0adbd8824efd383ff5a51ca643d 100644 (file)
@@ -1856,7 +1856,7 @@ void MeasureFormatTest::TestCurrencies() {
     u_uastrcpy(USD, "USD");
     UErrorCode status = U_ZERO_ERROR;
     CurrencyAmount USD_1(1.0, USD, status);
-    assertEquals("Currency Code", USD, USD_1.getISOCurrency());
+    assertEquals("Currency Code", USD, USD_1.getISOCurrency().get());
     CurrencyAmount USD_2(2.0, USD, status);
     CurrencyAmount USD_NEG_1(-1.0, USD, status);
     if (!assertSuccess("Error creating currencies", status)) {
index a8553f57802c2e371dd1c74c0412d18586c3e929..ea67aa2d47c51ae6754021fb4402f60cfd138bfc 100644 (file)
@@ -440,7 +440,7 @@ UBool NumberFormatTestDataDriven::isParseCurrencyPass(
         }
         return TRUE;
     }
-    UnicodeString currStr(currAmt->getISOCurrency());
+    UnicodeString currStr(currAmt->getISOCurrency().get());
     Formattable resultFormattable(currAmt->getNumber());
     UnicodeString resultStr(UnicodeString::fromUTF8(resultFormattable.getDecimalNumber(status)));
     if (tuple.output == "fail") {
@@ -3168,7 +3168,7 @@ void NumberFormatTest::expectParseCurrency(const NumberFormat &fmt, const UChar*
 
     uprv_strcpy(theOperation, theInfo);
     uprv_strcat(theOperation, ", check currency:");
-    assertEquals(theOperation, currency, currencyAmount->getISOCurrency());
+    assertEquals(theOperation, currency, currencyAmount->getISOCurrency().get());
 }
   
 
@@ -3763,14 +3763,14 @@ NumberFormatTest::TestCurrencyFormatForMixParsing() {
         } else if (result.getType() != Formattable::kObject ||
             (curramt = dynamic_cast<const CurrencyAmount*>(result.getObject())) == NULL ||
             curramt->getNumber().getDouble() != 1234.56 ||
-            UnicodeString(curramt->getISOCurrency()).compare(ISO_CURRENCY_USD)
+            UnicodeString(curramt->getISOCurrency().get()).compare(ISO_CURRENCY_USD)
         ) {
             errln("FAIL: getCurrencyFormat of default locale (en_US) failed roundtripping the number ");
             if (curramt->getNumber().getDouble() != 1234.56) {
                 errln((UnicodeString)"wong number, expect: 1234.56" + ", got: " + curramt->getNumber().getDouble());
             }
             if (curramt->getISOCurrency() != ISO_CURRENCY_USD) {
-                errln((UnicodeString)"wong currency, expect: USD" + ", got: " + curramt->getISOCurrency());
+                errln((UnicodeString)"wong currency, expect: USD" + ", got: " + curramt->getISOCurrency().get());
             }
         }
     }
index 036d5e1d3551237073dd0ded1c902f2dcef450df..5cff8ee51d0f94fd487ab197cb5814a6a9f2940a 100644 (file)
@@ -547,7 +547,7 @@ UBool ThreadSafeFormat::doStuff(int32_t offset, UnicodeString &appendErr, UError
     appendErr.append("fFormat currency != ")
       .append(kUSD)
       .append(", =")
-      .append(fFormat->getCurrency())
+      .append(fFormat->getCurrency().get())
       .append("! ");
     okay = FALSE;
   }
@@ -556,7 +556,7 @@ UBool ThreadSafeFormat::doStuff(int32_t offset, UnicodeString &appendErr, UError
     appendErr.append("gFormat currency != ")
       .append(kUSD)
       .append(", =")
-      .append(gSharedData->fFormat->getCurrency())
+      .append(gSharedData->fFormat->getCurrency().get())
       .append("! ");
     okay = FALSE;
   }