示例#1
0
    Stringp ProgramClass::_popenRead(Stringp command)
    {
        if( !command )
        {
            toplevel()->throwArgumentError(kNullArgumentError, "command");
        }

        StUTF8String commandUTF8(command);
        FILE *read_fp;
        char buffer[BUFSIZ + 1];
        int chars_read;

        VMPI_memset(buffer, '\0', sizeof(buffer));
        read_fp = VMPI_popen(commandUTF8.c_str(), "r");
        Stringp output = core()->newStringUTF8( "" );
        
        if (read_fp != NULL) {
            chars_read = (int) fread(buffer, sizeof(char), BUFSIZ, read_fp);
            output = output->append( core()->newStringUTF8(buffer, chars_read) );
            
            while(chars_read > 0) {
                buffer[chars_read - 1] = '\0';
                chars_read = (int) fread(buffer, sizeof(char), BUFSIZ, read_fp);
                output = output->append( core()->newStringUTF8(buffer, chars_read) );
            }
            
            VMPI_pclose(read_fp);
            return output;
        }
        
        return NULL;
    }
	/*static*/ Stringp VectorClass::makeVectorClassName(AvmCore* core, Traits* t)
	{
		Stringp s = core->newConstantStringLatin1("Vector.<");
		s = s->append(t->formatClassName());
		s = s->append(core->newConstantStringLatin1(">"));
		// all callers want it interned, so let's do it here
		return core->internString(s);
	}
	Stringp ScopeChain::format(AvmCore* core) const
	{
		Stringp r = core->kEmptyString;
		r = r->appendLatin1("SC:{dxns=(");
		r = r->append(_defaultXmlNamespace->format(core));
		r = r->appendLatin1("),");
		r = r->append(_scopeTraits->format(core));
		r = r->appendLatin1(",V:[");
		for (int i = 0; i < _scopeTraits->size; i++)
		{
			if (i > 0)
				r = r->appendLatin1(",");
			r = r->append(core->format(_scopes[i]));
		}
		r = r->appendLatin1("]}");
		return r;
	}
示例#4
0
	static Stringp getStackTraceLine(MethodInfo* method, Stringp filename) 
	{
		AvmCore *core = method->pool()->core;
		Stringp s = core->newStringLatin1("\tat ");
		s = core->concatStrings(s, method->format(core));
		if (filename)
		{
			s = s->appendLatin1("[");
			s = s->append(filename);
			s = s->appendLatin1(":");
		}
		return s;
	}
	Stringp ScopeTypeChain::format(AvmCore* core) const
	{
		Stringp r = core->kEmptyString;
		r = r->appendLatin1("STC:[");
		for (int i = 0; i < fullsize; i++)
		{
			if (i > 0)
				r = r->appendLatin1(",");
			Traits* t = getScopeTraitsAt(i);
			bool b = getScopeIsWithAt(i);
			r = r->append(t->format(core));
			r = r->appendLatin1(b?":1":":0");
		}
		r = r->appendLatin1("]");
		return r;
	}
示例#6
0
	Stringp XMLParser::unescape(int32_t start, int32_t last, bool intern)
	{
		Stringp dest = core->kEmptyString;

		if (start == last)
			return dest;

		int32_t bgn = m_str->indexOfCharCode('&', start, last);
		if (bgn < 0)
		{
			return intern ?
					m_str->intern_substring(start, last) :
					m_str->substring(start, last);
		}
		
		int32_t end = start;
		while (bgn >= start && bgn < last)
		{
			int32_t ampEnd = m_str->indexOfCharCode(';', ++bgn, last);
			if (ampEnd < 0)
				// &xxx without semicolon - we are done
				break;
			// add the text between the last sequence and this sequence
			dest = dest->append(m_str->substring(end, bgn-1));
			end = ampEnd;
			int32_t len = end - bgn;
			// an &xx; sequence is at least two characters
			bool ok = true;
			if (len >= 2)
			{
				int32_t ch = m_str[bgn];
				if (ch == '#')
				{
					// Parse a &#xx; decimal sequence.  Or a &#xDD hex sequence
					ch = m_str[++bgn];
					len--;
					int base = 10;
					if (len >= 2 && ch == 'x')
						base = 16, bgn++, len--;
					if (len > 0)
					{
						int32_t value = 0;
						while (len-- && ok)
						{
							ch = m_str[bgn++];
							if (ch >= 'A' && ch <= 'F')
								ch -= 7;
							ch -= '0';
							if (ch >= 0 && ch < base)
								value = (value * base) + ch;
							else
								ok = false;
							if (value > 0xFFFF)
								ok = false;
						}
						if (ok)
						{
							wchar c = (wchar) value;
							// note: this code is allowed to construct a string
							// containing illegal UTF16 sequences!
							dest = dest->append16(&c, 1);
							bgn = ++end;
						}
					}
				} 
				else if (len <= 4) // Our xmlEntities are only 4 characters or less
				{
					Atom entityAtom = m_str->intern_substring(bgn, end)->atom();
					Atom result = core->xmlEntities->get(entityAtom);
					if (result != undefinedAtom) 
					{
						AvmAssert(atomIsIntptr(result));
						wchar c = (wchar) atomGetIntptr(result);
						// note: this code is allowed to construct a string
						// containing illegal UTF16 sequences!
						dest = dest->append16(&c, 1);
						bgn = ++end;
					}
					else
						ok = false;
				}
				else
					ok = false;
			}
			if (!ok)
				bgn = end + 1;
			bgn = m_str->indexOfCharCode('&', bgn, last);
		}
		// add any remaining text
		if (end < last)
			dest = dest->append(m_str->substring(end, last));
		
		if (intern)
			dest = core->internString(dest);

		return dest;
	}