~drizzle-trunk/drizzle/development

1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
 *
3
 * PrimeBase Media Stream for MySQL
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
18
 *
19
 * Original author: Paul McCullagh (H&G2JCtL)
20
 * Continued development: Barry Leslie
21
 *
22
 * 2007-06-15
23
 *
24
 * CORE SYSTEM
25
 * This class encapsulates a basic string.
26
 *
27
 */
28
29
#ifndef __CSSTRING_H__
30
#define __CSSTRING_H__
31
#include <string.h>
32
33
#include "CSDefs.h"
34
#include "CSObject.h"
35
36
#ifdef OS_MACINTOSH
37
#include <CoreFoundation/CFString.h>
38
#endif
39
40
41
class CSString;
42
43
/*
44
 * A unsigned 16-bit unicode character:
45
 */
46
#define unichar			uint16_t
47
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
48
/* CSStringBufferImpl is the string buffer implementation.
49
 * Of this implementation we have various types.
50
 */
51
class CSStringBufferImpl {
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
52
public:
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
53
	CSStringBufferImpl();
54
	CSStringBufferImpl(uint32_t grow);
55
	~CSStringBufferImpl();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
56
57
	void clear();
58
59
	void append(char ch);
60
61
	void append(const char *str, size_t len);
62
63
	void append(const char *str) {append(str, strlen(str));}
64
65
	void append(int value);
66
67
	void append(uint32_t value);
68
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
69
	void append(uint64_t value);
70
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
71
	char *getCString();
72
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
73
	char *getBuffer(uint32_t pos) { return iBuffer ? iBuffer + pos : NULL; }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
74
75
	char *take();
76
	
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
77
	void setLength(uint32_t len);
78
79
	void setGrowSize(uint32_t size) { iGrow = size; }
80
81
	uint32_t length() { return myStrLen; }
82
83
	uint32_t ignore(uint32_t pos, char ch);
84
85
	uint32_t find(uint32_t pos, char ch);
86
87
	uint32_t trim(uint32_t pos, char ch);
88
89
	CSString *substr(uint32_t pos, uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
90
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
91
	void take(CSStringBufferImpl *buf) {
92
		clear();
93
		iGrow = buf->iGrow;
94
		iSize = buf->iSize;
95
		myStrLen = buf->myStrLen;
96
		iBuffer = buf->take();
97
	}
98
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
99
private:
100
	char *iBuffer;
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
101
	uint32_t iGrow;
102
	uint32_t iSize;
103
	uint32_t myStrLen;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
104
};
105
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
106
class CSStringBuffer : public CSStringBufferImpl, public CSObject {
107
public:
108
	CSStringBuffer(): CSStringBufferImpl(), CSObject() { }
109
	CSStringBuffer(uint32_t grow): CSStringBufferImpl(grow), CSObject() { }
110
};
111
112
class CSStaticStringBuffer : public CSStringBufferImpl, public CSStaticObject {
113
	virtual void finalize() { clear(); }
114
115
public:
116
	CSStaticStringBuffer(): CSStringBufferImpl(), CSStaticObject() { }
117
	CSStaticStringBuffer(uint32_t grow): CSStringBufferImpl(grow), CSStaticObject() { }
118
};
119
120
class CSRefStringBuffer : public CSStringBufferImpl, public CSRefObject {
121
public:
122
	CSRefStringBuffer(): CSStringBufferImpl(), CSRefObject() { }
123
	CSRefStringBuffer(uint32_t grow): CSStringBufferImpl(grow), CSRefObject() { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
124
};
125
126
class CSSyncStringBuffer : public CSStringBuffer, public CSSync {
127
public:
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
128
	CSSyncStringBuffer(uint32_t growSize): CSStringBuffer(growSize), CSSync() { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
129
	CSSyncStringBuffer(): CSStringBuffer(), CSSync() { }
130
};
131
132
#define CS_CHAR		int
133
134
class CSString : public CSRefObject {
135
public:
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
136
	CSString();
137
	CSString(const char *cstr);
138
	virtual ~CSString();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
139
140
	/*
141
	 * Construct a string from a C-style UTF-8
142
	 * string.
143
	 */
144
	static CSString *newString(const char *cstr);
145
146
	/* Construct a string from a UTF-8 byte array: */
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
147
	static CSString *newString(const char *bytes, uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
148
149
	/* Construct a string from string buffer: */
150
	static CSString *newString(CSStringBuffer *sb);
151
152
	/*
153
	 * Returns a pointer to a UTF-8 string.
154
	 * The returned string must be
155
	 * not be freed by the caller.
156
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
157
	virtual const char *getCString();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
158
159
	/*
160
	 * Return the character at a certain point:
161
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
162
	virtual CS_CHAR charAt(uint32_t pos);
163
	virtual CS_CHAR upperCharAt(uint32_t pos);
164
	virtual void setCharAt(uint32_t pos, CS_CHAR ch);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
165
166
	/*
167
	 * Returns < 0 if this string is
168
	 * sorted before val, 0 if equal,
169
	 * > 0 if sortede after.
170
	 * The comparison is case-insensitive.
171
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
172
	virtual int compare(CSString *val);
173
	virtual int compare(const char *val, uint32_t len = ((uint32_t) 0xFFFFFFFF));
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
174
175
	/*
176
	 * Case sensitive match.
177
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
178
	virtual bool startsWith(uint32_t index, const char *);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
179
180
	/* Returns the string length in characters. */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
181
	virtual uint32_t length() { return myStrLen; }
182
	virtual void setLength(uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
183
184
	virtual bool equals(const char *str);
185
186
	/*
187
	 * Return a copy of this string.
188
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
189
	virtual CSString *clone(uint32_t pos, uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
190
191
	/*
192
	 * Concatinate 2 strings.
193
	 */
194
	virtual CSString *concat(CSString *str);
195
	virtual CSString *concat(const char *str);
196
197
	/* Return an upper case version of the string: */
198
	virtual CSString *toUpper();
199
200
	/*
201
	 * Returns a case-insensitive has
202
	 * value.
203
	 */
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
204
	virtual uint32_t hashKey();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
205
206
	/*
207
	 * Locate the count'th occurance of the given
208
	 * string, moving from left to right or right to
209
	 * left if count is negative.
210
	 *
211
	 * The index of the first character is zero.
212
	 * If not found, then index returned depends
213
	 * on the search direction.
214
	 *
215
	 * Search from left to right will return
216
	 * the length of the string, and search
217
	 * from right to left will return 0.
218
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
219
	virtual uint32_t locate(const char *, int32_t count);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
220
	virtual uint32_t locate(uint32_t pos, const char *);
221
	virtual uint32_t locate(uint32_t pos, CS_CHAR ch);
222
223
	virtual uint32_t skip(uint32_t pos, CS_CHAR ch);
224
225
	virtual CSString *substr(uint32_t index, uint32_t size);
226
	virtual CSString *substr(uint32_t index);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
227
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
228
	virtual CSString *left(const char *, int32_t count);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
229
	virtual CSString *left(const char *);
230
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
231
	virtual CSString *right(const char *, int32_t count);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
232
	virtual CSString *right(const char *);
233
234
	virtual bool startsWith(const char *);
235
	virtual bool endsWith(const char *);
236
237
	/* Return the next position in the string, but do
238
	 * not go past the length of the string.
239
	 */
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
240
	virtual uint32_t nextPos(uint32_t pos);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
241
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
242
	virtual CSString *clone(uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
243
	virtual CSString *clone();
244
245
	virtual CSObject *getKey();
246
247
	virtual int compareKey(CSObject *);
248
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
249
private:
250
	char *myCString;
251
	uint32_t myStrLen;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
252
};
253
254
#endif
255