本文整理汇总了C++中Local::Utf8Length方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::Utf8Length方法的具体用法?C++ Local::Utf8Length怎么用?C++ Local::Utf8Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::Utf8Length方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
char* V8StringToFunctionChar(Handle<String> str) {
Local<String> prefix = String::New("(");
Local<String> postfix = String::New(")();");
Local<String> result = String::Concat(prefix,str);
result = String::Concat(result,postfix);
int len = result->Utf8Length();
char* buf = new char[len + 1];
result->WriteUtf8(buf, len);
buf[len] = '\0';
return buf;
}
示例2: New
// static
void Query::New(const FunctionCallbackInfo<Value>& args)
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.IsConstructCall()) {
if (args.Length() != 1) {
Local<String> str = String::NewFromUtf8(isolate, "Consturctor expects 1 agument");
isolate->ThrowException(Exception::TypeError(str));
return;
}
if (!args[0]->IsString()) {
Local<String> str = String::NewFromUtf8(isolate, "Argument must be a string");
isolate->ThrowException(Exception::TypeError(str));
return;
}
Local<String> str = args[0]->ToString();
QByteArray arr;
arr.resize(str->Utf8Length());
str->WriteUtf8(arr.data(), arr.length());
QString queryString = QString::fromUtf8(arr);
Query* query = new Query(queryString);
query->Wrap(args.This());
args.GetReturnValue().Set(args.This());
}
else {
// Invoked as plain function, turn into construct call.
const int argc = 1;
Local<Value> argv[argc] = { args[0] };
Local<Function> cons = Local<Function>::New(isolate, s_constructor);
args.GetReturnValue().Set(cons->NewInstance(argc, argv));
}
}
示例3: ThrowException
/**
* Generates 32-bit CRC
*/
Handle<Value> GenerateFastCRC32(const Arguments& args) {
HandleScope scope;
Local<String> input;
Local<Integer> output;
// Ensure an argument is passed
if (args.Length() < 1) {
return scope.Close(Undefined());
}
// Ensure the argument is not an object
if (args[0]->IsObject()) {
ThrowException(Exception::TypeError(String::New("Cannot compute CRC-32 for objects!")));
return scope.Close(Undefined());
}
// Convert the argument into a string
input = args[0]->ToString();
// Calculate the 32-bit CRC
output = Integer::NewFromUnsigned(fastcrc((char *) *(v8::String::Utf8Value(input)), input->Utf8Length()));
return scope.Close(output);
}
示例4: GetParametersFromArray
Parameter* ODBC::GetParametersFromArray (Local<Array> values, int *paramCount) {
DEBUG_PRINTF("ODBC::GetParametersFromArray\n");
*paramCount = values->Length();
Parameter* params = (Parameter *) malloc(*paramCount * sizeof(Parameter));
for (int i = 0; i < *paramCount; i++) {
Local<Value> value = values->Get(i);
params[i].size = 0;
params[i].length = SQL_NULL_DATA;
params[i].buffer_length = 0;
params[i].decimals = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - ¶m[%i].length = %X\n",
i, ¶ms[i].length);
if (value->IsString()) {
Local<String> string = value->ToString();
int length = string->Length();
params[i].c_type = SQL_C_TCHAR;
#ifdef UNICODE
params[i].type = (length >= 8000) ? SQL_WLONGVARCHAR : SQL_WVARCHAR;
params[i].buffer_length = (length * sizeof(uint16_t)) + sizeof(uint16_t);
#else
params[i].type = (length >= 8000) ? SQL_LONGVARCHAR : SQL_VARCHAR;
params[i].buffer_length = string->Utf8Length() + 1;
#endif
params[i].buffer = malloc(params[i].buffer_length);
params[i].size = params[i].buffer_length;
params[i].length = SQL_NTS;//params[i].buffer_length;
#ifdef UNICODE
string->Write((uint16_t *) params[i].buffer);
#else
string->WriteUtf8((char *) params[i].buffer);
#endif
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsString(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i "
"value=%s\n", i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length,
(char*) params[i].buffer);
}
else if (value->IsNull()) {
params[i].c_type = SQL_C_DEFAULT;
params[i].type = SQL_VARCHAR;
params[i].length = SQL_NULL_DATA;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNull(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i\n",
i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length);
}
else if (value->IsInt32()) {
int64_t *number = new int64_t(value->IntegerValue());
params[i].c_type = SQL_C_SBIGINT;
params[i].type = SQL_BIGINT;
params[i].buffer = number;
params[i].length = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsInt32(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i "
"value=%lld\n", i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length,
*number);
}
else if (value->IsNumber()) {
double *number = new double(value->NumberValue());
params[i].c_type = SQL_C_DOUBLE;
params[i].type = SQL_DECIMAL;
params[i].buffer = number;
params[i].buffer_length = sizeof(double);
params[i].length = params[i].buffer_length;
params[i].decimals = 7;
params[i].size = sizeof(double);
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNumber(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i "
"value=%f\n",
i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length,
*number);
}
else if (value->IsBoolean()) {
bool *boolean = new bool(value->BooleanValue());
params[i].c_type = SQL_C_BIT;
params[i].type = SQL_BIT;
params[i].buffer = boolean;
params[i].length = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsBoolean(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i\n",
i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length);
}
}
//.........这里部分代码省略.........
示例5: GetParametersFromArray
Parameter* ODBC::GetParametersFromArray (Local<Array> values, int *paramCount) {
DEBUG_PRINTF("ODBC::GetParametersFromArray\n");
*paramCount = values->Length();
Parameter* params = NULL;
if (*paramCount > 0) {
params = (Parameter *) malloc(*paramCount * sizeof(Parameter));
}
for (int i = 0; i < *paramCount; i++) {
Local<Value> value = values->Get(i);
params[i].ColumnSize = 0;
params[i].StrLen_or_IndPtr = SQL_NULL_DATA;
params[i].BufferLength = 0;
params[i].DecimalDigits = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - param[%i].length = %lli\n",
i, params[i].StrLen_or_IndPtr);
if (value->IsString()) {
Local<String> string = value->ToString();
int length = string->Length();
params[i].ValueType = SQL_C_TCHAR;
params[i].ColumnSize = 0; //SQL_SS_LENGTH_UNLIMITED
#ifdef UNICODE
params[i].ParameterType = SQL_WVARCHAR;
params[i].BufferLength = (length * sizeof(uint16_t)) + sizeof(uint16_t);
#else
params[i].ParameterType = SQL_VARCHAR;
params[i].BufferLength = string->Utf8Length() + 1;
#endif
params[i].ParameterValuePtr = malloc(params[i].BufferLength);
params[i].StrLen_or_IndPtr = SQL_NTS;//params[i].BufferLength;
#ifdef UNICODE
string->Write((uint16_t *) params[i].ParameterValuePtr);
#else
string->WriteUtf8((char *) params[i].ParameterValuePtr);
#endif
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsString(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli value=%s\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr,
(char*) params[i].ParameterValuePtr);
}
else if (value->IsNull()) {
params[i].ValueType = SQL_C_DEFAULT;
params[i].ParameterType = SQL_VARCHAR;
params[i].StrLen_or_IndPtr = SQL_NULL_DATA;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNull(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr);
}
else if (value->IsInt32()) {
int64_t *number = new int64_t(value->IntegerValue());
params[i].ValueType = SQL_C_SBIGINT;
params[i].ParameterType = SQL_BIGINT;
params[i].ParameterValuePtr = number;
params[i].StrLen_or_IndPtr = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsInt32(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli value=%lld\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr,
*number);
}
else if (value->IsNumber()) {
double *number = new double(value->NumberValue());
params[i].ValueType = SQL_C_DOUBLE;
params[i].ParameterType = SQL_DECIMAL;
params[i].ParameterValuePtr = number;
params[i].BufferLength = sizeof(double);
params[i].StrLen_or_IndPtr = params[i].BufferLength;
params[i].DecimalDigits = 7;
params[i].ColumnSize = sizeof(double);
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNumber(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli value=%f\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr,
*number);
}
else if (value->IsBoolean()) {
bool *boolean = new bool(value->BooleanValue());
params[i].ValueType = SQL_C_BIT;
params[i].ParameterType = SQL_BIT;
params[i].ParameterValuePtr = boolean;
params[i].StrLen_or_IndPtr = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsBoolean(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr);
}
}
return params;
}
示例6: Undefined
Handle<Value>
NodeSandbox::node_spawn(const Arguments& args)
{
HandleScope scope;
char** argv;
std::map<std::string, std::string> envp;
SandboxWrapper* wrap;
wrap = node::ObjectWrap::Unwrap<SandboxWrapper>(args.This());
argv = static_cast<char**>(calloc (sizeof (char*), args.Length()+1));
argv[args.Length()] = nullptr;
for(int i = 0; i < args.Length(); i++) {
if (args[i]->IsString()) {
Local<String> v = args[i]->ToString();
argv[i] = static_cast<char*>(calloc(sizeof(char), v->Utf8Length()+1));
v->WriteUtf8(argv[i]);
} else {
if (i <= args.Length() - 2 ) {
ThrowException(Exception::TypeError(String::New("Arguments must be strings.")));
goto out;
} else {
// Last parameter is an options structure
Local<Object> options = args[i]->ToObject();
if (!options.IsEmpty()) {
if (options->HasRealNamedProperty(String::NewSymbol("env"))) {
Local<Object> envOptions = options->Get(String::NewSymbol("env"))->ToObject();
if (!envOptions.IsEmpty()) {
Local<Array> envArray = envOptions->GetOwnPropertyNames();
for (uint32_t i = 0; i < envArray->Length(); i++) {
std::vector<char> strName;
std::vector<char> strValue;
Local<String> envName;
Local<String> envValue;
if (!(envArray->Get(i)->IsString() && envArray->Get(i)->IsString()))
goto err_env;
envName = envArray->Get(i)->ToString();
envValue = envOptions->Get(envName)->ToString();
strName.resize (envName->Utf8Length()+1);
strValue.resize (envValue->Utf8Length()+1);
envName->WriteUtf8 (strName.data());
envValue->WriteUtf8 (strValue.data());
envp.insert (std::make_pair(std::string (strName.data()), std::string(strValue.data())));
}
} else {
goto err_env;
}
}
} else {
goto err_options;
}
}
}
}
wrap->sbox->getVFS().setCWD ("/contract/");
wrap->sbox->spawn(argv, envp);
goto out;
err_env:
ThrowException(Exception::TypeError(String::New("'env' option must be a map of string:string")));
goto out;
err_options:
ThrowException(Exception::TypeError(String::New("Last argument must be an options structure.")));
goto out;
out:
for (int i = 0; i < args.Length();i ++) {
free (argv[i]);
}
free (argv);
return Undefined();
}