MCPcopy Create free account
hub / github.com/nodejs/node-addon-api / CheckString

Function CheckString

test/name.cc:52–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52Value CheckString(const CallbackInfo& info) {
53 String value = info[0].As<String>();
54 String encoding = info[1].As<String>();
55 Value length = info[2];
56
57 if (encoding.Utf8Value() == "utf8") {
58 std::string testValue = testValueUtf8;
59 if (!length.IsUndefined()) {
60 testValue = testValue.substr(0, length.As<Number>().Uint32Value());
61 }
62
63 std::string stringValue = value;
64 return Boolean::New(info.Env(), stringValue == testValue);
65 } else if (encoding.Utf8Value() == "utf16") {
66 std::u16string testValue = testValueUtf16;
67 if (!length.IsUndefined()) {
68 testValue = testValue.substr(0, length.As<Number>().Uint32Value());
69 }
70
71 std::u16string stringValue = value;
72 return Boolean::New(info.Env(), stringValue == testValue);
73 } else {
74 Error::New(info.Env(), "Invalid encoding.").ThrowAsJavaScriptException();
75 return Value();
76 }
77}
78
79Value CreateSymbol(const CallbackInfo& info) {
80 Value description = info[0];

Callers

nothing calls this directly

Calls 3

EnvMethod · 0.80
ValueClass · 0.50

Tested by

no test coverage detected