跳转至

ev-mold-string-starts-with-path-001

字段 值
项目 rui314/mold
固定 commit 27162691b71a
路径 lib/common.h
行段 L957-L960
特性 字符串与范围小工具
许可证 MIT
代码来源 项目源码
级别 manual
审核 zyuhao7 @ 2026-10-24
测试代码 否
发现方式 regex

用法

用 starts_with 判断路径是否绝对

为什么典型

把前缀判断写成单个谓词,替代 compare 或 find 的索引运算,边界由标准库处理。

摘录

template <typename Context>
MappedFile *open_file(Context &ctx, std::string path) {
  if (path.starts_with('/') && !ctx.arg.chroot.empty())
    path = ctx.arg.chroot + "/" + path_clean(path);

备注

生产路径;mold 构建声明 cxx_std_20。

查看固定 commit 源码 · 返回证据索引