From 238244337283a7f888cf49a1e56b809c22466a63 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 8 Aug 2019 09:59:52 -0700 Subject: Fixed a bug in the BlobBuilder. Appending wasn't working correctly. --- src/unstable/blobbuilder.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/unstable/blobbuilder.cpp') diff --git a/src/unstable/blobbuilder.cpp b/src/unstable/blobbuilder.cpp index 497a1a1..43c0779 100644 --- a/src/unstable/blobbuilder.cpp +++ b/src/unstable/blobbuilder.cpp @@ -7,6 +7,7 @@ #include "bu/blobbuilder.h" #include "bu/blob.h" +#include "bu/exceptionbase.h" #define PAGE_SIZE 8 @@ -132,6 +133,7 @@ void Bu::BlobBuilderCore::append( const char *pSrc, int32_t iLength ) if( iLength > 0 ) { pLast->pNext = new Chunk( pSrc, iLength ); + pLast = pLast->pNext; } } @@ -214,6 +216,21 @@ void Bu::BlobBuilderCore::copyTo( void *pDestRaw, int32_t iLength ) const } } +char Bu::BlobBuilderCore::getAt( int32_t iIndex ) const +{ + if( iIndex < 0 || iIndex >= iLength ) + throw Bu::ExceptionBase("Requseted index is out of range."); + + Chunk *pCur = pFirst; + while( iIndex >= pCur->iLength ) + { + iIndex -= pCur->iLength; + pCur = pCur->pNext; + } + + return pCur->pData[iIndex]; +} + ////// // BlobBuilder // @@ -245,6 +262,7 @@ void Bu::BlobBuilder::set( const char *pSrc, int32_t iLength ) void Bu::BlobBuilder::set( const char *pSrc ) { + _hardCopy(); set( pSrc, strlen( pSrc ) ); } @@ -262,6 +280,7 @@ void Bu::BlobBuilder::append( const char *pSrc, int32_t iLength ) void Bu::BlobBuilder::append( const char *pSrc ) { + _hardCopy(); append( pSrc, strlen( pSrc ) ); } @@ -279,6 +298,7 @@ void Bu::BlobBuilder::prepend( const char *pSrc, int32_t iLength ) void Bu::BlobBuilder::prepend( const char *pSrc ) { + _hardCopy(); prepend( pSrc, strlen( pSrc ) ); } @@ -297,6 +317,7 @@ void Bu::BlobBuilder::insert( int32_t iBefore, const char *pSrc, void Bu::BlobBuilder::insert( int32_t iBefore, const char *pSrc ) { + _hardCopy(); insert( iBefore, pSrc, strlen( pSrc ) ); } @@ -321,6 +342,11 @@ void Bu::BlobBuilder::copyTo( void *pDestRaw, int32_t iDestSize ) const core->copyTo( pDestRaw, iDestSize ); } +char Bu::BlobBuilder::operator[]( int32_t iIndex ) const +{ + return core->getAt( iIndex ); +} + Bu::BlobBuilder &Bu::BlobBuilder::operator=( const Blob &rSrc ) { set( rSrc ); @@ -333,6 +359,12 @@ Bu::BlobBuilder &Bu::BlobBuilder::operator=( const char *pSrc ) return *this; } +Bu::BlobBuilder &Bu::BlobBuilder::operator=( const char chr ) +{ + set( &chr, 1 ); + return *this; +} + Bu::BlobBuilder &Bu::BlobBuilder::operator+=( const Blob &rSrc ) { append( rSrc ); @@ -345,4 +377,9 @@ Bu::BlobBuilder &Bu::BlobBuilder::operator+=( const char *pSrc ) return *this; } +Bu::BlobBuilder &Bu::BlobBuilder::operator+=( const char chr ) +{ + append( &chr, 1 ); + return *this; +} -- cgit v1.2.3