nodejs / nodejs/node-addon-api

Unify handling of string-like arguments across the API

未关闭
#1,745 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

SemVer-major
主要语言
C++
星标
2.4k
派生
499
平均合并
2 天 11 小时
30 天内合并 PR
2

描述

Follow-up to #1741 / #1742.

Several APIs still carry multiple overloads for different string types. Now that the library requires C++17, we can modernize by preferring std::string_view and removing the redundant UTF-8 overloads, replacing them with a single constrained template, as a semver-major change.

For String::New, Symbol::New, and Symbol::For, collapse the const std::string& + std::string_view pair into:

template <typename T,
          std::enable_if_t<
              std::is_convertible_v<const T&, std::string_view> &&
              !std::is_convertible_v<const T&, const char*>, int> = 0>
static String New(napi_env env, const T& t);

This matches the C++17 standard-library idiom (std::string's find/append/compare/… members). The !is_convertible_v<const T&, const char*> clause keeps const char* and literals on the dedicated overload and filters nullptr (avoiding a UB string_view(nullptr)).

The enable_if alias is shareable across APIs e.g. enable_if_string_view_like_t<T>.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先定位 String::New、Symbol::New 和 Symbol::For 的声明与实现,然后比较它们现有的 std::string 和 std::string_view 重载。完成的标准是:通过受约束的 string_view-like 模板统一冗余重载,同时保留 const char* 和字面量的专用处理,并继续排除 nullptr。

由索引模型根据 Issue 内容生成。

评估

技术栈
cpp
领域
api
Issue 类型
重构
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。