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 \
--- /dev/null
+// © 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
<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>
<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>
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),
}
void
-Normalizer::setText(const UChar* newText,
+Normalizer::setText(ConstChar16Ptr newText,
int32_t length,
UErrorCode &status)
{
}
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();
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_),
// 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),
{
}
-UCharCharacterIterator::UCharCharacterIterator(const UChar* textPtr,
+UCharCharacterIterator::UCharCharacterIterator(ConstChar16Ptr textPtr,
int32_t length,
int32_t textBegin,
int32_t textEnd,
return pos;
}
-void UCharCharacterIterator::setText(const UChar* newText,
+void UCharCharacterIterator::setText(ConstChar16Ptr newText,
int32_t newTextLength) {
text = newText;
if(newText == 0 || newTextLength < 0) {
#define __CASEMAP_H__
#include "unicode/utypes.h"
+#include "unicode/char16ptr.h"
#include "unicode/uobject.h"
/**
*/
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);
/**
*/
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
*/
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
*/
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:
--- /dev/null
+// © 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__
* @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
* @param status a UErrorCode
* @deprecated ICU 56 Use Normalizer2 instead.
*/
- void setText(const UChar* newText,
+ void setText(ConstChar16Ptr newText,
int32_t length,
UErrorCode &status);
/**
* @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) {}
* @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
* 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.
* @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".
* @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);
/**
* @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);
* 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
#include <cstddef>
#include "unicode/utypes.h"
+#include "unicode/char16ptr.h"
#include "unicode/rep.h"
#include "unicode/std_string.h"
#include "unicode/stringpiece.h"
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
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.
*/
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) {
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
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
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
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) {
}
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);
//------------------------------------------------------
-const UChar * U_EXPORT2
+ConstChar16Ptr U_EXPORT2
DateFormatSymbols::getPatternUChars(void)
{
return gPatternChars;
}
}
-const UChar* NumberFormat::getCurrency() const {
+ConstChar16Ptr NumberFormat::getCurrency() const {
return fCurrency;
}
UErrorCode& status) const
{
translatePattern(fPattern, result,
- UnicodeString(DateFormatSymbols::getPatternUChars()),
+ UnicodeString(DateFormatSymbols::getPatternUChars().get()),
fSymbols->fLocalPatternChars, status);
return result;
}
{
translatePattern(pattern, fPattern,
fSymbols->fLocalPatternChars,
- UnicodeString(DateFormatSymbols::getPatternUChars()), status);
+ UnicodeString(DateFormatSymbols::getPatternUChars().get()), status);
}
//----------------------------------------------------------------------
* 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);
/**
* 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);
/**
* 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();
}
* 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
* Return the ISO currency code of this object.
* @stable ICU 3.0
*/
- inline const UChar* getISOCurrency() const;
+ inline ConstChar16Ptr getISOCurrency() const;
private:
/**
UChar isoCode[4];
};
-inline const UChar* CurrencyUnit::getISOCurrency() const {
+inline ConstChar16Ptr CurrencyUnit::getISOCurrency() const {
return isoCode;
}
* @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.
* 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
break;
case UNUM_CURRENCY_CODE:
- res = UnicodeString(df->getCurrency());
+ res = UnicodeString(df->getCurrency().get());
break;
default:
// 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));
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");
}
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)) {
}
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") {
uprv_strcpy(theOperation, theInfo);
uprv_strcat(theOperation, ", check currency:");
- assertEquals(theOperation, currency, currencyAmount->getISOCurrency());
+ assertEquals(theOperation, currency, currencyAmount->getISOCurrency().get());
}
} 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());
}
}
}
appendErr.append("fFormat currency != ")
.append(kUSD)
.append(", =")
- .append(fFormat->getCurrency())
+ .append(fFormat->getCurrency().get())
.append("! ");
okay = FALSE;
}
appendErr.append("gFormat currency != ")
.append(kUSD)
.append(", =")
- .append(gSharedData->fFormat->getCurrency())
+ .append(gSharedData->fFormat->getCurrency().get())
.append("! ");
okay = FALSE;
}