1
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
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.
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.
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
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
25
* This class encapsulates a basic string.
30
#ifndef __CSSTRING_H__
31
#define __CSSTRING_H__
38
#include <CoreFoundation/CFString.h>
45
* A unsigned 16-bit unicode character:
47
#define unichar uint16_t
49
/* CSStringBufferImpl is the string buffer implementation.
50
* Of this implementation we have various types.
52
class CSStringBufferImpl {
55
CSStringBufferImpl(uint32_t grow);
56
~CSStringBufferImpl();
62
void append(const char *str, size_t len);
64
void append(const char *str) {append(str, strlen(str));}
66
void append(int value);
68
void append(uint32_t value);
70
void append(uint64_t value);
74
char *getBuffer(uint32_t pos) { return iBuffer ? iBuffer + pos : NULL; }
78
void setLength(uint32_t len);
80
void setGrowSize(uint32_t size) { iGrow = size; }
82
uint32_t length() { return myStrLen; }
84
uint32_t ignore(uint32_t pos, char ch);
86
uint32_t find(uint32_t pos, char ch);
88
uint32_t trim(uint32_t pos, char ch);
90
CSString *substr(uint32_t pos, uint32_t len);
92
void take(CSStringBufferImpl *buf) {
96
myStrLen = buf->myStrLen;
97
iBuffer = buf->take();
107
class CSStringBuffer : public CSStringBufferImpl, public CSObject {
109
CSStringBuffer(): CSStringBufferImpl(), CSObject() { }
110
CSStringBuffer(uint32_t grow): CSStringBufferImpl(grow), CSObject() { }
113
class CSStaticStringBuffer : public CSStringBufferImpl, public CSStaticObject {
114
virtual void finalize() { clear(); }
117
CSStaticStringBuffer(): CSStringBufferImpl(), CSStaticObject() { }
118
CSStaticStringBuffer(uint32_t grow): CSStringBufferImpl(grow), CSStaticObject() { }
121
class CSRefStringBuffer : public CSStringBufferImpl, public CSRefObject {
123
CSRefStringBuffer(): CSStringBufferImpl(), CSRefObject() { }
124
CSRefStringBuffer(uint32_t grow): CSStringBufferImpl(grow), CSRefObject() { }
127
class CSSyncStringBuffer : public CSStringBuffer, public CSSync {
129
CSSyncStringBuffer(uint32_t growSize): CSStringBuffer(growSize), CSSync() { }
130
CSSyncStringBuffer(): CSStringBuffer(), CSSync() { }
135
class CSString : public CSRefObject {
138
CSString(const char *cstr);
142
* Construct a string from a C-style UTF-8
145
static CSString *newString(const char *cstr);
147
/* Construct a string from a UTF-8 byte array: */
148
static CSString *newString(const char *bytes, uint32_t len);
150
/* Construct a string from string buffer: */
151
static CSString *newString(CSStringBuffer *sb);
154
* Returns a pointer to a UTF-8 string.
155
* The returned string must be
156
* not be freed by the caller.
158
virtual const char *getCString();
161
* Return the character at a certain point:
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);
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.
173
virtual int compare(CSString *val);
174
virtual int compare(const char *val, uint32_t len = ((uint32_t) 0xFFFFFFFF));
177
* Case sensitive match.
179
virtual bool startsWith(uint32_t index, const char *);
181
/* Returns the string length in characters. */
182
virtual uint32_t length() { return myStrLen; }
183
virtual void setLength(uint32_t len);
185
virtual bool equals(const char *str);
188
* Return a copy of this string.
190
virtual CSString *clone(uint32_t pos, uint32_t len);
193
* Concatinate 2 strings.
195
virtual CSString *concat(CSString *str);
196
virtual CSString *concat(const char *str);
198
/* Return an upper case version of the string: */
199
virtual CSString *toUpper();
202
* Returns a case-insensitive has
205
virtual uint32_t hashKey();
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.
212
* The index of the first character is zero.
213
* If not found, then index returned depends
214
* on the search direction.
216
* Search from left to right will return
217
* the length of the string, and search
218
* from right to left will return 0.
220
virtual uint32_t locate(const char *, int32_t count);
221
virtual uint32_t locate(uint32_t pos, const char *);
222
virtual uint32_t locate(uint32_t pos, CS_CHAR ch);
224
virtual uint32_t skip(uint32_t pos, CS_CHAR ch);
226
virtual CSString *substr(uint32_t index, uint32_t size);
227
virtual CSString *substr(uint32_t index);
229
virtual CSString *left(const char *, int32_t count);
230
virtual CSString *left(const char *);
232
virtual CSString *right(const char *, int32_t count);
233
virtual CSString *right(const char *);
235
virtual bool startsWith(const char *);
236
virtual bool endsWith(const char *);
238
/* Return the next position in the string, but do
239
* not go past the length of the string.
241
virtual uint32_t nextPos(uint32_t pos);
243
virtual CSString *clone(uint32_t len);
244
virtual CSString *clone();
246
virtual CSObject *getKey();
248
virtual int compareKey(CSObject *);