~drizzle-trunk/drizzle/development

1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
1
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
29
#pragma once
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
30
#ifndef __CSSTRING_H__
31
#define __CSSTRING_H__
32
#include <string.h>
33
34
#include "CSDefs.h"
35
#include "CSObject.h"
36
37
#ifdef OS_MACINTOSH
38
#include <CoreFoundation/CFString.h>
39
#endif
40
41
42
class CSString;
43
44
/*
45
 * A unsigned 16-bit unicode character:
46
 */
47
#define unichar			uint16_t
48
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
49
/* CSStringBufferImpl is the string buffer implementation.
50
 * Of this implementation we have various types.
51
 */
52
class CSStringBufferImpl {
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
53
public:
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
54
	CSStringBufferImpl();
55
	CSStringBufferImpl(uint32_t grow);
56
	~CSStringBufferImpl();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
57
58
	void clear();
59
60
	void append(char ch);
61
62
	void append(const char *str, size_t len);
63
64
	void append(const char *str) {append(str, strlen(str));}
65
66
	void append(int value);
67
68
	void append(uint32_t value);
69
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
70
	void append(uint64_t value);
71
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
72
	char *getCString();
73
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.
74
	char *getBuffer(uint32_t pos) { return iBuffer ? iBuffer + pos : NULL; }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
75
76
	char *take();
77
	
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.
78
	void setLength(uint32_t len);
79
80
	void setGrowSize(uint32_t size) { iGrow = size; }
81
82
	uint32_t length() { return myStrLen; }
83
84
	uint32_t ignore(uint32_t pos, char ch);
85
86
	uint32_t find(uint32_t pos, char ch);
87
88
	uint32_t trim(uint32_t pos, char ch);
89
90
	CSString *substr(uint32_t pos, uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
91
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
92
	void take(CSStringBufferImpl *buf) {
93
		clear();
94
		iGrow = buf->iGrow;
95
		iSize = buf->iSize;
96
		myStrLen = buf->myStrLen;
97
		iBuffer = buf->take();
98
	}
99
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
100
private:
101
	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.
102
	uint32_t iGrow;
103
	uint32_t iSize;
104
	uint32_t myStrLen;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
105
};
106
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
107
class CSStringBuffer : public CSStringBufferImpl, public CSObject {
108
public:
109
	CSStringBuffer(): CSStringBufferImpl(), CSObject() { }
110
	CSStringBuffer(uint32_t grow): CSStringBufferImpl(grow), CSObject() { }
111
};
112
113
class CSStaticStringBuffer : public CSStringBufferImpl, public CSStaticObject {
114
	virtual void finalize() { clear(); }
115
116
public:
117
	CSStaticStringBuffer(): CSStringBufferImpl(), CSStaticObject() { }
118
	CSStaticStringBuffer(uint32_t grow): CSStringBufferImpl(grow), CSStaticObject() { }
119
};
120
121
class CSRefStringBuffer : public CSStringBufferImpl, public CSRefObject {
122
public:
123
	CSRefStringBuffer(): CSStringBufferImpl(), CSRefObject() { }
124
	CSRefStringBuffer(uint32_t grow): CSStringBufferImpl(grow), CSRefObject() { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
125
};
126
127
class CSSyncStringBuffer : public CSStringBuffer, public CSSync {
128
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.
129
	CSSyncStringBuffer(uint32_t growSize): CSStringBuffer(growSize), CSSync() { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
130
	CSSyncStringBuffer(): CSStringBuffer(), CSSync() { }
131
};
132
133
#define CS_CHAR		int
134
135
class CSString : public CSRefObject {
136
public:
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
137
	CSString();
138
	CSString(const char *cstr);
139
	virtual ~CSString();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
140
141
	/*
142
	 * Construct a string from a C-style UTF-8
143
	 * string.
144
	 */
145
	static CSString *newString(const char *cstr);
146
147
	/* 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.
148
	static CSString *newString(const char *bytes, uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
149
150
	/* Construct a string from string buffer: */
151
	static CSString *newString(CSStringBuffer *sb);
152
153
	/*
154
	 * Returns a pointer to a UTF-8 string.
155
	 * The returned string must be
156
	 * not be freed by the caller.
157
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
158
	virtual const char *getCString();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
159
160
	/*
161
	 * Return the character at a certain point:
162
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
163
	virtual CS_CHAR charAt(uint32_t pos);
164
	virtual CS_CHAR upperCharAt(uint32_t pos);
165
	virtual void setCharAt(uint32_t pos, CS_CHAR ch);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
166
167
	/*
168
	 * Returns < 0 if this string is
169
	 * sorted before val, 0 if equal,
170
	 * > 0 if sortede after.
171
	 * The comparison is case-insensitive.
172
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
173
	virtual int compare(CSString *val);
174
	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.
175
176
	/*
177
	 * Case sensitive match.
178
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
179
	virtual bool startsWith(uint32_t index, const char *);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
180
181
	/* 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
182
	virtual uint32_t length() { return myStrLen; }
183
	virtual void setLength(uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
184
185
	virtual bool equals(const char *str);
186
187
	/*
188
	 * Return a copy of this string.
189
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
190
	virtual CSString *clone(uint32_t pos, uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
191
192
	/*
193
	 * Concatinate 2 strings.
194
	 */
195
	virtual CSString *concat(CSString *str);
196
	virtual CSString *concat(const char *str);
197
198
	/* Return an upper case version of the string: */
199
	virtual CSString *toUpper();
200
201
	/*
202
	 * Returns a case-insensitive has
203
	 * value.
204
	 */
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.
205
	virtual uint32_t hashKey();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
206
207
	/*
208
	 * Locate the count'th occurance of the given
209
	 * string, moving from left to right or right to
210
	 * left if count is negative.
211
	 *
212
	 * The index of the first character is zero.
213
	 * If not found, then index returned depends
214
	 * on the search direction.
215
	 *
216
	 * Search from left to right will return
217
	 * the length of the string, and search
218
	 * from right to left will return 0.
219
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
220
	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.
221
	virtual uint32_t locate(uint32_t pos, const char *);
222
	virtual uint32_t locate(uint32_t pos, CS_CHAR ch);
223
224
	virtual uint32_t skip(uint32_t pos, CS_CHAR ch);
225
226
	virtual CSString *substr(uint32_t index, uint32_t size);
227
	virtual CSString *substr(uint32_t index);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
228
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
229
	virtual CSString *left(const char *, int32_t count);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
230
	virtual CSString *left(const char *);
231
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
232
	virtual CSString *right(const char *, int32_t count);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
233
	virtual CSString *right(const char *);
234
235
	virtual bool startsWith(const char *);
236
	virtual bool endsWith(const char *);
237
238
	/* Return the next position in the string, but do
239
	 * not go past the length of the string.
240
	 */
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.
241
	virtual uint32_t nextPos(uint32_t pos);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
242
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.
243
	virtual CSString *clone(uint32_t len);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
244
	virtual CSString *clone();
245
246
	virtual CSObject *getKey();
247
248
	virtual int compareKey(CSObject *);
249
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
250
private:
251
	char *myCString;
252
	uint32_t myStrLen;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
253
};
254
255
#endif
256