/src/serenity/AK/Demangle.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #ifndef KERNEL |
10 | | |
11 | | # include <AK/ByteString.h> |
12 | | # include <AK/StringView.h> |
13 | | # include <cxxabi.h> |
14 | | |
15 | | namespace AK { |
16 | | |
17 | | inline ByteString demangle(StringView name) |
18 | 0 | { |
19 | 0 | int status = 0; |
20 | 0 | auto* demangled_name = abi::__cxa_demangle(name.to_byte_string().characters(), nullptr, nullptr, &status); |
21 | 0 | auto string = ByteString(status == 0 ? StringView { demangled_name, strlen(demangled_name) } : name); |
22 | 0 | if (status == 0) |
23 | 0 | free(demangled_name); |
24 | 0 | return string; |
25 | 0 | } |
26 | | |
27 | | } |
28 | | |
29 | | # if USING_AK_GLOBALLY |
30 | | using AK::demangle; |
31 | | # endif |
32 | | |
33 | | #endif |