1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#include <cstring>
#include "Text.h"
#include "Decoder.h"
namespace jin
{
namespace graphics
{
/////////////////////////////////////////////////////////////////////////////
// iterator
/////////////////////////////////////////////////////////////////////////////
Text::Iterator::Iterator(const Iterator& itor)
: data(itor.data)
, p(itor.p)
, encode(itor.encode)
, length(itor.length)
{
switch (encode)
{
case Encode::UTF8: decoder = new Utf8(); break;
}
}
Text::Iterator::Iterator(const Encode& _encode, const void* _data, unsigned int _length)
: data(_data)
, p(_data)
, encode(_encode)
, length(_length)
{
switch (encode)
{
case Encode::UTF8: decoder = new Utf8(); break;
}
}
Text::Iterator::~Iterator()
{
delete decoder;
}
Codepoint Text::Iterator::get()
{
Codepoint codepoint;
decoder->decode(p, &codepoint);
return codepoint;
}
Codepoint Text::Iterator::operator*()
{
return get();
}
Text::Iterator Text::Iterator::begin()
{
Iterator itor(encode, data, length);
itor.toBegin();
return itor;
}
Text::Iterator Text::Iterator::end()
{
Iterator itor(encode, data, length);
itor.toEnd();
return itor;
}
void Text::Iterator::toBegin()
{
p = (const unsigned char*)data;
}
void Text::Iterator::toEnd()
{
p = (const unsigned char*)data + length;
}
Text::Iterator& Text::Iterator::operator ++()
{
p = decoder->next(p);
return *this;
}
Text::Iterator Text::Iterator::operator ++(int)
{
p = decoder->next(p);
Iterator itor(encode, data, length);
itor.p = p;
return itor;
}
bool Text::Iterator::operator !=(const Iterator& itor)
{
return !(data == itor.data
&& p == itor.p
&& length == itor.length
&& encode == itor.encode);
}
bool Text::Iterator::operator ==(const Iterator& itor)
{
return data == itor.data
&& p == itor.p
&& length == itor.length
&& encode == itor.encode;
}
/////////////////////////////////////////////////////////////////////////////
// text
/////////////////////////////////////////////////////////////////////////////
Text::Text(Encode encode, const void* data)
{
Iterator it = Iterator(encode, data, strlen((const char*)data));
for (; it != it.end(); ++it)
{
content.push_back(*it);
}
}
Text::Text(Encode _encode, const void* _data, unsigned int _length)
{
Iterator it = Iterator(_encode, _data, _length);
for (; it != it.end(); ++it)
{
content.push_back(*it);
}
}
Text::~Text()
{
}
const Content& Text::getContent() const
{
return content;
}
const Content& Text::operator*() const
{
return content;
}
} // graphics
} // jin
|