Skip to content

Commit

Permalink
new: allow utf16 string with length
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU authored and kkoopa committed Oct 7, 2015
1 parent 7764a9a commit 66ac6e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Nan::MaybeLocal<v8::String> Nan::New<T>(std::string const& value);
Nan::MaybeLocal<v8::String> Nan::New<T>(const char * value, int length);
Nan::MaybeLocal<v8::String> Nan::New<T>(const char * value);
Nan::MaybeLocal<v8::String> Nan::New<T>(const uint16_t * value);
Nan::MaybeLocal<v8::String> Nan::New<T>(const uint16_t * value, int length);
```

Specialized types:
Expand Down
6 changes: 6 additions & 0 deletions nan_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ New(const char * value, int length) {
return New<v8::String>(value, length);
}

inline
imp::Factory<v8::String>::return_t
New(const uint16_t * value, int length) {
return New<v8::String>(value, length);
}

inline
imp::Factory<v8::String>::return_t
New(const char * value) {
Expand Down
6 changes: 5 additions & 1 deletion test/cpp/nannew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ NAN_METHOD(testSignature) {
NAN_METHOD(testString) {
Tap t(info[0]);

t.plan(14);
t.plan(16);

t.ok(_( stringMatches(
New<String>("Hello World").ToLocalChecked(), "Hello World")));
Expand Down Expand Up @@ -319,6 +319,10 @@ NAN_METHOD(testString) {
t.ok(_( stringMatches( New("Hello World", 4).ToLocalChecked(), "Hell")));
t.ok(_( assertType<String>( New("plonk.", 4).ToLocalChecked())));

const uint16_t *widestring = reinterpret_cast<const uint16_t *>("H\0e\0l\0l\0o\0");
t.ok(_( stringMatches( New(widestring, 4).ToLocalChecked(), "Hell")));
t.ok(_( assertType<String>( New(widestring, 4).ToLocalChecked())));

t.ok(_( stringMatches( New(std::string("bar")).ToLocalChecked(), "bar")));
t.ok(_( assertType<String>( New(std::string("plonk.")).ToLocalChecked())));

Expand Down

0 comments on commit 66ac6e6

Please sign in to comment.