nodejs / nodejs/node-addon-api
Unify handling of string-like arguments across the API
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C++
- Sterne
- 2.4k
- Forks
- 499
- Ø Merge
- 2 T. 11 Std.
- Gemergte PRs (30 T.)
- 2
Beschreibung
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>.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Deklarationen und Implementierungen von String::New, Symbol::New und Symbol::For zu finden, und vergleiche anschließend deren bestehende std::string- und std::string_view-Überladungen. Erledigt ist die Aufgabe, wenn die redundanten Überladungen über das eingeschränkte string_view-ähnliche Template vereinheitlicht sind, während const char* und Literale ihre dedizierte Behandlung behalten und nullptr weiterhin ausgeschlossen bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- cpp
- Bereich
- api
- Issue-Typ
- Refactoring
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100