Rudiments

wstringbufferinlines.h
1 // Copyright (c) 1999-2018 David Muse
2 // See the COPYING file for more information
3
4 #include <rudiments/wcharstring.h>
5
6 inline
7 wstringbuffer::wstringbuffer() : bytebuffer() {
8 }
9
10 inline
11 wstringbuffer::wstringbuffer(size_t initialsize) : bytebuffer(initialsize) {
12 }
13
14 inline
15 wstringbuffer::wstringbuffer(wchar_t *initialcontents, size_t initialsize) :
16 bytebuffer((unsigned char *)initialcontents,
17 initialsize*sizeof(wchar_t)) {
18 }
19
20 inline
21 wstringbuffer::wstringbuffer(const wstringbuffer &s) : bytebuffer(s) {
22 }
23
24 inline
25 wstringbuffer &wstringbuffer::operator=(const wstringbuffer &s) {
26 if (this!=&s) {
27 bytebuffer::operator=(s);
28 }
29 return *this;
30 }
31
32 inline
33 wstringbuffer::~wstringbuffer() {
34 }
35
36 inline
37 void wstringbuffer::setPosition(size_t pos) {
38 bytebuffer::setPosition(pos*sizeof(wchar_t));
39 }
40
41 inline
42 const wchar_t *wstringbuffer::getString() {
43 bytebuffer::append(L'\0');
44 const wchar_t *retval=(const wchar_t *)getBuffer();
45 _position(_position()-1);
46 _size(_size()-1);
47 return retval;
48 }
49
50 inline
51 size_t wstringbuffer::getStringLength() {
52 return wcharstring::length(getString());
53 }
54
55 inline
56 wchar_t *wstringbuffer::detachString() {
57 bytebuffer::append(L'\0');
58 return (wchar_t *)detachBuffer();
59 }
60
61 inline
62 size_t wstringbuffer::getPosition() {
63 return bytebuffer::getPosition()/sizeof(wchar_t);
64 }
65
66 inline
67 void wstringbuffer::clear() {
68 bytebuffer::clear();
69 }
70
71 inline
72 void wstringbuffer::clear(size_t initialsize) {
73 bytebuffer::clear(initialsize);
74 }
75
76 inline
77 void wstringbuffer::clear(wchar_t *initialcontents, size_t initialsize) {
78 bytebuffer::clear((unsigned char *)initialcontents,
79 initialsize*sizeof(wchar_t));
80 }
81
82 inline
83 wstringbuffer *wstringbuffer::append(const wchar_t *string) {
84 return append(string,wcharstring::length(string));
85 }
86
87 inline
88 wstringbuffer *wstringbuffer::append(const wchar_t *string, size_t length) {
89 return (wstringbuffer *)bytebuffer::append(string,length);
90 }
91
92 inline
93 wstringbuffer *wstringbuffer::append(wchar_t character) {
94 return (wstringbuffer *)bytebuffer::append(character);
95 }
96
97 inline
98 wstringbuffer *wstringbuffer::append(int16_t number) {
99 return append(number,1);
100 }
101
102 inline
103 wstringbuffer *wstringbuffer::append(int32_t number) {
104 return append(number,1);
105 }
106
107 inline
108 wstringbuffer *wstringbuffer::append(int64_t number) {
109 return append(number,1);
110 }
111
112 inline
113 wstringbuffer *wstringbuffer::append(int16_t number, uint16_t zeropadding) {
114 return append((int64_t)number,zeropadding);
115 }
116
117 inline
118 wstringbuffer *wstringbuffer::append(int32_t number, uint16_t zeropadding) {
119 return append((int64_t)number,zeropadding);
120 }
121
122 inline
123 wstringbuffer *wstringbuffer::append(int64_t number, uint16_t zeropadding) {
124 wchar_t *num=wcharstring::parseNumber(number,zeropadding);
125 append(num);
126 delete[] num;
127 return this;
128 }
129
130 inline
131 wstringbuffer *wstringbuffer::append(uint16_t number) {
132 return append(number,1);
133 }
134
135 inline
136 wstringbuffer *wstringbuffer::append(uint32_t number) {
137 return append(number,1);
138 }
139
140 inline
141 wstringbuffer *wstringbuffer::append(uint64_t number) {
142 return append(number,1);
143 }
144
145 inline
146 wstringbuffer *wstringbuffer::append(uint16_t number, uint16_t zeropadding) {
147 return append((uint64_t)number,zeropadding);
148 }
149
150 inline
151 wstringbuffer *wstringbuffer::append(uint32_t number, uint16_t zeropadding) {
152 return append((uint64_t)number,zeropadding);
153 }
154
155 inline
156 wstringbuffer *wstringbuffer::append(uint64_t number, uint16_t zeropadding) {
157 wchar_t *num=wcharstring::parseNumber(number,zeropadding);
158 append(num);
159 delete[] num;
160 return this;
161 }
162
163 inline
164 wstringbuffer *wstringbuffer::append(float number) {
165 return append(number,4);
166 }
167
168 inline
169 wstringbuffer *wstringbuffer::append(float number, uint16_t scale) {
170 return (wstringbuffer *)appendFormatted(L"%.*f",
171 scale,number);
172 }
173
174 inline
175 wstringbuffer *wstringbuffer::append(float number, uint16_t precision,
176 uint16_t scale) {
177 return (wstringbuffer *)appendFormatted(L"%*.*f",
178 precision,scale,number);
179 }
180
181 inline
182 wstringbuffer *wstringbuffer::append(double number) {
183 return append(number,4);
184 }
185
186 inline
187 wstringbuffer *wstringbuffer::append(double number, uint16_t scale) {
188 return (wstringbuffer *)appendFormatted(L"%.*f",scale,number);
189 }
190
191 inline
192 wstringbuffer *wstringbuffer::append(double number, uint16_t precision,
193 uint16_t scale) {
194 return (wstringbuffer *)appendFormatted(L"%*.*f",
195 precision,scale,number);
196 }
197
198 inline
199 ssize_t wstringbuffer::write(const wchar_t *string) {
200 return write(string,wcharstring::length(string));
201 }
202
203 inline
204 ssize_t wstringbuffer::write(const wchar_t *string, size_t length) {
205 return bytebuffer::write(string,length);
206 }
207
208 inline
209 ssize_t wstringbuffer::write(wchar_t character) {
210 return bytebuffer::write(character);
211 }
212
213 inline
214 ssize_t wstringbuffer::write(int16_t number) {
215 return writeFormatted(L"%hd",number);
216 }
217
218 inline
219 ssize_t wstringbuffer::write(int32_t number) {
220 return writeFormatted(L"%d",number);
221 }
222
223 inline
224 ssize_t wstringbuffer::write(int64_t number) {
225 return writeFormatted(L"%lld",number);
226 }
227
228 inline
229 ssize_t wstringbuffer::write(uint16_t number) {
230 return writeFormatted(L"%hd",number);
231 }
232
233 inline
234 ssize_t wstringbuffer::write(uint32_t number) {
235 return writeFormatted(L"%d",number);
236 }
237
238 inline
239 ssize_t wstringbuffer::write(uint64_t number) {
240 return bytebuffer::writeFormatted(L"%lld",number);
241 }
242
243 inline
244 ssize_t wstringbuffer::write(float number) {
245 return write(number,4);
246 }
247
248 inline
249 ssize_t wstringbuffer::write(float number, uint16_t scale) {
250 return writeFormatted(L"%.*f",scale,number);
251 }
252
253 inline
254 ssize_t wstringbuffer::write(float number, uint16_t precision, uint16_t scale) {
255 return writeFormatted(L"%*.*f",precision,scale,number);
256 }
257
258 inline
259 ssize_t wstringbuffer::write(double number) {
260 return write(number,4);
261 }
262
263 inline
264 ssize_t wstringbuffer::write(double number, uint16_t scale) {
265 return writeFormatted(L"%.*f",scale,number);
266 }
267
268 inline
269 ssize_t wstringbuffer::write(double number, uint16_t precision, uint16_t scale) {
270 return writeFormatted(L"%*.*f",precision,scale,number);
271 }
272
273 inline
274 void wstringbuffer::truncate(size_t pos) {
275 bytebuffer::truncate(pos);
276 }
277
278 inline
279 void wstringbuffer::truncate() {
280 bytebuffer::truncate();
281 }
bytebuffer
Definition: bytebuffer.h:13
bytebuffer::detachBuffer
unsigned char * detachBuffer()
bytebuffer::append
bytebuffer * append(const unsigned char *data, size_t size)
bytebuffer::setPosition
void setPosition(size_t pos)
bytebuffer::clear
void clear()
bytebuffer::truncate
virtual void truncate()
bytebuffer::appendFormatted
bytebuffer * appendFormatted(const char *format,...)
bytebuffer::write
ssize_t write(const unsigned char *data, size_t size)
bytebuffer::operator=
bytebuffer & operator=(const bytebuffer &v)
bytebuffer::getBuffer
const unsigned char * getBuffer()
bytebuffer::writeFormatted
ssize_t writeFormatted(const char *format,...)
bytebuffer::getPosition
size_t getPosition()
character
Definition: character.h:11
wcharstring::length
static size_t length(const wchar_t *string)
wcharstring::parseNumber
static wchar_t * parseNumber(int16_t number)
wstringbuffer
Definition: wstringbuffer.h:14
wstringbuffer::wstringbuffer
wstringbuffer()
Definition: wstringbufferinlines.h:7
wstringbuffer::truncate
void truncate()
Definition: wstringbufferinlines.h:279
wstringbuffer::clear
void clear()
Definition: wstringbufferinlines.h:67
wstringbuffer::detachString
wchar_t * detachString()
Definition: wstringbufferinlines.h:56
wstringbuffer::append
wstringbuffer * append(const wchar_t *string)
Definition: wstringbufferinlines.h:83
wstringbuffer::operator=
wstringbuffer & operator=(const wstringbuffer &s)
Definition: wstringbufferinlines.h:25
wstringbuffer::getStringLength
size_t getStringLength()
Definition: wstringbufferinlines.h:51
wstringbuffer::write
ssize_t write(const wchar_t *string)
Definition: wstringbufferinlines.h:199
wstringbuffer::getPosition
size_t getPosition()
Definition: wstringbufferinlines.h:62
wstringbuffer::setPosition
void setPosition(size_t pos)
Definition: wstringbufferinlines.h:37
wstringbuffer::~wstringbuffer
~wstringbuffer()
Definition: wstringbufferinlines.h:33
wstringbuffer::getString
const wchar_t * getString()
Definition: wstringbufferinlines.h:42