lmt = bfr + bsz;
isz = max_size;
destroy = del;
+ share_lock = new Mutex("XMLBuffer::share_lock", 1);
}
XMLBuffer::XMLBuffer(const char *buf, long buf_size, int del)
lmt = inp = bfr+bsz;
isz = bsz;
destroy = del;
+ share_lock = new Mutex("XMLBuffer::share_lock");
}
XMLBuffer::XMLBuffer(long buf_size, char *buf, int del)
lmt = outp = bfr+bsz;
isz = bsz;
destroy = del;
+ share_lock = new Mutex("XMLBuffer::share_lock");
}
XMLBuffer::~XMLBuffer()
{
if( destroy ) delete [] bfr;
+ delete share_lock;
}
int XMLBuffer::demand(long len)
void XMLBuffer::copy_from(XMLBuffer *xbuf)
{
- if( bsz != xbuf->bsz ) { delete [] bfr; bfr = 0; }
- if( !bfr ) bfr = new unsigned char[bsz = xbuf->bsz];
- lmt = bfr + bsz;
- long ilen = xbuf->otell(), olen = xbuf->itell();
- inp = pos(ilen);
- outp = pos(olen);
- if( ilen > 0 )
- memmove(bfr, xbuf->bfr, ilen);
- destroy = xbuf->destroy;
+ xbuf->share_lock->lock("XMLBuffer::copy_from");
+ share_lock->lock("XMLBuffer::copy_from");
+ oseek(0);
+ write((const char*)xbuf->pos(0), xbuf->otell());
+ iseek(xbuf->itell());
+ xbuf->share_lock->unlock();
+ share_lock->unlock();
}
const char *prop = properties[i]->prop;
const char *value = properties[i]->value;
int plen = strlen(prop), vlen = strlen(value);
- bool need_quotes = !vlen || strchr(value,' ');
+ bool need_quotes = !vlen || strchr(value,' ') || strchr(value,'\n');
buf->next(' ');
xml->append_text(prop, plen);
buf->next('=');
FileXML::~FileXML()
{
if( !shared ) delete buffer;
+ else buffer->share_lock->unlock();
delete [] output;
}
char* FileXML::get_data()
{
+ char *data = (char *)buffer->cstr();
long ofs = buffer->itell();
- return (char *)buffer->pos(ofs);
+ return data + ofs;
}
char* FileXML::string()
{
return buffer->otell();
}
-char* FileXML::read_text()
+char* FileXML::read_text(const char *tag_title)
{
+ if( !tag_title ) tag_title = tag.title;
int ch = buffer->next();
// filter out first char is new line
if( ch == '\n' ) ch = buffer->next();
- long ipos = buffer->itell()-1;
+ long ipos = buffer->itell();
+ if( ch >= 0 ) --ipos;
+ long pos = ipos;
// scan for delimiter
- while( ch >= 0 && ch != left_delm ) ch = buffer->next();
- long pos = buffer->itell()-1;
- if( ch >= 0 ) buffer->iseek(pos);
+ while( ch >= 0 ) {
+ while( ch >= 0 && ch != left_delm ) ch = buffer->next();
+ if( ch < 0 ) break;
+ pos = buffer->itell()-1;
+ if( (ch = buffer->next()) != '/' ) continue;
+ const char *cp = tag_title;
+ while( (ch=buffer->next()) >= 0 && ch == *cp ) ++cp;
+ if( ch < 0 ) break;
+ if( *cp ) continue;
+ while( ch == ' ' ) ch = buffer->next();
+ if( ch == right_delm ) break;
+ }
+ if( ch < 0 )
+ pos = buffer->itell();
+ buffer->iseek(pos);
long len = pos - ipos;
if( len >= output_length ) {
delete [] output;
output_length = len+1;
output = new char[output_length];
}
- decode(output,(const char *)buffer->pos(ipos), len);
+ if( len > 0 )
+ decode(output,(const char *)buffer->pos(ipos), len);
+ output[len] = 0;
return output;
}
strcpy(this->filename, "");
delete buffer;
buffer = xbuf;
+ xbuf->share_lock->lock("FileXML::set_shared_input");
xbuf->iseek(0);
- set_coding(coded);
shared = 1;
+ set_coding(coded);
return 0;
}
strcpy(this->filename, "");
delete buffer;
buffer = xbuf;
+ xbuf->share_lock->lock("FileXML::set_shared_output");
xbuf->oseek(0);
- set_coding(coded);
shared = 1;
+ set_coding(coded);
return 0;
}