aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2019-11-12 06:02:12 -0800
committerMike Buland <eichlan@xagasoft.com>2019-11-12 06:02:12 -0800
commitfd830279725081d95e3f08f768ed6879c92fe838 (patch)
tree3da9be0025e703d7a0afcb48458034b203efd8f3 /src
parent96759377ae8a4394d325747f597fe5b60afabf6e (diff)
downloadlibbu++-fd830279725081d95e3f08f768ed6879c92fe838.tar.gz
libbu++-fd830279725081d95e3f08f768ed6879c92fe838.tar.bz2
libbu++-fd830279725081d95e3f08f768ed6879c92fe838.tar.xz
libbu++-fd830279725081d95e3f08f768ed6879c92fe838.zip
32bit
Diffstat (limited to '')
-rw-r--r--src/unstable/text.cpp55
-rw-r--r--src/unstable/text.h13
-rw-r--r--src/unstable/textbuilder.cpp12
-rw-r--r--src/unstable/textbuilder.h1
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 @@
6 */ 6 */
7 7
8#include "bu/text.h" 8#include "bu/text.h"
9
10#include "bu/exceptionbase.h"
11
9#include <string.h> 12#include <string.h>
10 13
11Bu::Text::Text() : 14Bu::Text::Text() :
12 pData( NULL ), 15 pData( NULL ),
13 iSize( 0 ), 16 bIsBmpOnly( true ),
14 iCodePoints( 0 ) 17 iSize( 0 )
15{ 18{
16} 19}
17 20
18Bu::Text::Text( const Text &rSrc ) : 21Bu::Text::Text( const Text &rSrc ) :
19 pData( NULL ), 22 pData( NULL ),
20 iSize( rSrc.iSize ), 23 bIsBmpOnly( rSrc.bIsBmpOnly ),
21 iCodePoints( rSrc.iCodePoints ) 24 iSize( rSrc.iSize )
25{
26 pData = new CodePoint[iSize];
27 memcpy( pData, rSrc.pData, sizeof(CodePoint)*iSize );
28}
29
30Bu::Text::Text( const TextBuilder &rSrc ) :
31 pData( NULL ),
32 bIsBmpOnly( true ),
33 iSize( rSrc.getSize() )
22{ 34{
23 pData = new uint16_t[iSize]; 35 pData = new CodePoint[iSize];
24 memcpy( pData, rSrc.pData, sizeof(uint16_t)*iSize ); 36
25} 37}
26 38
27Bu::Text::~Text() 39Bu::Text::~Text()
@@ -30,4 +42,35 @@ Bu::Text::~Text()
30 pData = NULL; 42 pData = NULL;
31} 43}
32 44
45bool Bu::Text::isEmpty() const
46{
47 return (iSize == 0);
48}
49
50bool Bu::Text::isBmpOnly() const
51{
52 return bIsBmpOnly;
53}
54
55int32_t Bu::Text::getSize() const
56{
57 return iSize;
58}
59
60int32_t Bu::Text::getSizeInBytes() const
61{
62 return iSize*sizeof(CodePoint);
63}
64
65Bu::CodePoint Bu::Text::operator[]( int32_t iIndex ) const
66{
67 if( iIndex < 0 || iIndex >= iSize )
68 throw Bu::ExceptionBase("Index out of range.");
69 return pData[iIndex];
70}
71
72Bu::CodePoint *Bu::Text::getData() const
73{
74 return pData;
75}
33 76
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
27 * multilpe code points. In addition, a code point can also represent 27 * multilpe code points. In addition, a code point can also represent
28 * formatting or display inforamtion. 28 * formatting or display inforamtion.
29 * 29 *
30 * Internally all data is stored in UTF-16, which is a fair compromise for
31 * mose text. All characters from all modern natural languages fit within
32 * the Basic Multilingual Plane, which requires only a single 16 bit value
33 * to represent it. However, when iterating through or addressing data
34 * in the Text object all work is done on a code point basis.
35 */ 30 */
36 class Text 31 class Text
37 { 32 {
@@ -43,20 +38,22 @@ namespace Bu
43 public: 38 public:
44 Text(); 39 Text();
45 Text( const Text &rSrc ); 40 Text( const Text &rSrc );
41 Text( const TextBuilder &rSrc );
46 virtual ~Text(); 42 virtual ~Text();
47 43
48 bool isEmpty() const; 44 bool isEmpty() const;
49 bool isBmpOnly() const; 45 bool isBmpOnly() const;
50 int32_t getSize() const; 46 int32_t getSize() const;
51 int32_t getSizeInBytes() const; 47 int32_t getSizeInBytes() const;
48 CodePoint operator[]( int32_t iIndex ) const;
52 49
53 uint16_t *getRawData() const; 50 CodePoint *getData() const;
54// Text transform( (CodePoint *)(*pCallback)( CodePoint * ) ); 51// Text transform( (CodePoint *)(*pCallback)( CodePoint * ) );
55 52
56 private: 53 private:
57 uint16_t *pData; 54 CodePoint *pData;
55 bool bIsBmpOnly;
58 int32_t iSize; 56 int32_t iSize;
59 int32_t iCodePoints;
60 }; 57 };
61 typedef Text::CodePoint CodePoint; 58 typedef Text::CodePoint CodePoint;
62} 59}
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 )
191 191
192void Bu::TextBuilderCore::copyTo( void *pDestRaw, int32_t iLength ) 192void Bu::TextBuilderCore::copyTo( void *pDestRaw, int32_t iLength )
193{ 193{
194 194 CodePoint *pDest = reinterpret_cast<CodePoint *>( pDestRaw );
195
196 Chunk *pCur = pFirst;
197 while( pCur && iLength )
198 {
199 }
195} 200}
196 201
197Bu::CodePoint Bu::TextBuilderCore::getAt( int32_t iIndex ) const 202Bu::CodePoint Bu::TextBuilderCore::getAt( int32_t iIndex ) const
@@ -270,6 +275,11 @@ Bu::Text Bu::TextBuilder::getText() const
270 return Text( *this ); 275 return Text( *this );
271} 276}
272 277
278void Bu::TextBuilder::copyTo( void *pDestRaw, int32_t iDestSize ) const
279{
280 core->copyTo( pDestRaw, iDestSize );
281}
282
273Bu::CodePoint Bu::TextBuilder::operator[]( int32_t iIndex ) const 283Bu::CodePoint Bu::TextBuilder::operator[]( int32_t iIndex ) const
274{ 284{
275 return core->getAt( iIndex ); 285 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
75 75
76 int32_t getSize() const; 76 int32_t getSize() const;
77 Text getText() const; 77 Text getText() const;
78 void copyTo( void *pDestRaw, int32_t iDestSize ) const;
78 CodePoint operator[]( int32_t iIndex ) const; 79 CodePoint operator[]( int32_t iIndex ) const;
79 80
80 TextBuilder &operator=( const Text &rSrc ); 81 TextBuilder &operator=( const Text &rSrc );