From 59be1eca587eb3da14c2e924a186396f321f5a58 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 6 Feb 2020 11:58:11 -0800 Subject: Closer on the TextBuilder. Codecs are next. --- src/unstable/textbuilder.cpp | 19 ++++++++++++++++--- src/unstable/textbuilder.h | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/unstable/textbuilder.cpp b/src/unstable/textbuilder.cpp index 26b46f5..acd3501 100644 --- a/src/unstable/textbuilder.cpp +++ b/src/unstable/textbuilder.cpp @@ -196,8 +196,15 @@ void Bu::TextBuilderCore::copyTo( void *pDestRaw, int32_t iLength ) Chunk *pCur = pFirst; while( pCur && iLength ) { - int32_t iChunkLun = pCur->iLength; + int32_t iChunkLen = pCur->iLength; + if( iChunkLen > iLength ) + iChunkLen = iLength; + memcpy( pDest, pCur->pData, iChunkLen*sizeof(CodePoint) ); + pDest += iChunkLen; + iLength -= iChunkLen; + + pCur = pCur->pNext; } } @@ -225,6 +232,7 @@ Bu::TextBuilder::TextBuilder() Bu::TextBuilder::TextBuilder( const Text &rSrc ) { + core->append( rSrc.getData(), rSrc.getSize() ); } Bu::TextBuilder::TextBuilder( const TextBuilder &rSrc ) : @@ -245,26 +253,31 @@ void Bu::TextBuilder::set( const Text &rSrc ) void Bu::TextBuilder::append( const Text &rSrc ) { _hardCopy(); + core->append( rSrc.getData(), rSrc.getSize() ); } void Bu::TextBuilder::append( const CodePoint *pSrc, int32_t iLength ) { _hardCopy(); + core->append( pSrc, iLength ); } void Bu::TextBuilder::prepend( const Text &rSrc ) { _hardCopy(); + core->prepend( rSrc.getData(), rSrc.getSize() ); } -void Bu::TextBuilder::insert( const Text &rSrc ) +void Bu::TextBuilder::insert( int32_t iBefore, const Text &rSrc ) { _hardCopy(); + core->insert( iBefore, rSrc.getData(), rSrc.getSize() ); } void Bu::TextBuilder::clear() { _hardCopy(); + core->clear(); } int32_t Bu::TextBuilder::getSize() const @@ -295,7 +308,7 @@ Bu::TextBuilder &Bu::TextBuilder::operator=( const Text &rSrc ) Bu::TextBuilder &Bu::TextBuilder::operator==( const Text &rSrc ) { - set( pSrc ); + return *this; } diff --git a/src/unstable/textbuilder.h b/src/unstable/textbuilder.h index f0dee8c..8c49f2a 100644 --- a/src/unstable/textbuilder.h +++ b/src/unstable/textbuilder.h @@ -70,7 +70,7 @@ namespace Bu void append( const Text &rSrc ); void append( const CodePoint *pSrc, int32_t iLength ); void prepend( const Text &rSrc ); - void insert( const Text &rSrc ); + void insert( int32_t iBefore, const Text &rSrc ); void clear(); int32_t getSize() const; -- cgit v1.2.3