nodejs / nodejs/node-addon-api
Unify handling of string-like arguments across the API
还没有人认领这个 Issue。
- 主要语言
- 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>.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 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