File: stringbuffer.h

package info (click to toggle)
librudiments0 0.27-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,528 kB
  • ctags: 2,284
  • sloc: cpp: 14,657; sh: 7,547; ansic: 2,664; makefile: 945; xml: 15
file content (78 lines) | stat: -rw-r--r-- 2,510 bytes parent folder | download
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
// Copyright (c) 2002 David Muse
// See the COPYING file for more information.

#ifndef RUDIMENTS_STRINGBUFFER_H
#define RUDIMENTS_STRINGBUFFER_H

#include <rudiments/private/stringbufferincludes.h>

// The stringbuffer class can be used to store strings of arbitrary length.

class stringbuffer : public variablebuffer {
	public:
			stringbuffer();
			stringbuffer(char *initialcontents,
					size_t initialsize,
					size_t increment);
			// Creates a new buffer which will grow as necessary
			// to accomodate the string written to it.
			~stringbuffer();

		void	setPosition(size_t pos);
			// Sets the position at which the next write will
			// occur to "pos".  If the position is set beyond the
			// end of the buffer, the buffer will grow but the data
			// between the current end of the buffer and the new
			// position will be undefined.

		// The write() and append() methods return a pointer to the
		// variablebuffer instance.  This enables chaining:
		//
		//	sb->write("numbers: ")->write(5)->write(5.5);
		//	 	or
		//	sb->append("numbers: ")->append(5)->append(5.5);
		stringbuffer	*write(const char *string);
		stringbuffer	*write(const char *string, size_t size);
		stringbuffer	*write(char character);
		stringbuffer	*write(long number);
		stringbuffer	*write(double number);
		stringbuffer	*write(double number,
						unsigned short scale);
		stringbuffer	*write(double number,
						unsigned short precision,
						unsigned short scale);
			// Writes the data to the stringbuffer at the current
			// position.  If necessary, the buffer will grow to
			// accommodate the new data.
		stringbuffer	*append(const char *string);
		stringbuffer	*append(const char *string, size_t size);
		stringbuffer	*append(char character);
		stringbuffer	*append(long number);
		stringbuffer	*append(double number);
		stringbuffer	*append(double number,
						unsigned short scale);
		stringbuffer	*append(double number,
						unsigned short precision,
						unsigned short scale);
			// Appends the data to the stringbuffer.  The buffer
			// will grow to accommodate the new data.

		void	clear();
			// Empties the stringbuffer.

		char	*getString();
			// Returns the string currently stored in the
			// stringbuffer.

		size_t	getStringLength();
			// Returns the length of the string currently stored
			// in the stringbuffer.

		size_t	getPosition();
			// Returns the position in the buffer at which
			// the next write will occur.

	#include <rudiments/private/stringbuffer.h>
};

#endif