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