1*0e209d39SAndroid Build Coastguard Worker // © 2017 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker 4*0e209d39SAndroid Build Coastguard Worker // char16ptr.h 5*0e209d39SAndroid Build Coastguard Worker // created: 2017feb28 Markus W. Scherer 6*0e209d39SAndroid Build Coastguard Worker 7*0e209d39SAndroid Build Coastguard Worker #ifndef __CHAR16PTR_H__ 8*0e209d39SAndroid Build Coastguard Worker #define __CHAR16PTR_H__ 9*0e209d39SAndroid Build Coastguard Worker 10*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 11*0e209d39SAndroid Build Coastguard Worker 12*0e209d39SAndroid Build Coastguard Worker #if LIBICU_U_SHOW_CPLUSPLUS_API 13*0e209d39SAndroid Build Coastguard Worker 14*0e209d39SAndroid Build Coastguard Worker #include <cstddef> 15*0e209d39SAndroid Build Coastguard Worker 16*0e209d39SAndroid Build Coastguard Worker /** 17*0e209d39SAndroid Build Coastguard Worker * @addtogroup icu4c ICU4C 18*0e209d39SAndroid Build Coastguard Worker * @{ 19*0e209d39SAndroid Build Coastguard Worker * \file 20*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: char16_t pointer wrappers with 21*0e209d39SAndroid Build Coastguard Worker * implicit conversion from bit-compatible raw pointer types. 22*0e209d39SAndroid Build Coastguard Worker * Also conversion functions from char16_t * to UChar * and OldUChar *. 23*0e209d39SAndroid Build Coastguard Worker */ 24*0e209d39SAndroid Build Coastguard Worker 25*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 26*0e209d39SAndroid Build Coastguard Worker 27*0e209d39SAndroid Build Coastguard Worker /** 28*0e209d39SAndroid Build Coastguard Worker * \def U_ALIASING_BARRIER 29*0e209d39SAndroid Build Coastguard Worker * Barrier for pointer anti-aliasing optimizations even across function boundaries. 30*0e209d39SAndroid Build Coastguard Worker * \xrefitem internal "Internal" "Internal List" Do not use. This API is for internal use only. 31*0e209d39SAndroid Build Coastguard Worker */ 32*0e209d39SAndroid Build Coastguard Worker #ifdef U_ALIASING_BARRIER 33*0e209d39SAndroid Build Coastguard Worker // Use the predefined value. 34*0e209d39SAndroid Build Coastguard Worker #elif (defined(__clang__) || defined(__GNUC__)) && U_PLATFORM != U_PF_BROWSER_NATIVE_CLIENT 35*0e209d39SAndroid Build Coastguard Worker # define U_ALIASING_BARRIER(ptr) asm volatile("" : : "rm"(ptr) : "memory") 36*0e209d39SAndroid Build Coastguard Worker #elif defined(U_IN_DOXYGEN) 37*0e209d39SAndroid Build Coastguard Worker # define U_ALIASING_BARRIER(ptr) 38*0e209d39SAndroid Build Coastguard Worker #endif 39*0e209d39SAndroid Build Coastguard Worker 40*0e209d39SAndroid Build Coastguard Worker /** 41*0e209d39SAndroid Build Coastguard Worker * char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types. 42*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 43*0e209d39SAndroid Build Coastguard Worker */ 44*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API Char16Ptr final { 45*0e209d39SAndroid Build Coastguard Worker public: 46*0e209d39SAndroid Build Coastguard Worker /** 47*0e209d39SAndroid Build Coastguard Worker * Copies the pointer. 48*0e209d39SAndroid Build Coastguard Worker * @param p pointer 49*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 50*0e209d39SAndroid Build Coastguard Worker */ 51*0e209d39SAndroid Build Coastguard Worker inline Char16Ptr(char16_t *p); 52*0e209d39SAndroid Build Coastguard Worker #if !U_CHAR16_IS_TYPEDEF 53*0e209d39SAndroid Build Coastguard Worker /** 54*0e209d39SAndroid Build Coastguard Worker * Converts the pointer to char16_t *. 55*0e209d39SAndroid Build Coastguard Worker * @param p pointer to be converted 56*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 57*0e209d39SAndroid Build Coastguard Worker */ 58*0e209d39SAndroid Build Coastguard Worker inline Char16Ptr(uint16_t *p); 59*0e209d39SAndroid Build Coastguard Worker #endif 60*0e209d39SAndroid Build Coastguard Worker #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 61*0e209d39SAndroid Build Coastguard Worker /** 62*0e209d39SAndroid Build Coastguard Worker * Converts the pointer to char16_t *. 63*0e209d39SAndroid Build Coastguard Worker * (Only defined if U_SIZEOF_WCHAR_T==2.) 64*0e209d39SAndroid Build Coastguard Worker * @param p pointer to be converted 65*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 66*0e209d39SAndroid Build Coastguard Worker */ 67*0e209d39SAndroid Build Coastguard Worker inline Char16Ptr(wchar_t *p); 68*0e209d39SAndroid Build Coastguard Worker #endif 69*0e209d39SAndroid Build Coastguard Worker /** 70*0e209d39SAndroid Build Coastguard Worker * nullptr constructor. 71*0e209d39SAndroid Build Coastguard Worker * @param p nullptr 72*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 73*0e209d39SAndroid Build Coastguard Worker */ 74*0e209d39SAndroid Build Coastguard Worker inline Char16Ptr(std::nullptr_t p); 75*0e209d39SAndroid Build Coastguard Worker /** 76*0e209d39SAndroid Build Coastguard Worker * Destructor. 77*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 78*0e209d39SAndroid Build Coastguard Worker */ 79*0e209d39SAndroid Build Coastguard Worker inline ~Char16Ptr(); 80*0e209d39SAndroid Build Coastguard Worker 81*0e209d39SAndroid Build Coastguard Worker /** 82*0e209d39SAndroid Build Coastguard Worker * Pointer access. 83*0e209d39SAndroid Build Coastguard Worker * @return the wrapped pointer 84*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 85*0e209d39SAndroid Build Coastguard Worker */ 86*0e209d39SAndroid Build Coastguard Worker inline char16_t *get() const; 87*0e209d39SAndroid Build Coastguard Worker /** 88*0e209d39SAndroid Build Coastguard Worker * char16_t pointer access via type conversion (e.g., static_cast). 89*0e209d39SAndroid Build Coastguard Worker * @return the wrapped pointer 90*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 91*0e209d39SAndroid Build Coastguard Worker */ 92*0e209d39SAndroid Build Coastguard Worker inline operator char16_t *() const { return get(); } 93*0e209d39SAndroid Build Coastguard Worker 94*0e209d39SAndroid Build Coastguard Worker private: 95*0e209d39SAndroid Build Coastguard Worker Char16Ptr() = delete; 96*0e209d39SAndroid Build Coastguard Worker 97*0e209d39SAndroid Build Coastguard Worker #ifdef U_ALIASING_BARRIER cast(T * t)98*0e209d39SAndroid Build Coastguard Worker template<typename T> static char16_t *cast(T *t) { 99*0e209d39SAndroid Build Coastguard Worker U_ALIASING_BARRIER(t); 100*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<char16_t *>(t); 101*0e209d39SAndroid Build Coastguard Worker } 102*0e209d39SAndroid Build Coastguard Worker 103*0e209d39SAndroid Build Coastguard Worker char16_t *p_; 104*0e209d39SAndroid Build Coastguard Worker #else 105*0e209d39SAndroid Build Coastguard Worker union { 106*0e209d39SAndroid Build Coastguard Worker char16_t *cp; 107*0e209d39SAndroid Build Coastguard Worker uint16_t *up; 108*0e209d39SAndroid Build Coastguard Worker wchar_t *wp; 109*0e209d39SAndroid Build Coastguard Worker } u_; 110*0e209d39SAndroid Build Coastguard Worker #endif 111*0e209d39SAndroid Build Coastguard Worker }; 112*0e209d39SAndroid Build Coastguard Worker 113*0e209d39SAndroid Build Coastguard Worker /// \cond 114*0e209d39SAndroid Build Coastguard Worker #ifdef U_ALIASING_BARRIER 115*0e209d39SAndroid Build Coastguard Worker Char16Ptr(char16_t * p)116*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::Char16Ptr(char16_t *p) : p_(p) {} 117*0e209d39SAndroid Build Coastguard Worker #if !U_CHAR16_IS_TYPEDEF Char16Ptr(uint16_t * p)118*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::Char16Ptr(uint16_t *p) : p_(cast(p)) {} 119*0e209d39SAndroid Build Coastguard Worker #endif 120*0e209d39SAndroid Build Coastguard Worker #if U_SIZEOF_WCHAR_T==2 Char16Ptr(wchar_t * p)121*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::Char16Ptr(wchar_t *p) : p_(cast(p)) {} 122*0e209d39SAndroid Build Coastguard Worker #endif Char16Ptr(std::nullptr_t p)123*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::Char16Ptr(std::nullptr_t p) : p_(p) {} ~Char16Ptr()124*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::~Char16Ptr() { 125*0e209d39SAndroid Build Coastguard Worker U_ALIASING_BARRIER(p_); 126*0e209d39SAndroid Build Coastguard Worker } 127*0e209d39SAndroid Build Coastguard Worker get()128*0e209d39SAndroid Build Coastguard Workerchar16_t *Char16Ptr::get() const { return p_; } 129*0e209d39SAndroid Build Coastguard Worker 130*0e209d39SAndroid Build Coastguard Worker #else 131*0e209d39SAndroid Build Coastguard Worker Char16Ptr(char16_t * p)132*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::Char16Ptr(char16_t *p) { u_.cp = p; } 133*0e209d39SAndroid Build Coastguard Worker #if !U_CHAR16_IS_TYPEDEF Char16Ptr(uint16_t * p)134*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::Char16Ptr(uint16_t *p) { u_.up = p; } 135*0e209d39SAndroid Build Coastguard Worker #endif 136*0e209d39SAndroid Build Coastguard Worker #if U_SIZEOF_WCHAR_T==2 Char16Ptr(wchar_t * p)137*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::Char16Ptr(wchar_t *p) { u_.wp = p; } 138*0e209d39SAndroid Build Coastguard Worker #endif Char16Ptr(std::nullptr_t p)139*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::Char16Ptr(std::nullptr_t p) { u_.cp = p; } ~Char16Ptr()140*0e209d39SAndroid Build Coastguard WorkerChar16Ptr::~Char16Ptr() {} 141*0e209d39SAndroid Build Coastguard Worker get()142*0e209d39SAndroid Build Coastguard Workerchar16_t *Char16Ptr::get() const { return u_.cp; } 143*0e209d39SAndroid Build Coastguard Worker 144*0e209d39SAndroid Build Coastguard Worker #endif 145*0e209d39SAndroid Build Coastguard Worker /// \endcond 146*0e209d39SAndroid Build Coastguard Worker 147*0e209d39SAndroid Build Coastguard Worker /** 148*0e209d39SAndroid Build Coastguard Worker * const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types. 149*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 150*0e209d39SAndroid Build Coastguard Worker */ 151*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API ConstChar16Ptr final { 152*0e209d39SAndroid Build Coastguard Worker public: 153*0e209d39SAndroid Build Coastguard Worker /** 154*0e209d39SAndroid Build Coastguard Worker * Copies the pointer. 155*0e209d39SAndroid Build Coastguard Worker * @param p pointer 156*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 157*0e209d39SAndroid Build Coastguard Worker */ 158*0e209d39SAndroid Build Coastguard Worker inline ConstChar16Ptr(const char16_t *p); 159*0e209d39SAndroid Build Coastguard Worker #if !U_CHAR16_IS_TYPEDEF 160*0e209d39SAndroid Build Coastguard Worker /** 161*0e209d39SAndroid Build Coastguard Worker * Converts the pointer to char16_t *. 162*0e209d39SAndroid Build Coastguard Worker * @param p pointer to be converted 163*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 164*0e209d39SAndroid Build Coastguard Worker */ 165*0e209d39SAndroid Build Coastguard Worker inline ConstChar16Ptr(const uint16_t *p); 166*0e209d39SAndroid Build Coastguard Worker #endif 167*0e209d39SAndroid Build Coastguard Worker #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 168*0e209d39SAndroid Build Coastguard Worker /** 169*0e209d39SAndroid Build Coastguard Worker * Converts the pointer to char16_t *. 170*0e209d39SAndroid Build Coastguard Worker * (Only defined if U_SIZEOF_WCHAR_T==2.) 171*0e209d39SAndroid Build Coastguard Worker * @param p pointer to be converted 172*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 173*0e209d39SAndroid Build Coastguard Worker */ 174*0e209d39SAndroid Build Coastguard Worker inline ConstChar16Ptr(const wchar_t *p); 175*0e209d39SAndroid Build Coastguard Worker #endif 176*0e209d39SAndroid Build Coastguard Worker /** 177*0e209d39SAndroid Build Coastguard Worker * nullptr constructor. 178*0e209d39SAndroid Build Coastguard Worker * @param p nullptr 179*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 180*0e209d39SAndroid Build Coastguard Worker */ 181*0e209d39SAndroid Build Coastguard Worker inline ConstChar16Ptr(const std::nullptr_t p); 182*0e209d39SAndroid Build Coastguard Worker 183*0e209d39SAndroid Build Coastguard Worker /** 184*0e209d39SAndroid Build Coastguard Worker * Destructor. 185*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 186*0e209d39SAndroid Build Coastguard Worker */ 187*0e209d39SAndroid Build Coastguard Worker inline ~ConstChar16Ptr(); 188*0e209d39SAndroid Build Coastguard Worker 189*0e209d39SAndroid Build Coastguard Worker /** 190*0e209d39SAndroid Build Coastguard Worker * Pointer access. 191*0e209d39SAndroid Build Coastguard Worker * @return the wrapped pointer 192*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 193*0e209d39SAndroid Build Coastguard Worker */ 194*0e209d39SAndroid Build Coastguard Worker inline const char16_t *get() const; 195*0e209d39SAndroid Build Coastguard Worker /** 196*0e209d39SAndroid Build Coastguard Worker * char16_t pointer access via type conversion (e.g., static_cast). 197*0e209d39SAndroid Build Coastguard Worker * @return the wrapped pointer 198*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 199*0e209d39SAndroid Build Coastguard Worker */ 200*0e209d39SAndroid Build Coastguard Worker inline operator const char16_t *() const { return get(); } 201*0e209d39SAndroid Build Coastguard Worker 202*0e209d39SAndroid Build Coastguard Worker private: 203*0e209d39SAndroid Build Coastguard Worker ConstChar16Ptr() = delete; 204*0e209d39SAndroid Build Coastguard Worker 205*0e209d39SAndroid Build Coastguard Worker #ifdef U_ALIASING_BARRIER cast(const T * t)206*0e209d39SAndroid Build Coastguard Worker template<typename T> static const char16_t *cast(const T *t) { 207*0e209d39SAndroid Build Coastguard Worker U_ALIASING_BARRIER(t); 208*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<const char16_t *>(t); 209*0e209d39SAndroid Build Coastguard Worker } 210*0e209d39SAndroid Build Coastguard Worker 211*0e209d39SAndroid Build Coastguard Worker const char16_t *p_; 212*0e209d39SAndroid Build Coastguard Worker #else 213*0e209d39SAndroid Build Coastguard Worker union { 214*0e209d39SAndroid Build Coastguard Worker const char16_t *cp; 215*0e209d39SAndroid Build Coastguard Worker const uint16_t *up; 216*0e209d39SAndroid Build Coastguard Worker const wchar_t *wp; 217*0e209d39SAndroid Build Coastguard Worker } u_; 218*0e209d39SAndroid Build Coastguard Worker #endif 219*0e209d39SAndroid Build Coastguard Worker }; 220*0e209d39SAndroid Build Coastguard Worker 221*0e209d39SAndroid Build Coastguard Worker /// \cond 222*0e209d39SAndroid Build Coastguard Worker #ifdef U_ALIASING_BARRIER 223*0e209d39SAndroid Build Coastguard Worker ConstChar16Ptr(const char16_t * p)224*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::ConstChar16Ptr(const char16_t *p) : p_(p) {} 225*0e209d39SAndroid Build Coastguard Worker #if !U_CHAR16_IS_TYPEDEF ConstChar16Ptr(const uint16_t * p)226*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::ConstChar16Ptr(const uint16_t *p) : p_(cast(p)) {} 227*0e209d39SAndroid Build Coastguard Worker #endif 228*0e209d39SAndroid Build Coastguard Worker #if U_SIZEOF_WCHAR_T==2 ConstChar16Ptr(const wchar_t * p)229*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::ConstChar16Ptr(const wchar_t *p) : p_(cast(p)) {} 230*0e209d39SAndroid Build Coastguard Worker #endif ConstChar16Ptr(const std::nullptr_t p)231*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::ConstChar16Ptr(const std::nullptr_t p) : p_(p) {} ~ConstChar16Ptr()232*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::~ConstChar16Ptr() { 233*0e209d39SAndroid Build Coastguard Worker U_ALIASING_BARRIER(p_); 234*0e209d39SAndroid Build Coastguard Worker } 235*0e209d39SAndroid Build Coastguard Worker get()236*0e209d39SAndroid Build Coastguard Workerconst char16_t *ConstChar16Ptr::get() const { return p_; } 237*0e209d39SAndroid Build Coastguard Worker 238*0e209d39SAndroid Build Coastguard Worker #else 239*0e209d39SAndroid Build Coastguard Worker ConstChar16Ptr(const char16_t * p)240*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::ConstChar16Ptr(const char16_t *p) { u_.cp = p; } 241*0e209d39SAndroid Build Coastguard Worker #if !U_CHAR16_IS_TYPEDEF ConstChar16Ptr(const uint16_t * p)242*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::ConstChar16Ptr(const uint16_t *p) { u_.up = p; } 243*0e209d39SAndroid Build Coastguard Worker #endif 244*0e209d39SAndroid Build Coastguard Worker #if U_SIZEOF_WCHAR_T==2 ConstChar16Ptr(const wchar_t * p)245*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::ConstChar16Ptr(const wchar_t *p) { u_.wp = p; } 246*0e209d39SAndroid Build Coastguard Worker #endif ConstChar16Ptr(const std::nullptr_t p)247*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::ConstChar16Ptr(const std::nullptr_t p) { u_.cp = p; } ~ConstChar16Ptr()248*0e209d39SAndroid Build Coastguard WorkerConstChar16Ptr::~ConstChar16Ptr() {} 249*0e209d39SAndroid Build Coastguard Worker get()250*0e209d39SAndroid Build Coastguard Workerconst char16_t *ConstChar16Ptr::get() const { return u_.cp; } 251*0e209d39SAndroid Build Coastguard Worker 252*0e209d39SAndroid Build Coastguard Worker #endif 253*0e209d39SAndroid Build Coastguard Worker /// \endcond 254*0e209d39SAndroid Build Coastguard Worker 255*0e209d39SAndroid Build Coastguard Worker /** 256*0e209d39SAndroid Build Coastguard Worker * Converts from const char16_t * to const UChar *. 257*0e209d39SAndroid Build Coastguard Worker * Includes an aliasing barrier if available. 258*0e209d39SAndroid Build Coastguard Worker * @param p pointer 259*0e209d39SAndroid Build Coastguard Worker * @return p as const UChar * 260*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 261*0e209d39SAndroid Build Coastguard Worker */ toUCharPtr(const char16_t * p)262*0e209d39SAndroid Build Coastguard Workerinline const UChar *toUCharPtr(const char16_t *p) { 263*0e209d39SAndroid Build Coastguard Worker #ifdef U_ALIASING_BARRIER 264*0e209d39SAndroid Build Coastguard Worker U_ALIASING_BARRIER(p); 265*0e209d39SAndroid Build Coastguard Worker #endif 266*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<const UChar *>(p); 267*0e209d39SAndroid Build Coastguard Worker } 268*0e209d39SAndroid Build Coastguard Worker 269*0e209d39SAndroid Build Coastguard Worker /** 270*0e209d39SAndroid Build Coastguard Worker * Converts from char16_t * to UChar *. 271*0e209d39SAndroid Build Coastguard Worker * Includes an aliasing barrier if available. 272*0e209d39SAndroid Build Coastguard Worker * @param p pointer 273*0e209d39SAndroid Build Coastguard Worker * @return p as UChar * 274*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 275*0e209d39SAndroid Build Coastguard Worker */ toUCharPtr(char16_t * p)276*0e209d39SAndroid Build Coastguard Workerinline UChar *toUCharPtr(char16_t *p) { 277*0e209d39SAndroid Build Coastguard Worker #ifdef U_ALIASING_BARRIER 278*0e209d39SAndroid Build Coastguard Worker U_ALIASING_BARRIER(p); 279*0e209d39SAndroid Build Coastguard Worker #endif 280*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<UChar *>(p); 281*0e209d39SAndroid Build Coastguard Worker } 282*0e209d39SAndroid Build Coastguard Worker 283*0e209d39SAndroid Build Coastguard Worker /** 284*0e209d39SAndroid Build Coastguard Worker * Converts from const char16_t * to const OldUChar *. 285*0e209d39SAndroid Build Coastguard Worker * Includes an aliasing barrier if available. 286*0e209d39SAndroid Build Coastguard Worker * @param p pointer 287*0e209d39SAndroid Build Coastguard Worker * @return p as const OldUChar * 288*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 289*0e209d39SAndroid Build Coastguard Worker */ toOldUCharPtr(const char16_t * p)290*0e209d39SAndroid Build Coastguard Workerinline const OldUChar *toOldUCharPtr(const char16_t *p) { 291*0e209d39SAndroid Build Coastguard Worker #ifdef U_ALIASING_BARRIER 292*0e209d39SAndroid Build Coastguard Worker U_ALIASING_BARRIER(p); 293*0e209d39SAndroid Build Coastguard Worker #endif 294*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<const OldUChar *>(p); 295*0e209d39SAndroid Build Coastguard Worker } 296*0e209d39SAndroid Build Coastguard Worker 297*0e209d39SAndroid Build Coastguard Worker /** 298*0e209d39SAndroid Build Coastguard Worker * Converts from char16_t * to OldUChar *. 299*0e209d39SAndroid Build Coastguard Worker * Includes an aliasing barrier if available. 300*0e209d39SAndroid Build Coastguard Worker * @param p pointer 301*0e209d39SAndroid Build Coastguard Worker * @return p as OldUChar * 302*0e209d39SAndroid Build Coastguard Worker * \xrefitem stable "Stable" "Stable List" ICU 59 303*0e209d39SAndroid Build Coastguard Worker */ toOldUCharPtr(char16_t * p)304*0e209d39SAndroid Build Coastguard Workerinline OldUChar *toOldUCharPtr(char16_t *p) { 305*0e209d39SAndroid Build Coastguard Worker #ifdef U_ALIASING_BARRIER 306*0e209d39SAndroid Build Coastguard Worker U_ALIASING_BARRIER(p); 307*0e209d39SAndroid Build Coastguard Worker #endif 308*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<OldUChar *>(p); 309*0e209d39SAndroid Build Coastguard Worker } 310*0e209d39SAndroid Build Coastguard Worker 311*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 312*0e209d39SAndroid Build Coastguard Worker 313*0e209d39SAndroid Build Coastguard Worker #endif /* LIBICU_U_SHOW_CPLUSPLUS_API */ 314*0e209d39SAndroid Build Coastguard Worker 315*0e209d39SAndroid Build Coastguard Worker #endif // __CHAR16PTR_H__ 316*0e209d39SAndroid Build Coastguard Worker 317*0e209d39SAndroid Build Coastguard Worker /** @} */ // addtogroup 318