switch StrPair() over to _ for member vars

This commit is contained in:
Lee Thomason 2012-10-12 10:06:59 -07:00
parent a9cf3f9f3f
commit 120b3a62be
2 changed files with 49 additions and 38 deletions

View File

@ -87,12 +87,12 @@ StrPair::~StrPair()
void StrPair::Reset()
{
if ( flags & NEEDS_DELETE ) {
delete [] start;
if ( _flags & NEEDS_DELETE ) {
delete [] _start;
}
flags = 0;
start = 0;
end = 0;
_flags = 0;
_start = 0;
_end = 0;
}
@ -100,10 +100,10 @@ void StrPair::SetStr( const char* str, int flags )
{
Reset();
size_t len = strlen( str );
start = new char[ len+1 ];
memcpy( start, str, len+1 );
end = start + len;
this->flags = flags | NEEDS_DELETE;
_start = new char[ len+1 ];
memcpy( _start, str, len+1 );
_end = _start + len;
_flags = flags | NEEDS_DELETE;
}
@ -155,11 +155,11 @@ char* StrPair::ParseName( char* p )
void StrPair::CollapseWhitespace()
{
// Trim leading space.
start = XMLUtil::SkipWhiteSpace( start );
_start = XMLUtil::SkipWhiteSpace( _start );
if ( start && *start ) {
char* p = start; // the read pointer
char* q = start; // the write pointer
if ( _start && *_start ) {
char* p = _start; // the read pointer
char* q = _start; // the write pointer
while( *p ) {
if ( XMLUtil::IsWhiteSpace( *p )) {
@ -181,16 +181,16 @@ void StrPair::CollapseWhitespace()
const char* StrPair::GetStr()
{
if ( flags & NEEDS_FLUSH ) {
*end = 0;
flags ^= NEEDS_FLUSH;
if ( _flags & NEEDS_FLUSH ) {
*_end = 0;
_flags ^= NEEDS_FLUSH;
if ( flags ) {
char* p = start; // the read pointer
char* q = start; // the write pointer
if ( _flags ) {
char* p = _start; // the read pointer
char* q = _start; // the write pointer
while( p < end ) {
if ( (flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) {
while( p < _end ) {
if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) {
// CR-LF pair becomes LF
// CR alone becomes LF
// LF-CR becomes LF
@ -202,7 +202,7 @@ const char* StrPair::GetStr()
}
*q++ = LF;
}
else if ( (flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) {
else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) {
if ( *(p+1) == CR ) {
p += 2;
}
@ -211,7 +211,7 @@ const char* StrPair::GetStr()
}
*q++ = LF;
}
else if ( (flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
// Entities handled by tinyXML2:
// - special entities in the entity table [in/out]
// - numeric character reference [in]
@ -255,12 +255,12 @@ const char* StrPair::GetStr()
}
// The loop below has plenty going on, and this
// is a less useful mode. Break it out.
if ( flags & COLLAPSE_WHITESPACE ) {
if ( _flags & COLLAPSE_WHITESPACE ) {
CollapseWhitespace();
}
flags = (flags & NEEDS_DELETE);
_flags = (_flags & NEEDS_DELETE);
}
return start;
return _start;
}

View File

@ -137,30 +137,32 @@ public:
COMMENT = NEEDS_NEWLINE_NORMALIZATION
};
StrPair() : flags( 0 ), start( 0 ), end( 0 ) {}
StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
~StrPair();
void Set( char* _start, char* _end, int _flags ) {
void Set( char* start, char* end, int flags ) {
Reset();
this->start = _start;
this->end = _end;
this->flags = _flags | NEEDS_FLUSH;
_start = start;
_end = end;
_flags = flags | NEEDS_FLUSH;
}
const char* GetStr();
bool Empty() const {
return start == end;
return _start == _end;
}
void SetInternedStr( const char* str ) {
Reset();
this->start = const_cast<char*>(str);
_start = const_cast<char*>(str);
}
void SetStr( const char* str, int flags=0 );
char* ParseText( char* in, const char* endTag, int strFlags );
char* ParseName( char* in );
private:
void Reset();
void CollapseWhitespace();
@ -171,9 +173,9 @@ private:
};
// After parsing, if *end != 0, it can be set to zero.
int flags;
char* start;
char* end;
int _flags;
char* _start;
char* _end;
};
@ -191,11 +193,13 @@ public:
allocated = INIT;
size = 0;
}
~DynArray() {
if ( mem != pool ) {
delete [] mem;
}
}
void Push( T t ) {
EnsureCapacity( size+1 );
mem[size++] = t;
@ -207,9 +211,11 @@ public:
size += count;
return ret;
}
T Pop() {
return mem[--size];
}
void PopArr( int count ) {
TIXMLASSERT( size >= count );
size -= count;
@ -218,28 +224,33 @@ public:
bool Empty() const {
return size == 0;
}
T& operator[](int i) {
TIXMLASSERT( i>= 0 && i < size );
return mem[i];
}
const T& operator[](int i) const {
TIXMLASSERT( i>= 0 && i < size );
return mem[i];
}
int Size() const {
return size;
}
int Capacity() const {
return allocated;
}
const T* Mem() const {
return mem;
}
T* Mem() {
return mem;
}
private:
void EnsureCapacity( int cap ) {
if ( cap > allocated ) {