mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-12992 remove Char16Ptr output conversion overloads, remove wrapper-as-pointer operators, some cleanup
X-SVN-Rev: 39730
This commit is contained in:
parent
5a13a8ca58
commit
568486c964
7 changed files with 24 additions and 148 deletions
|
@ -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 \
|
||||
|
|
|
@ -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
|
|
@ -448,7 +448,6 @@
|
|||
<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" />
|
||||
|
|
|
@ -463,9 +463,6 @@
|
|||
<ClCompile Include="bytestream.cpp">
|
||||
<Filter>strings</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="char16ptr.cpp">
|
||||
<Filter>strings</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="chariter.cpp">
|
||||
<Filter>strings</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -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<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 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<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; }
|
||||
|
@ -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<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 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<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; }
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue