File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 2020#endif // NAPI_HAS_THREADS
2121#include < type_traits>
2222#include < utility>
23+ #if __cplusplus >= 201703L
24+ #include < string_view>
25+ #endif
2326
2427#if defined(__clang__) || defined(__GNUC__)
2528#define NAPI_NO_SANITIZE_VPTR __attribute__ ((no_sanitize(" vptr" )))
@@ -1255,6 +1258,12 @@ inline String String::New(napi_env env, const std::u16string& val) {
12551258 return String::New (env, val.c_str (), val.size ());
12561259}
12571260
1261+ #if __cplusplus >= 201703L
1262+ inline String String::New (napi_env env, const std::string_view& val) {
1263+ return String::New (env, val.data (), val.size ());
1264+ }
1265+ #endif
1266+
12581267inline String String::New (napi_env env, const char * val) {
12591268 // TODO(@gabrielschulhof) Remove if-statement when core's error handling is
12601269 // available in all supported versions.
Original file line number Diff line number Diff line change 1919#endif // NAPI_HAS_THREADS
2020#include < string>
2121#include < vector>
22+ #if __cplusplus >= 201703L
23+ #include < string_view>
24+ #endif
2225
2326// VS2015 RTM has bugs with constexpr, so require min of VS2015 Update 3 (known
2427// good version)
@@ -718,6 +721,14 @@ class String : public Name {
718721 const std::u16string& value // /< UTF-16 encoded C++ string
719722 );
720723
724+ #if __cplusplus >= 201703L
725+ // / Creates a new String value from a UTF-8 encoded C++ string view.
726+ static String New (
727+ napi_env env, // /< Node-API environment
728+ const std::string_view& value // /< UTF-8 encoded C++ string view
729+ );
730+ #endif
731+
721732 // / Creates a new String value from a UTF-8 encoded C string.
722733 static String New (
723734 napi_env env, // /< Node-API environment
You can’t perform that action at this time.
0 commit comments