From: Markus Scherer Date: Fri, 3 Mar 2017 23:55:13 +0000 (+0000) Subject: ICU-12992 remove Char16Ptr output conversion overloads, remove wrapper-as-pointer... X-Git-Tag: release-59-rc~119^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=568486c964aedd75e64b9cdc2b3c941a4caee508;p=icu ICU-12992 remove Char16Ptr output conversion overloads, remove wrapper-as-pointer operators, some cleanup X-SVN-Rev: 39730 --- diff --git a/icu4c/source/common/Makefile.in b/icu4c/source/common/Makefile.in index 5a82fbf7262..10fa8de38eb 100644 --- a/icu4c/source/common/Makefile.in +++ b/icu4c/source/common/Makefile.in @@ -95,7 +95,7 @@ bytestrie.o bytestrieiterator.o \ ucharstrie.o ucharstriebuilder.o ucharstrieiterator.o \ dictionarydata.o \ edits.o \ -char16ptr.o appendable.o ustr_cnv.o unistr_cnv.o unistr.o unistr_case.o unistr_props.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 deleted file mode 100644 index 5afec2af303..00000000000 --- a/icu4c/source/common/char16ptr.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// © 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 - -U_NAMESPACE_END diff --git a/icu4c/source/common/common.vcxproj b/icu4c/source/common/common.vcxproj index 9e760180666..33ef60e2b99 100644 --- a/icu4c/source/common/common.vcxproj +++ b/icu4c/source/common/common.vcxproj @@ -448,7 +448,6 @@ - diff --git a/icu4c/source/common/common.vcxproj.filters b/icu4c/source/common/common.vcxproj.filters index b29fe2fc4f2..0542a8b1384 100644 --- a/icu4c/source/common/common.vcxproj.filters +++ b/icu4c/source/common/common.vcxproj.filters @@ -463,9 +463,6 @@ strings - - strings - strings diff --git a/icu4c/source/common/unicode/char16ptr.h b/icu4c/source/common/unicode/char16ptr.h index 1d75f694f31..780a1502738 100644 --- a/icu4c/source/common/unicode/char16ptr.h +++ b/icu4c/source/common/unicode/char16ptr.h @@ -30,19 +30,20 @@ U_NAMESPACE_BEGIN #endif /** - * char16_t * wrapper with implicit conversion from/to distinct but bit-compatible pointer types. + * char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types. * @draft ICU 59 */ class U_COMMON_API Char16Ptr final { public: /** * Copies the pointer. - * TODO: @param p ... + * @param p pointer * @draft ICU 59 */ inline Char16Ptr(char16_t *p); /** * Converts the pointer to char16_t *. + * @param p pointer to be converted * @draft ICU 59 */ inline Char16Ptr(uint16_t *p); @@ -50,12 +51,14 @@ public: /** * Converts the pointer to char16_t *. * (Only defined if U_SIZEOF_WCHAR_T==2.) + * @param p pointer to be converted * @draft ICU 59 */ inline Char16Ptr(wchar_t *p); #endif /** * nullptr constructor. + * @param p nullptr * @draft ICU 59 */ inline Char16Ptr(std::nullptr_t p); @@ -67,59 +70,16 @@ public: /** * Pointer access. - * TODO @return ... + * @return the wrapped pointer * @draft ICU 59 */ inline char16_t *get() const; /** * char16_t pointer access via type conversion (e.g., static_cast). + * @return the wrapped pointer * @draft ICU 59 */ - operator char16_t *() const { return get(); } - // TODO: do we need output conversion and other operator overloads - // if we do not change return values to pointer wrappers? - /** - * 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[](std::ptrdiff_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(*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(*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 0. - * @return TRUE if the pointer is nullptr and zero==0 - * @draft ICU 59 - */ - UBool operator==(int zero) const { return get() == nullptr && zero == 0; } - /** - * Comparison with 0. - * @return TRUE if the pointer is not nullptr and zero==0 - * @draft ICU 59 - */ - UBool operator!=(int zero) const { return get() != nullptr && zero == 0; } - - Char16Ptr operator+(std::ptrdiff_t offset) const { return Char16Ptr(get() + offset); } + inline operator char16_t *() const { return get(); } private: Char16Ptr() = delete; @@ -154,17 +114,6 @@ Char16Ptr::~Char16Ptr() { char16_t *Char16Ptr::get() const { return p; } -Char16Ptr::operator uint16_t *() const { - U_ALIASING_BARRIER(p); - return reinterpret_cast(p); -} -#if U_SIZEOF_WCHAR_T==2 -Char16Ptr::operator wchar_t *() const { - U_ALIASING_BARRIER(p); - return reinterpret_cast(p); -} -#endif - #else Char16Ptr::Char16Ptr(char16_t *p) { u.cp = p; } @@ -177,30 +126,23 @@ 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/to distinct but bit-compatible pointer types. + * const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types. * @draft ICU 59 */ class U_COMMON_API ConstChar16Ptr final { public: /** * Copies the pointer. + * @param p pointer * @draft ICU 59 */ inline ConstChar16Ptr(const char16_t *p); /** * Converts the pointer to char16_t *. + * @param p pointer to be converted * @draft ICU 59 */ inline ConstChar16Ptr(const uint16_t *p); @@ -208,12 +150,14 @@ public: /** * Converts the pointer to char16_t *. * (Only defined if U_SIZEOF_WCHAR_T==2.) + * @param p pointer to be converted * @draft ICU 59 */ inline ConstChar16Ptr(const wchar_t *p); #endif /** * nullptr constructor. + * @param p nullptr * @draft ICU 59 */ inline ConstChar16Ptr(const std::nullptr_t p); @@ -225,46 +169,16 @@ public: /** * Pointer access. + * @return the wrapped pointer * @draft ICU 59 */ inline const char16_t *get() const; /** * char16_t pointer access via type conversion (e.g., static_cast). + * @return the wrapped pointer * @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[](std::ptrdiff_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(*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(*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 zero) const { return get() == nullptr && zero == 0; } - UBool operator!=(int zero) const { return get() != nullptr && zero == 0; } - - ConstChar16Ptr operator+(std::ptrdiff_t offset) { return ConstChar16Ptr(get() + offset); } + inline operator const char16_t *() const { return get(); } private: ConstChar16Ptr() = delete; @@ -299,17 +213,6 @@ ConstChar16Ptr::~ConstChar16Ptr() { const char16_t *ConstChar16Ptr::get() const { return p; } -ConstChar16Ptr::operator const uint16_t *() const { - U_ALIASING_BARRIER(p); - return reinterpret_cast(p); -} -#if U_SIZEOF_WCHAR_T==2 -ConstChar16Ptr::operator const wchar_t *() const { - U_ALIASING_BARRIER(p); - return reinterpret_cast(p); -} -#endif - #else ConstChar16Ptr::ConstChar16Ptr(const char16_t *p) { u.cp = p; } @@ -322,15 +225,6 @@ 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 diff --git a/icu4c/source/common/unicode/unistr.h b/icu4c/source/common/unicode/unistr.h index 3de890666aa..9eedd2f52df 100644 --- a/icu4c/source/common/unicode/unistr.h +++ b/icu4c/source/common/unicode/unistr.h @@ -3017,7 +3017,7 @@ public: * @draft ICU 59 */ UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) : - UnicodeString(ConstChar16Ptr(text).get()) {} + UnicodeString(ConstChar16Ptr(text)) {} #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) /** @@ -3032,7 +3032,7 @@ public: * @draft ICU 59 */ UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) : - UnicodeString(ConstChar16Ptr(text).get()) {} + UnicodeString(ConstChar16Ptr(text)) {} #endif /** @@ -3065,7 +3065,7 @@ public: * @draft ICU 59 */ UnicodeString(const uint16_t *text, int32_t length) : - UnicodeString(ConstChar16Ptr(text).get(), length) {} + UnicodeString(ConstChar16Ptr(text), length) {} #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) /** @@ -3077,7 +3077,7 @@ public: * @draft ICU 59 */ UnicodeString(const wchar_t *text, int32_t length) : - UnicodeString(ConstChar16Ptr(text).get(), length) {} + UnicodeString(ConstChar16Ptr(text), length) {} #endif /** @@ -3144,7 +3144,7 @@ public: * @draft ICU 59 */ UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) : - UnicodeString(Char16Ptr(buffer).get(), buffLength, buffCapacity) {} + UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {} #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) /** @@ -3157,7 +3157,7 @@ public: * @draft ICU 59 */ UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) : - UnicodeString(Char16Ptr(buffer).get(), buffLength, buffCapacity) {} + UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {} #endif /** diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index 29ea82df7f1..416b909917d 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -875,11 +875,10 @@ UnicodeString::doExtract(int32_t start, } int32_t -UnicodeString::extract(Char16Ptr destPtr, int32_t destCapacity, +UnicodeString::extract(Char16Ptr dest, int32_t destCapacity, UErrorCode &errorCode) const { int32_t len = length(); if(U_SUCCESS(errorCode)) { - UChar *dest = destPtr; if(isBogus() || destCapacity<0 || (destCapacity>0 && dest==0)) { errorCode=U_ILLEGAL_ARGUMENT_ERROR; } else {