本文整理汇总了C++中AvmCore::newStringUTF8方法的典型用法代码示例。如果您正苦于以下问题:C++ AvmCore::newStringUTF8方法的具体用法?C++ AvmCore::newStringUTF8怎么用?C++ AvmCore::newStringUTF8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AvmCore
的用法示例。
在下文中一共展示了AvmCore::newStringUTF8方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
ArrayObject * ProgramClass::_getEnviron()
{
Toplevel *toplevel = this->toplevel();
AvmCore *core = this->core();
ArrayObject *array = toplevel->arrayClass()->newArray();
#if AVMSYSTEM_WIN32
wchar **cur = VMPI_GetEnviron16();
int i = 0;
while( cur[i] )
{
Stringp value = core->newStringUTF16(cur[i]);
StUTF8String valueUTF8(value);
array->setUintProperty( i, core->newStringUTF8( valueUTF8.c_str() )->atom() );
i++;
}
#else
char **cur = VMPI_GetEnviron();
int i = 0;
while( cur[i] )
{
array->setUintProperty( i, core->newStringUTF8( cur[i] )->atom() );
i++;
}
#endif
return array;
}
示例2: memcpy
/*static*/ ChostentObject* CNetdbClass::gethostbyname(ScriptObject* self, Stringp name)
{
AvmCore *core = self->core();
Toplevel* toplevel = self->toplevel();
if( !name )
{
toplevel->throwArgumentError(kNullArgumentError, "name");
}
struct hostent *he;
StUTF8String nameUTF8(name);
he = VMPI_gethostbyname( nameUTF8.c_str() );
if( he )
{
ShellToplevel* shelltop = (ShellToplevel*)self->toplevel();
ChostentClass *hc = shelltop->getShellClasses()->get_hostentClass();
ChostentObject *ho = hc->constructObject();
ho->set_h_name( core->newStringUTF8( he->h_name ) );
ArrayObject *aliases = toplevel->arrayClass()->newArray();
int count = 0;
int i;
for( i=0; he->h_aliases[i] != NULL; ++i )
{
aliases->setUintProperty( count++, core->newStringUTF8( he->h_aliases[i] )->atom() );
}
ho->set_h_aliases( aliases );
ho->set_h_addrtype( he->h_addrtype );
ho->set_h_length( he->h_length );
ArrayObject *addrlist = toplevel->arrayClass()->newArray();
count = 0;
for( i=0; he->h_addr_list[i] != NULL; ++i )
{
struct in_addr in;
memcpy(&in.s_addr, he->h_addr_list[i], sizeof (in.s_addr));
CIn_AddrClass *ac = shelltop->getShellClasses()->get_in_addrClass();
CIn_AddrObject *ao = ac->constructObject();
ao->set_s_addr( in.s_addr );
addrlist->setUintProperty( count++, ao->toAtom() );
//addrlist->setUintProperty( count++, core->newStringUTF8( inet_ntoa(in) )->atom() );
}
ho->set_h_addr_list( addrlist );
return ho;
}
return NULL;
}
示例3:
/*static*/ CdirentObject* CDirentClass::readdir(ScriptObject* self, CDIRObject* dirp)
{
Toplevel* toplevel = self->toplevel();
if( !dirp )
{
toplevel->throwArgumentError(kNullArgumentError, "dirp");
}
dirent *entry = VMPI_readdir( dirp->read() );
if( entry )
{
ShellToplevel* shelltop = (ShellToplevel*)self->toplevel();
CdirentClass *direc = shelltop->getShellClasses()->get_direntClass();
CdirentObject *direo = direc->constructObject();
direo->write( entry );
AvmCore *core = self->core();
direo->set_d_ino( entry->d_ino );
direo->set_d_name( core->newStringUTF8( entry->d_name ) );
return direo;
}
return NULL;
}
示例4: read
Stringp FileClass::read(Stringp filename)
{
Toplevel* toplevel = this->toplevel();
AvmCore* core = this->core();
if (!filename) {
toplevel->throwArgumentError(kNullArgumentError, "filename");
}
StUTF8String filenameUTF8(filename);
File* fp = Platform::GetInstance()->createFile();
if(!fp || !fp->open(filenameUTF8.c_str(), File::OPEN_READ))
{
if(fp)
{
Platform::GetInstance()->destroyFile(fp);
}
toplevel->throwError(kFileOpenError, filename);
}
int64_t fileSize = fp->size();
if(fileSize >= (int64_t)INT32_T_MAX) //File APIs cannot handle files > 2GB
{
toplevel->throwRangeError(kOutOfRangeError, filename);
}
int len = (int)fileSize;
MMgc::GC::AllocaAutoPtr _c;
union {
uint8_t* c;
wchar* c_w;
};
c = (uint8_t*)VMPI_alloca(core, _c, len+1);
len = (int)fp->read(c, len); //need to force since the string creation functions expect an int
c[len] = 0;
fp->close();
Platform::GetInstance()->destroyFile(fp);
if (len >= 3)
{
// UTF8 BOM
if ((c[0] == 0xef) && (c[1] == 0xbb) && (c[2] == 0xbf))
{
return core->newStringUTF8((const char*)c + 3, len - 3);
}
else if ((c[0] == 0xfe) && (c[1] == 0xff))
{
//UTF-16 big endian
c += 2;
len = (len - 2) >> 1;
return core->newStringEndianUTF16(/*littleEndian*/false, c_w, len);
}
else if ((c[0] == 0xff) && (c[1] == 0xfe))
示例5: getFilename
Stringp HTTPFormClass::getFilename(Stringp key)
{
AvmCore *core = this->core();
string sKey(((StUTF8String) key).c_str());
for (std::vector<FormFile>::iterator it=sapi->files.begin(); it!=sapi->files.end(); it++)
if (sKey == (*it).name) return core->newStringUTF8((*it).filename.data(), (*it).filename.length());
return NULL;
}
示例6: read
Stringp FileClass::read(Stringp filename)
{
Toplevel* toplevel = this->toplevel();
AvmCore* core = this->core();
if (!filename) {
toplevel->throwArgumentError(kNullArgumentError, "filename");
}
StUTF8String filenameUTF8(filename);
File* fp = Platform::GetInstance()->createFile();
if(!fp || !fp->open(filenameUTF8.c_str(), File::OPEN_READ))
{
if(fp)
{
Platform::GetInstance()->destroyFile(fp);
}
toplevel->throwError(kFileOpenError, filename);
}
int64_t fileSize = fp->size();
if(fileSize >= (int64_t)INT32_T_MAX) //File APIs cannot handle files > 2GB
{
toplevel->throwRangeError(kOutOfRangeError, filename);
}
int len = (int)fileSize;
// Avoid VMPI_alloca - the buffer can be large and the memory is non-pointer-containing,
// but the GC will scan it conservatively.
uint8_t* c = (uint8_t*)core->gc->Alloc(len+1);
len = (int)fp->read(c, len); //need to force since the string creation functions expect an int
c[len] = 0;
fp->close();
Platform::GetInstance()->destroyFile(fp);
Stringp ret = NULL;
if (len >= 3)
{
// UTF8 BOM
if ((c[0] == 0xef) && (c[1] == 0xbb) && (c[2] == 0xbf))
{
ret = core->newStringUTF8((const char*)c + 3, len - 3);
}
else if ((c[0] == 0xfe) && (c[1] == 0xff))
{
//UTF-16 big endian
c += 2;
len = (len - 2) >> 1;
ret = core->newStringEndianUTF16(/*littleEndian*/false, (wchar*)(void*)c, len);
}
else if ((c[0] == 0xff) && (c[1] == 0xfe))
示例7: listFileKeys
ArrayObject* HTTPFormClass::listFileKeys()
{
AvmCore *core = this->core();
ArrayObject *out = this->toplevel()->arrayClass->newArray();
for (std::vector<FormFile>::iterator it=sapi->files.begin(); it!=sapi->files.end(); it++)
{
out->setUintProperty(out->get_length(), core->newStringUTF8((*it).name.data(), (*it).name.length())->atom());
}
return out;
}
示例8:
ArrayObject * ProgramClass::_getArgv()
{
Toplevel *toplevel = this->toplevel();
AvmCore *core = this->core();
ArrayObject *array = toplevel->arrayClass()->newArray();
for( int i=0; i<user_argc; i++ )
{
array->setUintProperty(i, core->newStringUTF8(user_argv[i])->atom());
}
return array;
}
示例9:
/*static*/ Stringp CStdlibClass::getenv(ScriptObject* self, Stringp name)
{
AvmCore *core = self->core();
Toplevel* toplevel = self->toplevel();
if( !name )
{
toplevel->throwArgumentError(kNullArgumentError, "name");
}
#if AVMSYSTEM_WIN32
StUTF16String nameUTF16(name);
const wchar * str = VMPI_getenv16( nameUTF16.c_str() );
Stringp value = core->newStringUTF16( str );
StUTF8String valueUTF8(value);
return core->newStringUTF8( valueUTF8.c_str() );
#else
StUTF8String nameUTF8(name);
const char * str = VMPI_getenv( nameUTF8.c_str() );
return core->newStringUTF8( str );
#endif
}
示例10: if
/*static*/ ArrayObject* CNetdbClass::getaddrinfo(ScriptObject* self, Stringp nodename, Stringp servname, CaddrinfoObject* hints, CEAIrrorObject* eaierr)
{
AvmCore *core = self->core();
Toplevel* toplevel = self->toplevel();
ShellToplevel* shelltop = (ShellToplevel*)self->toplevel();
if( !hints )
{
CaddrinfoClass *ai_c = shelltop->getShellClasses()->get_addrinfoClass();
CaddrinfoObject *hints = ai_c->constructObject();
//default properties
hints->set_ai_family( AF_UNSPEC );
hints->set_ai_socktype( SOCK_STREAM );
}
StUTF8String nodenameUTF8(nodename);
StUTF8String servnameUTF8(servname);
//(void)hints;
struct addrinfo h;
VMPI_memset(&h, 0, sizeof h);
h.ai_flags = hints->get_ai_flags();
h.ai_family = hints->get_ai_family();
h.ai_socktype = hints->get_ai_socktype();
h.ai_protocol = hints->get_ai_protocol();
//ignore other propertiess
struct addrinfo *res, *p;
int result = VMPI_getaddrinfo( nodenameUTF8.c_str(), servnameUTF8.c_str(), &h, &res );
if( result != 0 )
{
//printf( "getaddrinfo: %s\n", gai_strerror(result));
if( eaierr )
{
eaierr->call_apply( result );
}
return NULL;
}
ArrayObject *infolist = toplevel->arrayClass()->newArray();
int count = 0;
for( p = res; p != NULL; p = p->ai_next )
{
CaddrinfoClass *infoc = shelltop->getShellClasses()->get_addrinfoClass();
CaddrinfoObject *info = infoc->constructObject();
info->set_ai_flags( p->ai_flags );
info->set_ai_family( p->ai_family );
info->set_ai_socktype( p->ai_socktype );
info->set_ai_protocol( p->ai_protocol );
info->set_ai_addrlen( (int) p->ai_addrlen );
info->set_ai_canonname( core->newStringUTF8( p->ai_canonname ) );
if( p->ai_family == AF_INET )
{
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
CSockaddr_inClass *addr4c = shelltop->getShellClasses()->get_sockaddr_inClass();
CSockaddr_inObject *addr4o = addr4c->constructObject();
addr4o->set_sin_family( ipv4->sin_family );
addr4o->set_sin_port( ipv4->sin_port );
CIn_AddrClass *ac = shelltop->getShellClasses()->get_in_addrClass();
CIn_AddrObject *ao = ac->constructObject();
ao->set_s_addr( ipv4->sin_addr.s_addr );
addr4o->set_sin_addr( ao );
info->set_ai_addr( addr4o->toAtom() );
}
else if( p->ai_family == AF_INET6 )
{
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
CSockaddr_in6Class *addr6c = shelltop->getShellClasses()->get_sockaddr_in6Class();
CSockaddr_in6Object *addr6o = addr6c->constructObject();
addr6o->set_sin6_family( ipv6->sin6_family );
addr6o->set_sin6_port( ipv6->sin6_port );
addr6o->set_sin6_flowinfo( ipv6->sin6_flowinfo );
addr6o->set_sin6_scope_id( ipv6->sin6_scope_id );
CIn6_AddrClass *ac6 = shelltop->getShellClasses()->get_in6_addrClass();
CIn6_AddrObject *ao6 = ac6->constructObject();
ao6->fromStruct( ipv6->sin6_addr );
addr6o->set_sin6_addr( ao6 );
info->set_ai_addr( addr6o->toAtom() );
}
infolist->setUintProperty( count++, info->toAtom() );
}
VMPI_freeaddrinfo( res );
//.........这里部分代码省略.........
示例11:
/*static*/ Stringp CNetdbClass::gai_strerror(ScriptObject* self, int ecode)
{
AvmCore *core = self->core();
return core->newStringUTF8( VMPI_gai_strerror( ecode ) );
}
示例12: rawPostData
Stringp HTTPFormClass::rawPostData()
{
AvmCore* core = this->core();
Stringp s = core->newStringUTF8(sapi->postData.data(), sapi->postData.length());
return s;
}