Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / o3tl / runtimetooustring.hxx
blob7f20158057224d2fecdde642d6ee7d38f4ff9f4a
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_RUNTIMETOOUSTRING_HXX
11 #define INCLUDED_O3TL_RUNTIMETOOUSTRING_HXX
13 #include <sal/config.h>
15 #include <cassert>
16 #include <cstring>
18 #include <rtl/textcvt.h>
19 #include <rtl/textenc.h>
20 #include <rtl/ustring.h>
21 #include <rtl/ustring.hxx>
23 namespace o3tl {
25 /** Convert an NTBS from the C++ runtime to an OUString.
27 This is used to convert an NTBS as provided by std::exception::what or
28 std::type_info::name into an OUString in a "lossless" way. The conversion
29 is done using RTL_TEXTENCODING_ISO_8859_1, so each char in the input maps
30 to one Unicode character in the output.
32 inline OUString runtimeToOUString(char const * runtimeString) {
33 OUString s;
34 bool ok = rtl_convertStringToUString(
35 &s.pData, runtimeString, std::strlen(runtimeString),
36 RTL_TEXTENCODING_ISO_8859_1,
37 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
38 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
39 | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR));
40 assert(ok); (void) ok;
41 return s;
46 #endif
48 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */