nss: upgrade to release 3.73
[LibreOffice.git] / include / o3tl / char16_t2wchar_t.hxx
blob6ffab02e78c9dd2bc5846987e68590b88e61f73a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_O3TL_CHAR16_T2WCHAR_T_HXX
11 #define INCLUDED_O3TL_CHAR16_T2WCHAR_T_HXX
13 #include <sal/config.h>
15 namespace o3tl {
17 #if defined _WIN32
18 // Helpers for safe conversion between wchar_t and char16_t in MSVC
20 static_assert(sizeof(char16_t) == sizeof(wchar_t),
21 "These helper functions are only applicable to implementations with 16-bit wchar_t");
23 // While other implementations define wchar_t as 32-bit integral value, and mostly use
24 // char-based UTF-8 string APIs, in MSVC wchar_t is (non-conformant) 16-bit, and Unicode
25 // support is implemented by Unicode-aware WinAPI functions taking UTF-16 LE strings,
26 // and also stdlib functions taking those strings.
28 // In LibreOffice, internal string representation is also UTF-16 with system endianness
29 // (sal_Unicode that is typedef for char16_t); so it is an important implementation concept
30 // to treat internal strings as directly usable by WinAPI/stdlib functions and vice versa.
31 // Also, it's important to use safe conversion between unrelated underlying C++ types
32 // used for MSVC and LibreOffice string storage without plain reinterpret_cast that brings
33 // risks of masking errors like casting char buffers to wchar_t/char16_t.
35 // Use these helpers for wchar_t (WSTR, WCHAR, OLESTR etc) to char16_t (sal_Unicode) string
36 // conversions instead of reinterpret-cast in Windows-specific code.
37 inline wchar_t * toW(char16_t * p)
39 return reinterpret_cast<wchar_t *>(p);
41 inline wchar_t const * toW(char16_t const * p)
43 return reinterpret_cast<wchar_t const *>(p);
45 inline char16_t * toU(wchar_t * p)
47 return reinterpret_cast<char16_t *>(p);
49 inline char16_t const * toU(wchar_t const * p)
51 return reinterpret_cast<char16_t const *>(p);
53 #endif
57 #endif
59 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */