ProteoWizard
Public Member Functions | Private Member Functions | Private Attributes
pwiz::minimxml::SAXParser::saxstring Class Reference

#include <SAXParser.hpp>

List of all members.

Public Member Functions

 saxstring (size_t size=0)
 saxstring (const SAXParser::saxstring &rhs)
 saxstring (const std::string &rhs)
void unescapeXML ()
 ~saxstring ()
saxstringoperator= (const SAXParser::saxstring &rhs)
saxstringoperator= (const char *rhs)
saxstringoperator+= (const SAXParser::saxstring &rhs)
saxstringoperator+= (const char *rhs)
bool operator== (const char *c) const
bool operator== (const std::string &s) const
bool operator== (const saxstring &s) const
char * resize (size_t size)
void clear ()
const char * c_str () const
char & operator[] (size_t n)
size_t length () const
size_t capacity () const
void trim_trail_ws ()
int trim_lead_ws ()
bool starts_with (const char *txt) const
bool ends_with (const char *txt) const
char * data ()

Private Member Functions

void init (size_t size)

Private Attributes

char * _data
size_t _used
size_t _lead
size_t _capacity

Detailed Description

Definition at line 60 of file SAXParser.hpp.


Constructor & Destructor Documentation

pwiz::minimxml::SAXParser::saxstring::saxstring ( size_t  size = 0)
inline

Definition at line 72 of file SAXParser.hpp.

References init().

{
init(size);
}
pwiz::minimxml::SAXParser::saxstring::saxstring ( const SAXParser::saxstring rhs)
inline

Definition at line 76 of file SAXParser.hpp.

{
*this = rhs;
}
pwiz::minimxml::SAXParser::saxstring::saxstring ( const std::string &  rhs)
inline

Definition at line 80 of file SAXParser.hpp.

References data(), and init().

{
init(rhs.length());
memcpy(data(),rhs.c_str(),rhs.length());
(*this)[rhs.length()] = 0; // nullterm
}
pwiz::minimxml::SAXParser::saxstring::~saxstring ( )
inline

Definition at line 93 of file SAXParser.hpp.

References _data.

{
free(_data);
}

Member Function Documentation

void pwiz::minimxml::SAXParser::saxstring::unescapeXML ( )
inline

Definition at line 86 of file SAXParser.hpp.

References c_str(), data(), and resize().

{
if (strchr(c_str(),'&')) {
resize(strlen(c_str()));
}
}
saxstring& pwiz::minimxml::SAXParser::saxstring::operator= ( const SAXParser::saxstring rhs)
inline

Definition at line 97 of file SAXParser.hpp.

References c_str(), data(), init(), and length().

{
init(rhs.length());
if (length()) {
memcpy(data(),rhs.c_str(),length()+1);
}
return *this;
}
saxstring& pwiz::minimxml::SAXParser::saxstring::operator= ( const char *  rhs)
inline

Definition at line 105 of file SAXParser.hpp.

References data(), init(), and length().

{
init(rhs ? strlen(rhs) : 0);
if (length()) {
memcpy(data(),rhs,length()+1);
}
return *this;
}
saxstring& pwiz::minimxml::SAXParser::saxstring::operator+= ( const SAXParser::saxstring rhs)
inline

Definition at line 113 of file SAXParser.hpp.

References c_str(), data(), length(), and resize().

{
if (rhs.length()) {
size_t oldsize = length();
resize(rhs.length()+oldsize);
memcpy(data()+oldsize,rhs.c_str(),rhs.length()+1);
}
return *this;
}
saxstring& pwiz::minimxml::SAXParser::saxstring::operator+= ( const char *  rhs)
inline

Definition at line 122 of file SAXParser.hpp.

References data(), length(), and resize().

{
size_t rhslen = rhs?strlen(rhs):0;
if (rhslen) {
size_t oldsize = length();
resize(rhslen+oldsize);
strcpy(data()+oldsize,rhs);
}
return *this;
}
bool pwiz::minimxml::SAXParser::saxstring::operator== ( const char *  c) const
inline

Definition at line 132 of file SAXParser.hpp.

References c_str().

{
return c && !strcmp(c,c_str());
}
bool pwiz::minimxml::SAXParser::saxstring::operator== ( const std::string &  s) const
inline

Definition at line 136 of file SAXParser.hpp.

References c_str().

{
return !strcmp(c_str(),s.c_str());
}
bool pwiz::minimxml::SAXParser::saxstring::operator== ( const saxstring s) const
inline

