void StringBuilder::append( const StringBuilder &_string ) { while( (m_pos + _string.m_pos) > m_alloc ) growCapacity(); memcpy(&m_buffer[m_pos],_string.m_buffer,_string.m_pos); m_pos += _string.m_pos; zeroTerminateIfDebug(); }
void StringBuilder::append( const char* const _string, size_t _length ) { while( (m_pos + _length) > m_alloc ) growCapacity(); memcpy(&m_buffer[m_pos],_string,_length); m_pos += _length; zeroTerminateIfDebug(); }
void StringBuilder::append( char _c, size_t _count ) { while( (m_pos + _count) > m_alloc ) growCapacity(); memset(&m_buffer[m_pos],_c,_count); m_pos += _count; zeroTerminateIfDebug(); }
void StringBuilder::toScreen() const { if( m_pos == 0 ) return; if( m_pos == m_alloc ) growCapacity((size_t)1); // make sure we have enough room for the following temproary '/0' termination m_buffer[m_pos] = '\0'; // *must* zero terminate printf("%s",m_buffer); }
int StringBuilder::parseInt() const { if( m_pos == 0 ) throw ParseException("StringBuilder::parseInt(): Cannot parse a '0' length string!"); if( m_pos == m_alloc ) growCapacity((size_t)1); // make sure we have enough room for the following temproary '/0' termination int lvalue; if(sscanf(m_buffer,"%d",&lvalue)!=1) throw ParseException("StringBuilder::parseInt()"); return lvalue; }
void StringBuilder::append( const std::string &_string ) { size_t length = _string.size(); while( (m_pos + length) > m_alloc ) growCapacity(); memcpy(&m_buffer[m_pos],_string.c_str(),length); m_pos += length; zeroTerminateIfDebug(); }
void StringBuilder::setBufferAt(size_t _index, char _value ) { if( _index >= m_alloc ) { growCapacity( m_alloc - _index ); } m_buffer[_index] = _value; }
void StringBuilder::appendingReplace( size_t _index, char _withChar, size_t _count ) { if( _index > m_pos ) throw OutOfRangeException("appendingReplace() call index is outside the current array bounds!"); size_t endIndex = _index + _count; while( endIndex > m_alloc ) growCapacity(); if( endIndex > m_pos ) m_pos = endIndex; memset(&m_buffer[_index],_withChar,_count); zeroTerminateIfDebug(); }
void StringBuilder::append( long a, char *formatstring ) { // System defines: LLONG_MAX 9223372036854775807 const int ensureCapacity = 20; // make sure we can store 20 characters in our buffer while( (m_pos + ensureCapacity) > m_alloc ) growCapacity(); int addedCharacters = sprintf(&m_buffer[m_pos],formatstring,a); m_pos += addedCharacters; zeroTerminateIfDebug(); }
void StringBuilder::append( double a, char *formatstring ) { // System defines: INT_MAX 2147483647 const int ensureCapacity = 10; // make sure we can store 10 characters in our buffer while( (m_pos + ensureCapacity) > m_alloc ) growCapacity(); int addedCharacters = sprintf(&m_buffer[m_pos],formatstring,a); m_pos += addedCharacters; zeroTerminateIfDebug(); }
void StringBuilder::append( int a, char *formatstring ) { // System defines: DBL_MAX 1.7976931348623158e+308 const int ensureCapacity = 23; // make sure we can store 23 characters in our buffer while( (m_pos + ensureCapacity) > m_alloc ) growCapacity(); int addedCharacters = sprintf(&m_buffer[m_pos],formatstring,a); m_pos += addedCharacters; zeroTerminateIfDebug(); }
void StringBuilder::append( const StringBuilder &_string, size_t _index, size_t _length ) { size_t strLen = _string.size(); if( strLen < (_index+_length) ) throw OutOfRangeException("Range given is outside of the range of the given string!"); while( (m_pos + _length) > m_alloc ) growCapacity(); memcpy(&m_buffer[m_pos],&_string.m_buffer[_index],_length); m_pos += _length; zeroTerminateIfDebug(); }
void StringBuilder::appendingReplace( size_t _index, const StringBuilder &_string ) { if( _index > m_pos ) throw OutOfRangeException("appendingReplace() call index is outside the current array bounds!"); size_t endIndex = _index + _string.m_pos; while( endIndex > m_alloc ) growCapacity(); if( endIndex > m_pos ) m_pos = endIndex; memcpy(&m_buffer[_index],_string.m_buffer,_string.m_pos); zeroTerminateIfDebug(); }
double StringBuilder::parseDouble( size_t _index ) const { if( m_pos == 0 || _index >= m_pos-1 ) throw ParseException("StringBuilder::parseDouble( size_t _index )"); if( m_pos == m_alloc ) growCapacity((size_t)1); // make sure we have enough room for the following temproary '/0' termination m_buffer[m_pos] = 0; // ensure a '0' terminated string for sscanf() but do not increase the size of the string double lvalue; if(sscanf(&m_buffer[_index],"%lf",&lvalue)!=1) throw ParseException("StringBuilder::parseDouble()"); return lvalue; }
void StringBuilder::toScreen( size_t _index, size_t _length ) const { if( (_index + _length) > m_pos ) throw OutOfRangeException("toString( size_t _index, size_t _length ) call is outside of current array bounds!"); if( _length == 0 ) return; if( _index+_length == m_alloc ) growCapacity((size_t)1); // make sure we have enough room for the following temproary '/0' termination char store = m_buffer[_index+_length]; // store the value m_buffer[_index+_length] = '\0'; // *must* zero terminate printf("%s",&m_buffer[_index]); // perform the print operation on the now terminated string m_buffer[_index+_length] = store; }
uint8_t* grow(unsigned alignment, size_t size) { size_t alignedSize = ((m_bufferSize + alignment - 1) / alignment) * alignment; growCapacity(alignedSize + size); m_bufferSize = alignedSize + size; m_bufferPointer = m_buffer.get() + m_bufferSize; return m_buffer.get() + alignedSize; }
void StringBuilder::insert( size_t _index, char _Char ) { if( m_pos == m_alloc ) growCapacity(); for( int i = (int)m_pos; i > _index; i-- ) // This must be an 'int' if _index == 0!! { m_buffer[i] = m_buffer[i-1]; } m_buffer[_index] = _Char; m_pos++; zeroTerminateIfDebug(); }
double StringBuilder::parseDouble( size_t _index, size_t _length ) const { size_t tempTerminatorIndex = _index + _length; if( _length == 0 || tempTerminatorIndex > m_pos ) throw ParseException("StringBuilder::parseDouble(): Cannot parse a '0' length string!"); if( tempTerminatorIndex+1 > m_alloc ) growCapacity((size_t)(tempTerminatorIndex+1 - m_alloc)); // make sure we have enough room for the following temproary '/0' termination char cache = m_buffer[tempTerminatorIndex]; // store what was here before m_buffer[tempTerminatorIndex] = 0; // ensure a '0' terminated string for sscanf() but do not increase the size of the string double lvalue; int result = sscanf(&m_buffer[_index],"%lf",&lvalue); m_buffer[tempTerminatorIndex] = cache; // put it back! if(result!=1) throw ParseException("StringBuilder::parseInt()"); else return lvalue; }
void StringBuilder::insert( size_t _index, const StringBuilder &_string ) { int j; while( (m_pos + _string.m_pos) > m_alloc ) growCapacity(); for( int i = (int)m_pos; i > _index; i-- ) // This must be an 'int' if _index == 0!! { j = i - 1; m_buffer[_string.m_pos+j] = m_buffer[j]; } memcpy(&m_buffer[_index],_string.m_buffer,_string.m_pos); m_pos += _string.m_pos; zeroTerminateIfDebug(); }
void StringBuilder::insert( size_t _index, const char* _string, size_t _length ) { while( (m_pos + _length) > m_alloc ) growCapacity(); int j; for( int i = (int)m_pos; i > _index; i-- ) // This must be an 'int' if _index == 0!! { j = i - 1; m_buffer[_length+j] = m_buffer[j]; } memcpy(&m_buffer[_index],_string,_length); m_pos += _length; zeroTerminateIfDebug(); }
void StringBuilder::insert( size_t _index, char _Char, size_t _count ) { while( (m_pos + _count) > m_alloc ) growCapacity(); size_t j; for( int i = (int)m_pos; i > _index; i-- ) // This must be an 'int' if _index == 0!! { j = i - 1; m_buffer[_count+j] = m_buffer[j]; } memset(&m_buffer[_index],_Char,_count); m_pos += _count; zeroTerminateIfDebug(); }
void StringBuilder::append( char _c ) { if( m_pos == m_alloc ) growCapacity(); m_buffer[m_pos++] = _c; zeroTerminateIfDebug(); }