aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/textbuilder.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2019-11-11 05:01:29 -0800
committerMike Buland <eichlan@xagasoft.com>2019-11-11 05:01:29 -0800
commit96759377ae8a4394d325747f597fe5b60afabf6e (patch)
treedd2daea517d126edb782924cf6003b5ae24cbe50 /src/unstable/textbuilder.h
parentd5098782e5645d39b5e92f150e187e7194ef055a (diff)
downloadlibbu++-96759377ae8a4394d325747f597fe5b60afabf6e.tar.gz
libbu++-96759377ae8a4394d325747f597fe5b60afabf6e.tar.bz2
libbu++-96759377ae8a4394d325747f597fe5b60afabf6e.tar.xz
libbu++-96759377ae8a4394d325747f597fe5b60afabf6e.zip
Working on TextBuilder & Text.
Seriously thinking about changing Text to just use full codepoints. It would be much less work, more reliable and predictable, easier to use, but would use twice the memory.
Diffstat (limited to 'src/unstable/textbuilder.h')
-rw-r--r--src/unstable/textbuilder.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/unstable/textbuilder.h b/src/unstable/textbuilder.h
index 73271f8..22fa653 100644
--- a/src/unstable/textbuilder.h
+++ b/src/unstable/textbuilder.h
@@ -5,4 +5,82 @@
5 * terms of the license contained in the file LICENSE. 5 * terms of the license contained in the file LICENSE.
6 */ 6 */
7 7
8#ifndef BU_TEXT_BUILDER_H
9#define BU_TEXT_BUILDER_H
10
11#include <stdint.h>
12#include "bu/sharedcore.h"
13#include "bu/text.h"
14
15namespace Bu
16{
17 class TextBuilder;
18
19 /** @cond DEVEL */
20 class TextBuilderCore
21 {
22 friend class TextBuilder;
23 friend class SharedCore<TextBuilder, TextBuilderCore>;
24 private:
25 class Chunk
26 {
27 public:
28 Chunk( const CodePoint *pSrc, int32_t iLength );
29 ~Chunk();
30
31 void append( const CodePoint *&pSrc, int32_t &iLength );
32
33 Chunk *split( int32_t iIndex );
34
35 int32_t iLength;
36 CodePoint *pData;
37 Chunk *pNext;
38 };
39
40 TextBuilderCore();
41 TextBuilderCore( const TextBuilderCore &rSrc );
42 virtual ~TextBuilderCore();
43
44 void clear();
45 void append( const CodePoint *pSrc, int32_t iLength );
46 void prepend( const CodePoint *pSrc, int32_t iLength );
47 void insert( int32_t iBefore, const CodePoint *pSrc, int32_t iLength );
48 void set( const CodePoint *pSrc, int32_t iLength );
49 void copyTo( void *pDestRaw, int32_t iLength );
50 CodePoint getAt( int32_t iIndex ) const;
51
52 Chunk *pFirst;
53 Chunk *pLast;
54 int32_t iLength;
55 };
56
57 class TextBuilder : public Bu::SharedCore<TextBuilder, TextBuilderCore>
58 {
59 protected:
60 using SharedCore<TextBuilder, TextBuilderCore>::core;
61 using SharedCore<TextBuilder, TextBuilderCore>::_hardCopy;
62
63 public:
64 TextBuilder();
65 TextBuilder( const Text &rSrc );
66 TextBuilder( const TextBuilder &rSrc );
67 virtual ~TextBuilder();
68
69 void set( const Text &rSrc );
70 void append( const Text &rSrc );
71 void append( const CodePoint *pSrc, int32_t iLength );
72 void prepend( const Text &rSrc );
73 void insert( const Text &rSrc );
74 void clear();
75
76 int32_t getSize() const;
77 Text getText() const;
78 CodePoint operator[]( int32_t iIndex ) const;
79
80 TextBuilder &operator=( const Text &rSrc );
81 TextBuilder &operator==( const Text &rSrc );
82 };
83}
84
85#endif
8 86