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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
*
* PrimeBase Media Stream for MySQL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original author: Paul McCullagh (H&G2JCtL)
* Continued development: Barry Leslie
*
* 2007-06-15
*
* CORE SYSTEM
* This class encapsulates a basic string.
*
*/
#ifndef __CSSTRING_H__
#define __CSSTRING_H__
#include <string.h>
#include "CSDefs.h"
#include "CSObject.h"
#ifdef OS_MACINTOSH
#include <CoreFoundation/CFString.h>
#endif
class CSString;
/*
* A unsigned 16-bit unicode character:
*/
#define unichar uint16_t
// CSStringBuffer_ is just a base class to define
// referenced and non referenced versions on.
class CSStringBuffer_ {
public:
CSStringBuffer_();
CSStringBuffer_(uint32_t grow);
~CSStringBuffer_();
void clear();
void append(char ch);
void append(const char *str, size_t len);
void append(const char *str) {append(str, strlen(str));}
void append(int value);
void append(uint32_t value);
char *getCString();
char *getBuffer(uint32_t pos) { return iBuffer ? iBuffer + pos : NULL; }
char *take();
void setLength(uint32_t len);
void setGrowSize(uint32_t size) { iGrow = size; }
uint32_t length() { return myStrLen; }
uint32_t ignore(uint32_t pos, char ch);
uint32_t find(uint32_t pos, char ch);
uint32_t trim(uint32_t pos, char ch);
CSString *substr(uint32_t pos, uint32_t len);
private:
char *iBuffer;
uint32_t iGrow;
uint32_t iSize;
uint32_t myStrLen;
};
class CSStringBuffer : public CSStringBuffer_, public CSObject {
public:
CSStringBuffer(): CSStringBuffer_(){ }
CSStringBuffer(uint32_t grow): CSStringBuffer_(grow){ }
};
class CSRefStringBuffer : public CSStringBuffer_, public CSRefObject {
public:
CSRefStringBuffer(): CSStringBuffer_(){ }
CSRefStringBuffer(uint32_t grow): CSStringBuffer_(grow){ }
};
class CSSyncStringBuffer : public CSStringBuffer, public CSSync {
public:
CSSyncStringBuffer(uint32_t growSize): CSStringBuffer(growSize), CSSync() { }
CSSyncStringBuffer(): CSStringBuffer(), CSSync() { }
};
#define CS_CHAR int
class CSString : public CSRefObject {
public:
CSString() { }
virtual ~CSString() { }
/*
* Construct a string from a C-style UTF-8
* string.
*/
static CSString *newString(const char *cstr);
/* Construct a string from a UTF-8 byte array: */
static CSString *newString(const char *bytes, uint32_t len);
/* Construct a string from string buffer: */
static CSString *newString(CSStringBuffer *sb);
/*
* Returns a pointer to a UTF-8 string.
* The returned string must be
* not be freed by the caller.
*/
virtual const char *getCString() = 0;
/*
* Return the character at a certain point:
*/
virtual CS_CHAR charAt(uint32_t pos) = 0;
virtual CS_CHAR upperCharAt(uint32_t pos) = 0;
virtual void setCharAt(uint32_t pos, CS_CHAR ch) = 0;
/*
* Returns < 0 if this string is
* sorted before val, 0 if equal,
* > 0 if sortede after.
* The comparison is case-insensitive.
*/
virtual int compare(CSString *val) = 0;
virtual int compare(const char *val, uint32_t len = ((uint32_t) 0xFFFFFFFF)) = 0;
/*
* Case sensitive match.
*/
virtual bool startsWith(uint32_t index, const char *) = 0;
/* Returns the string length in characters. */
virtual uint32_t length() = 0;
virtual void setLength(uint32_t len) = 0;
virtual bool equals(const char *str);
/*
* Return a copy of this string.
*/
virtual CSString *clone(uint32_t pos, uint32_t len) = 0;
/*
* Concatinate 2 strings.
*/
virtual CSString *concat(CSString *str);
virtual CSString *concat(const char *str);
/* Return an upper case version of the string: */
virtual CSString *toUpper();
/*
* Returns a case-insensitive has
* value.
*/
virtual uint32_t hashKey();
/*
* Locate the count'th occurance of the given
* string, moving from left to right or right to
* left if count is negative.
*
* The index of the first character is zero.
* If not found, then index returned depends
* on the search direction.
*
* Search from left to right will return
* the length of the string, and search
* from right to left will return 0.
*/
virtual uint32_t locate(const char *, s_int count);
virtual uint32_t locate(uint32_t pos, const char *);
virtual uint32_t locate(uint32_t pos, CS_CHAR ch);
virtual uint32_t skip(uint32_t pos, CS_CHAR ch);
virtual CSString *substr(uint32_t index, uint32_t size);
virtual CSString *substr(uint32_t index);
virtual CSString *left(const char *, s_int count);
virtual CSString *left(const char *);
virtual CSString *right(const char *, s_int count);
virtual CSString *right(const char *);
virtual bool startsWith(const char *);
virtual bool endsWith(const char *);
/* Return the next position in the string, but do
* not go past the length of the string.
*/
virtual uint32_t nextPos(uint32_t pos);
virtual CSString *clone(uint32_t len);
virtual CSString *clone();
};
class CSCString : public CSString {
public:
char *myCString;
uint32_t myStrLen;
CSCString();
~CSCString();
virtual const char *getCString();
virtual CS_CHAR charAt(uint32_t pos);
virtual CS_CHAR upperCharAt(uint32_t pos);
virtual void setCharAt(uint32_t pos, CS_CHAR ch);
virtual int compare(CSString *val);
virtual int compare(const char *val, uint32_t len = ((uint32_t) 0xFFFFFFFF));
virtual bool startsWith(uint32_t index, const char *);
virtual bool startsWith(const char *str) { return CSString::startsWith(str);}
virtual uint32_t length() { return myStrLen; }
virtual void setLength(uint32_t len);
virtual CSString *clone(uint32_t pos, uint32_t len);
virtual CSString *clone(uint32_t len){ return CSString::clone(len);}
virtual CSString *clone(){ return CSString::clone();}
virtual CSObject *getKey();
virtual int compareKey(CSObject *);
static CSCString *newString(const char *cstr);
static CSCString *newString(const char *bytes, uint32_t len);
static CSCString *newString(CSStringBuffer *sb);
};
#endif
|