Пример #1
0
void SQDbgServer::BeginElement(const SQChar *name)
{
	_xmlcurrentement++;
	XMLElementState *self = &xmlstate[_xmlcurrentement];
	scstrcpy(self->name,name);
	self->haschildren = false;
	if(_xmlcurrentement > 0) {
		XMLElementState *parent = &xmlstate[_xmlcurrentement-1];
		if(!parent->haschildren) {
			SendChunk(_SC(">")); // closes the parent tag
			parent->haschildren = true;
		}
	}
	_scratchstring.resize(2+scstrlen(name));
	scsprintf(&_scratchstring[0],_SC("<%s"),name);
	SendChunk(&_scratchstring[0]);
}
Пример #2
0
//this can be done much better/faster(do we need that?)
const SQChar *SQDbgServer::escape_xml(const SQChar *s)
{
    SQChar *temp = sq_getscratchpad(_v, ((SQInteger) scstrlen(s) * 6) + sizeof(SQChar));
    SQChar *dest = temp;
    while (*s != _SC('\0')) {

        const SQChar *escape = NULL;
        switch (*s) {
            case _SC('<'):
                escape = _SC("&lt;");
                break;
            case _SC('>'):
                escape = _SC("&gt;");
                break;
            case _SC('&'):
                escape = _SC("&amp;");
                break;
            case _SC('\''):
                escape = _SC("&apos;");
                break;
            case _SC('\"'):
                escape = _SC("&quot;");
                break;
            case _SC('\n'):
                escape = _SC("\\n");
                break;
            case _SC('\r'):
                escape = _SC("\\r");
                break;
        }
        if (escape) {
            scstrcpy(dest, escape);
            dest += scstrlen(escape);
        }
        else {
            *dest = *s;
            *dest++;
        }
        *s++;
    }
    *dest = _SC('\0');
    return temp;

}
Пример #3
0
const SQChar *EscapeXMLString(HSQUIRRELVM v,const SQChar *s)
{
	
	SQChar *temp=sq_getscratchpad(v,((int)scstrlen(s)*6) + sizeof(SQChar));
	SQChar *dest=temp;
	while(*s!=_SC('\0')){
		int i=0;
		bool escaped=false;
		while(g_escapes[i].esc!=NULL){
			if(*s==g_escapes[i].c){
				scstrcpy(dest,g_escapes[i].esc);
				dest+=scstrlen(g_escapes[i].esc);
				escaped=true;
				break;
			}
			i++;
		}
		if(!escaped){*dest=*s;*dest++;}
		*s++;
	}
	*dest=_SC('\0');
	return temp;
}