Rudiments: /home/dmuse/temp/rudiments/include/rudiments/private/stringbufferinlines.h Source File

Rudiments

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