From fd830279725081d95e3f08f768ed6879c92fe838 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 12 Nov 2019 06:02:12 -0800 Subject: 32bit --- src/unstable/text.cpp | 55 +++++++++++++++++++++++++++++++++++++++----- src/unstable/text.h | 13 ++++------- src/unstable/textbuilder.cpp | 12 +++++++++- src/unstable/textbuilder.h | 1 + 4 files changed, 66 insertions(+), 15 deletions(-) diff --git a/src/unstable/text.cpp b/src/unstable/text.cpp index 9e5670d..6ec41da 100644 --- a/src/unstable/text.cpp +++ b/src/unstable/text.cpp @@ -6,22 +6,34 @@ */ #include "bu/text.h" + +#include "bu/exceptionbase.h" + #include Bu::Text::Text() : pData( NULL ), - iSize( 0 ), - iCodePoints( 0 ) + bIsBmpOnly( true ), + iSize( 0 ) { } Bu::Text::Text( const Text &rSrc ) : pData( NULL ), - iSize( rSrc.iSize ), - iCodePoints( rSrc.iCodePoints ) + bIsBmpOnly( rSrc.bIsBmpOnly ), + iSize( rSrc.iSize ) +{ + pData = new CodePoint[iSize]; + memcpy( pData, rSrc.pData, sizeof(CodePoint)*iSize ); +} + +Bu::Text::Text( const TextBuilder &rSrc ) : + pData( NULL ), + bIsBmpOnly( true ), + iSize( rSrc.getSize() ) { - pData = new uint16_t[iSize]; - memcpy( pData, rSrc.pData, sizeof(uint16_t)*iSize ); + pData = new CodePoint[iSize]; + } Bu::Text::~Text() @@ -30,4 +42,35 @@ Bu::Text::~Text() pData = NULL; } +bool Bu::Text::isEmpty() const +{ + return (iSize == 0); +} + +bool Bu::Text::isBmpOnly() const +{ + return bIsBmpOnly; +} + +int32_t Bu::Text::getSize() const +{ + return iSize; +} + +int32_t Bu::Text::getSizeInBytes() const +{ + return iSize*sizeof(CodePoint); +} + +Bu::CodePoint Bu::Text::operator[]( int32_t iIndex ) const +{ + if( iIndex < 0 || iIndex >= iSize ) + throw Bu::ExceptionBase("Index out of range."); + return pData[iIndex]; +} + +Bu::CodePoint *Bu::Text::getData() const +{ + return pData; +} diff --git a/src/unstable/text.h b/src/unstable/text.h index 1d623ff..1154a50 100644 --- a/src/unstable/text.h +++ b/src/unstable/text.h @@ -27,11 +27,6 @@ namespace Bu * multilpe code points. In addition, a code point can also represent * formatting or display inforamtion. * - * Internally all data is stored in UTF-16, which is a fair compromise for - * mose text. All characters from all modern natural languages fit within - * the Basic Multilingual Plane, which requires only a single 16 bit value - * to represent it. However, when iterating through or addressing data - * in the Text object all work is done on a code point basis. */ class Text { @@ -43,20 +38,22 @@ namespace Bu public: Text(); Text( const Text &rSrc ); + Text( const TextBuilder &rSrc ); virtual ~Text(); bool isEmpty() const; bool isBmpOnly() const; int32_t getSize() const; int32_t getSizeInBytes() const; + CodePoint operator[]( int32_t iIndex ) const; - uint16_t *getRawData() const; + CodePoint *getData() const; // Text transform( (CodePoint *)(*pCallback)( CodePoint * ) ); private: - uint16_t *pData; + CodePoint *pData; + bool bIsBmpOnly; int32_t iSize; - int32_t iCodePoints; }; typedef Text::CodePoint CodePoint; } diff --git a/src/unstable/textbuilder.cpp b/src/unstable/textbuilder.cpp index af4dbac..5209e7b 100644 --- a/src/unstable/textbuilder.cpp +++ b/src/unstable/textbuilder.cpp @@ -191,7 +191,12 @@ void Bu::TextBuilderCore::set( const CodePoint *pSrc, int32_t iLength ) void Bu::TextBuilderCore::copyTo( void *pDestRaw, int32_t iLength ) { - + CodePoint *pDest = reinterpret_cast( pDestRaw ); + + Chunk *pCur = pFirst; + while( pCur && iLength ) + { + } } Bu::CodePoint Bu::TextBuilderCore::getAt( int32_t iIndex ) const @@ -270,6 +275,11 @@ Bu::Text Bu::TextBuilder::getText() const return Text( *this ); } +void Bu::TextBuilder::copyTo( void *pDestRaw, int32_t iDestSize ) const +{ + core->copyTo( pDestRaw, iDestSize ); +} + Bu::CodePoint Bu::TextBuilder::operator[]( int32_t iIndex ) const { return core->getAt( iIndex ); diff --git a/src/unstable/textbuilder.h b/src/unstable/textbuilder.h index 22fa653..f0dee8c 100644 --- a/src/unstable/textbuilder.h +++ b/src/unstable/textbuilder.h @@ -75,6 +75,7 @@ namespace Bu int32_t getSize() const; Text getText() const; + void copyTo( void *pDestRaw, int32_t iDestSize ) const; CodePoint operator[]( int32_t iIndex ) const; TextBuilder &operator=( const Text &rSrc ); -- cgit v1.2.3