Definition at line 140 of file SAXParser.hpp.

References c_str().

{
return !strcmp(c_str(),s.c_str());
}
char* pwiz::minimxml::SAXParser::saxstring::resize ( size_t  size)
inline

Definition at line 144 of file SAXParser.hpp.

References _capacity, _data, _lead, and _used.

Referenced by clear(), data(), init(), operator+=(), trim_trail_ws(), and unescapeXML().

{
if (!size) {
_lead = 0; // empty, reclaim the start of buffer
}
size_t new_used = size + _lead; // translate to "used" space
if (new_used >= _capacity) {
_data = (char *)realloc(_data, (_used = new_used)+1);
if (_used && !_data) {
throw std::runtime_error("SAXParser: cannot allocate memory");
}
} else {
_used = new_used;
}
_data[_used] = 0;
return _data;
}
void pwiz::minimxml::SAXParser::saxstring::clear ( )
inline

Definition at line 161 of file SAXParser.hpp.

References resize().

{
resize(0);
}
const char* pwiz::minimxml::SAXParser::saxstring::c_str ( ) const
inline
char& pwiz::minimxml::SAXParser::saxstring::operator[] ( size_t  n)
inline

Definition at line 167 of file SAXParser.hpp.

References data().

{
return *(data()+n);
}
size_t pwiz::minimxml::SAXParser::saxstring::length ( ) const
inline
size_t pwiz::minimxml::SAXParser::saxstring::capacity ( ) const
inline

Definition at line 173 of file SAXParser.hpp.

References _capacity.

{
return _capacity;
}
void pwiz::minimxml::SAXParser::saxstring::trim_trail_ws ( )
inline

Definition at line 176 of file SAXParser.hpp.

References c_str(), pwiz::minimxml::SAXParser::count_trail_ws(), length(), and resize().

Referenced by testSaxParserString().

{ // remove trailing whitespace if any
size_t n = count_trail_ws(c_str(),length());
resize(length()-n);
}
int pwiz::minimxml::SAXParser::saxstring::trim_lead_ws ( )
inline

Definition at line 181 of file SAXParser.hpp.

References _lead, and c_str().

Referenced by testSaxParserString().

{
size_t n=0;
for (const char *c=c_str(); *c && strchr(" \n\r\t",*c); c++) {
n++;
}
_lead += n;
return n;
}
bool pwiz::minimxml::SAXParser::saxstring::starts_with ( const char *  txt) const
inline

Definition at line 189 of file SAXParser.hpp.

References c_str().

{
return !strncmp(c_str(),txt,strlen(txt));
}
bool pwiz::minimxml::SAXParser::saxstring::ends_with ( const char *  txt) const
inline

Definition at line 192 of file SAXParser.hpp.

References c_str(), and length().

{
size_t len = strlen(txt);
return (len <= length()) ? (!strcmp(c_str()+length()-len,txt)) : false;
}
char* pwiz::minimxml::SAXParser::saxstring::data ( )
inline

Definition at line 196 of file SAXParser.hpp.

References _data, _lead, and resize().

Referenced by pwiz::minimxml::SAXParser::Handler::Attributes::Attributes(), operator+=(), operator=(), operator[](), saxstring(), testSaxParserString(), and unescapeXML().

{ // direct access to data buffer
if (!_data) {
resize(0);
}
return _data+_lead;
}
void pwiz::minimxml::SAXParser::saxstring::init ( size_t  size)
inlineprivate

Definition at line 203 of file SAXParser.hpp.

References _capacity, _data, _lead, _used, and resize().

Referenced by operator=(), and saxstring().

{
_used = 0;
_lead = 0;
_capacity = 0;
_data = NULL;
if (size) {
resize(size);
}
}

Member Data Documentation

char* pwiz::minimxml::SAXParser::saxstring::_data
private

Definition at line 212 of file SAXParser.hpp.

Referenced by c_str(), data(), init(), resize(), and ~saxstring().

size_t pwiz::minimxml::SAXParser::saxstring::_used
private

Definition at line 213 of file SAXParser.hpp.

Referenced by init(), length(), and resize().

size_t pwiz::minimxml::SAXParser::saxstring::_lead
private

Definition at line 214 of file SAXParser.hpp.

Referenced by c_str(), data(), init(), length(), resize(), and trim_lead_ws().

size_t pwiz::minimxml::SAXParser::saxstring::_capacity
private

Definition at line 215 of file SAXParser.hpp.

Referenced by capacity(), init(), and resize().


The documentation for this class was generated from the following file: