Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/o3tl/runtimetooustring.hxx
Line
Count
Source
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.
4
 *
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
 */
9
10
#ifndef INCLUDED_O3TL_RUNTIMETOOUSTRING_HXX
11
#define INCLUDED_O3TL_RUNTIMETOOUSTRING_HXX
12
13
#include <sal/config.h>
14
15
#include <cassert>
16
#include <cstring>
17
18
#include <rtl/textcvt.h>
19
#include <rtl/textenc.h>
20
#include <rtl/ustring.h>
21
#include <rtl/ustring.hxx>
22
23
namespace o3tl
24
{
25
/** Convert an NTBS from the C++ runtime to an OUString.
26
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.
31
*/
32
inline OUString runtimeToOUString(char const* runtimeString)
33
42
{
34
42
    OUString s;
35
42
    bool ok = rtl_convertStringToUString(
36
42
        &s.pData, runtimeString, std::strlen(runtimeString), RTL_TEXTENCODING_ISO_8859_1,
37
42
        (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
38
42
         | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR));
39
    assert(ok);
40
42
    (void)ok;
41
42
    return s;
42
42
}
43
}
44
45
#endif
46
47
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */