7 #ifndef __CHAR16PTR_H__
8 #define __CHAR16PTR_H__
12 #if U_SHOW_CPLUSPLUS_API
15 #include <string_view>
31 #ifdef U_ALIASING_BARRIER
33 #elif (defined(__clang__) || defined(__GNUC__)) && U_PLATFORM != U_PF_BROWSER_NATIVE_CLIENT
34 # define U_ALIASING_BARRIER(ptr) asm volatile("" : : "rm"(ptr) : "memory")
35 #elif defined(U_IN_DOXYGEN)
36 # define U_ALIASING_BARRIER(ptr)
51 #if !U_CHAR16_IS_TYPEDEF
59 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
85 inline char16_t *
get()
const;
91 inline operator char16_t *()
const {
return get(); }
96 #ifdef U_ALIASING_BARRIER
97 template<
typename T>
static char16_t *cast(T *t) {
99 return reinterpret_cast<char16_t *
>(t);
113 #ifdef U_ALIASING_BARRIER
115 Char16Ptr::Char16Ptr(char16_t *p) : p_(p) {}
116 #if !U_CHAR16_IS_TYPEDEF
117 Char16Ptr::Char16Ptr(uint16_t *p) : p_(cast(p)) {}
119 #if U_SIZEOF_WCHAR_T==2
120 Char16Ptr::Char16Ptr(
wchar_t *p) : p_(cast(p)) {}
122 Char16Ptr::Char16Ptr(std::nullptr_t p) : p_(p) {}
131 Char16Ptr::Char16Ptr(char16_t *p) { u_.cp = p; }
132 #if !U_CHAR16_IS_TYPEDEF
133 Char16Ptr::Char16Ptr(uint16_t *p) { u_.up = p; }
135 #if U_SIZEOF_WCHAR_T==2
136 Char16Ptr::Char16Ptr(
wchar_t *p) { u_.wp = p; }
138 Char16Ptr::Char16Ptr(std::nullptr_t p) { u_.cp = p; }
158 #if !U_CHAR16_IS_TYPEDEF
166 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
193 inline const char16_t *
get()
const;
199 inline operator const char16_t *()
const {
return get(); }
204 #ifdef U_ALIASING_BARRIER
205 template<
typename T>
static const char16_t *cast(
const T *t) {
207 return reinterpret_cast<const char16_t *
>(t);
221 #ifdef U_ALIASING_BARRIER
223 ConstChar16Ptr::ConstChar16Ptr(
const char16_t *p) : p_(p) {}
224 #if !U_CHAR16_IS_TYPEDEF
225 ConstChar16Ptr::ConstChar16Ptr(
const uint16_t *p) : p_(cast(p)) {}
227 #if U_SIZEOF_WCHAR_T==2
228 ConstChar16Ptr::ConstChar16Ptr(
const wchar_t *p) : p_(cast(p)) {}
230 ConstChar16Ptr::ConstChar16Ptr(
const std::nullptr_t p) : p_(p) {}
239 ConstChar16Ptr::ConstChar16Ptr(
const char16_t *p) { u_.cp = p; }
240 #if !U_CHAR16_IS_TYPEDEF
241 ConstChar16Ptr::ConstChar16Ptr(
const uint16_t *p) { u_.up = p; }
243 #if U_SIZEOF_WCHAR_T==2
244 ConstChar16Ptr::ConstChar16Ptr(
const wchar_t *p) { u_.wp = p; }
246 ConstChar16Ptr::ConstChar16Ptr(
const std::nullptr_t p) { u_.cp = p; }
262 #ifdef U_ALIASING_BARRIER
265 return reinterpret_cast<const UChar *
>(p);
276 #ifdef U_ALIASING_BARRIER
279 return reinterpret_cast<UChar *
>(p);
290 #ifdef U_ALIASING_BARRIER
293 return reinterpret_cast<const OldUChar *
>(p);
304 #ifdef U_ALIASING_BARRIER
307 return reinterpret_cast<OldUChar *
>(p);
310 #ifndef U_FORCE_HIDE_INTERNAL_API
317 std::is_convertible_v<T, std::u16string_view>
318 #if !U_CHAR16_IS_TYPEDEF && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 180000)
319 || std::is_convertible_v<T, std::basic_string_view<uint16_t>>
321 #if U_SIZEOF_WCHAR_T==2
322 || std::is_convertible_v<T, std::wstring_view>
333 #if !U_CHAR16_IS_TYPEDEF && (!defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 180000)
344 #if U_SIZEOF_WCHAR_T==2
350 inline std::u16string_view toU16StringView(std::wstring_view sv) {
359 template <
typename T,
360 typename =
typename std::enable_if_t<!std::is_pointer_v<std::remove_reference_t<T>>>>
369 template <
typename T,
370 typename =
typename std::enable_if_t<std::is_pointer_v<std::remove_reference_t<T>>>,
373 if (text ==
nullptr)
return {};
std::u16string_view toU16StringView(std::u16string_view sv)
Pass-through overload.
std::u16string_view toU16StringViewNullable(const T &text)
Pass-through overload.
#define U_ALIASING_BARRIER(ptr)
Barrier for pointer anti-aliasing optimizations even across function boundaries.
char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Char16Ptr(std::nullptr_t p)
nullptr constructor.
Char16Ptr(uint16_t *p)
Converts the pointer to char16_t *.
Char16Ptr(wchar_t *p)
Converts the pointer to char16_t *.
char16_t * get() const
Pointer access.
Char16Ptr(char16_t *p)
Copies the pointer.
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
ConstChar16Ptr(const char16_t *p)
Copies the pointer.
const char16_t * get() const
Pointer access.
ConstChar16Ptr(const uint16_t *p)
Converts the pointer to char16_t *.
~ConstChar16Ptr()
Destructor.
ConstChar16Ptr(const wchar_t *p)
Converts the pointer to char16_t *.
ConstChar16Ptr(const std::nullptr_t p)
nullptr constructor.
constexpr bool ConvertibleToU16StringView
Is T convertible to a std::u16string_view or some other 16-bit string view?
const OldUChar * toOldUCharPtr(const char16_t *p)
Converts from const char16_t * to const OldUChar *.
const UChar * toUCharPtr(const char16_t *p)
Converts from const char16_t * to const UChar *.
char16_t UChar
The base type for UTF-16 code units and pointers.
uint16_t OldUChar
Default ICU 58 definition of UChar.
Basic definitions for ICU, for both C and C++ APIs.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.