ev-mold-string-view-starts-with-demangle-003¶
| 字段 | 值 |
|---|---|
| 项目 | rui314/mold |
| 固定 commit | 27162691b71a |
| 路径 | lib/demangle.cc |
| 行段 | L13-L27 |
| 特性 | 字符串与范围小工具 |
| 许可证 | MIT |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-24 |
| 测试代码 | 否 |
| 发现方式 | regex |
用法¶
在 string_view 上检查 Itanium 名称前缀
为什么典型¶
视图上直接判断,不构造 std::string,也没有空终止假设;适合处理来自符号表的非拥有字符串。
摘录¶
std::optional<std::string_view> demangle_cpp(std::string_view name) {
static thread_local char *buf;
static thread_local size_t buflen;
// TODO(cwasser): Actually demangle Symbols on Windows using e.g.
// `UnDecorateSymbolName` from Dbghelp, maybe even Itanium symbols?
#ifndef _WIN32
if (name.starts_with("_Z")) {
int status;
char *p = abi::__cxa_demangle(std::string(name).c_str(), buf, &buflen, &status);
if (status == 0) {
buf = p;
return p;
}
}
备注¶
生产路径;摘录保留平台条件与返回路径。