MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / ConvertChunk

Method ConvertChunk

node/opencc.cc:208–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206 }
207
208 Napi::Value ConvertChunk(const Napi::CallbackInfo& info) {
209 Napi::Env env = info.Env();
210 if (info.Length() < 1 || (!info[0].IsBuffer() && !info[0].IsString())) {
211 Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
212 return env.Undefined();
213 }
214
215 try {
216 std::string output;
217 if (info[0].IsBuffer()) {
218 Napi::Buffer<char> input = info[0].As<Napi::Buffer<char>>();
219 output = stream_->ConvertChunk({input.Data(), input.Length()});
220 } else {
221 const std::string input = ToUtf8String(info[0]);
222 output = stream_->ConvertChunk(input);
223 }
224 return Napi::String::New(env, output);
225 } catch (opencc::Exception& e) {
226 Napi::Error::New(env, e.what()).ThrowAsJavaScriptException();
227 return env.Undefined();
228 }
229 }
230
231 Napi::Value Finish(const Napi::CallbackInfo& info) {
232 Napi::Env env = info.Env();

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
ToUtf8StringFunction · 0.85
LengthMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected