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

View File

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