本文整理汇总了C++中AvmCore::newString方法的典型用法代码示例。如果您正苦于以下问题:C++ AvmCore::newString方法的具体用法?C++ AvmCore::newString怎么用?C++ AvmCore::newString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AvmCore
的用法示例。
在下文中一共展示了AvmCore::newString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _toString
/**
* Object.prototype.toString()
*/
Stringp ObjectClass::_toString(Atom thisAtom)
{
AvmCore* core = this->core();
if (core->istype(thisAtom, CLASS_TYPE))
{
ClassClosure *cc = (ClassClosure *)AvmCore::atomToScriptObject(thisAtom);
Traits* t = cc->ivtable()->traits;
Stringp s = core->concatStrings(core->newString("[class "), t->name);
return core->concatStrings(s, core->newString("]"));
}
else
{
Traits* t = toplevel()->toTraits(thisAtom);
Stringp s = core->concatStrings(core->newString("[object "), t->name);
return core->concatStrings(s, core->newString("]"));
}
}
示例2: read
Stringp FileClass::read(Stringp filename)
{
Toplevel* toplevel = this->toplevel();
AvmCore* core = this->core();
if (!filename) {
toplevel->throwArgumentError(kNullArgumentError, "filename");
}
UTF8String* filenameUTF8 = filename->toUTF8String();
FILE *fp = fopen(filenameUTF8->c_str(), "r");
if (fp == NULL) {
toplevel->throwError(kFileOpenError, filename);
}
fseek(fp, 0L, SEEK_END);
long len = ftell(fp);
#ifdef UNDER_CE
fseek (fp, 0L, SEEK_SET);
#else
rewind(fp);
#endif
unsigned char *c = new unsigned char[len+1];
len = (long)fread(c, 1, len, fp);
c[len] = 0;
fclose(fp);
if (len >= 3)
{
// UTF8 BOM
if ((c[0] == 0xef) && (c[1] == 0xbb) && (c[2] == 0xbf))
{
return core->newString(((char *)c) + 3, len - 3);
}
else if ((c[0] == 0xfe) && (c[1] == 0xff))
{
//UTF-16 big endian
c += 2;
len = (len - 2) >> 1;
Stringp out = new (core->GetGC()) String(len);
wchar *buffer = out->lockBuffer();
for (long i = 0; i < len; i++)
{
buffer[i] = (c[0] << 8) + c[1];
c += 2;
}
out->unlockBuffer();
return out;
}
else if ((c[0] == 0xff) && (c[1] == 0xfe))
示例3: split
ArrayObject* RegExpObject::split(Stringp subject, uint32 limit)
{
AvmCore *core = this->core();
ArrayObject *out = toplevel()->arrayClass->newArray();
UsesUTF8String utf8Subject(subject);
int startIndex=0;
int matchIndex;
int matchLen;
ArrayObject* matchArray;
unsigned n=0;
bool isEmptyRE = m_source->length() == 0;
while ((matchArray = _exec(subject,
utf8Subject,
startIndex,
matchIndex,
matchLen)) != NULL)
{
// [cn 11/22/04] when match is made, but is length 0 we've matched the empty
// position between characters. Although we've "matched", its zero length so just break out.
if (matchLen == 0 ) {
matchLen = 0;
matchIndex = startIndex+numBytesInUtf8Character((uint8*)(utf8Subject->c_str())+startIndex); // +1char will advance startIndex, extract just one char
if( !isEmptyRE )
{
// don't break if we're processing an empty regex - then we want to split the string into each character
// so we want the loop to continue
break;
}
}
//[ed 8/10/04] don't go past end of string. not sure why pcre doesn't return null
//for a match starting past the end.
//[cn 12/3/04] because a regular expression which matches an empty position (space between characters)
// will match the empty position just past the last character. This test is correct, though
// it needs to come before we do any setProperties to avoid a bogus xtra result.
if (matchIndex+matchLen > utf8Subject->length()) {
startIndex = matchIndex+matchLen;
break;
} else {
out->setUintProperty(n++,
(core->newString(utf8Subject->c_str()+startIndex,
matchIndex-startIndex))->atom());
if (n >= limit)
break;
for (uint32 j=1; j<matchArray->getLength(); j++) {
out->setUintProperty(n++, matchArray->getUintProperty(j));
if (n >= limit)
break;
}
// Advance past this match
startIndex = matchIndex+matchLen;
}
}
// If we found no match, or we did find a match and are still under limit, and there is a remainder left, add it
if ((unsigned)n < limit && startIndex <= utf8Subject->length()) {
out->setUintProperty(n++,
(core->newString(utf8Subject->c_str()+startIndex,
utf8Subject->length()-startIndex))->atom());
}
return out;
}