aboutsummaryrefslogtreecommitdiff
path: root/index.cpp
blob: 25a359d81e2aff7a9a04999d17bfecbdb22d2541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <node.h>
#include <v8.h>

#include <iostream>
#include <stdlib.h>
#include "iconvlite.h"
#include "vkext_flex.h"

using namespace v8;

void flex(const FunctionCallbackInfo<Value>& args) {
    Isolate* isolate = args.GetIsolate();

    String::Utf8Value nameArg(args[0]);
    std::string nameString(*nameArg);
    std::string nameStringWindows1251 = utf2cp(nameString);

    String::Utf8Value caseArg(args[2]);
    std::string caseString(*caseArg);
    std::string caseStringWindows1251 = utf2cp(caseString);

    String::Utf8Value typeArg(args[3]);
    std::string typeString(*typeArg);
    std::string ctypeStringWindows1251 = utf2cp(typeString);

    int sex = (int)args[1]->NumberValue();
    int lang = (int)args[4]->NumberValue();

    char *result = do_flex(
        nameStringWindows1251.c_str(),
        nameStringWindows1251.length(),
        caseStringWindows1251.c_str(),
        caseStringWindows1251.length(),
        sex,
        ctypeStringWindows1251.c_str(),
        lang);

    std::string resultStringWindows1251(result);
    free(result);

    std::string resultString = cp2utf(resultStringWindows1251);

    args.GetReturnValue().Set(String::NewFromUtf8(isolate, resultString.c_str()));
}

void Init(Handle<Object> exports) {
    NODE_SET_METHOD(exports, "flex", flex);
}

NODE_MODULE(vkext_flex, Init)