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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
25
* This class encapsulates a basic string.
29
#ifndef __CSSTRING_H__
30
#define __CSSTRING_H__
37
#include <CoreFoundation/CFString.h>
44
* A unsigned 16-bit unicode character:
46
#define unichar uint16_t
48
// CSStringBuffer_ is just a base class to define
49
// referenced and non referenced versions on.
50
class CSStringBuffer_ {
53
CSStringBuffer_(u_int grow);
60
void append(const char *str, size_t len);
62
void append(const char *str) {append(str, strlen(str));}
64
void append(int value);
66
void append(uint32_t value);
70
char *getBuffer(u_int pos) { return iBuffer ? iBuffer + pos : NULL; }
74
void setLength(u_int len);
76
void setGrowSize(u_int size) { iGrow = size; }
78
u_int length() { return myStrLen; }
80
u_int ignore(u_int pos, char ch);
82
u_int find(u_int pos, char ch);
84
u_int trim(u_int pos, char ch);
86
CSString *substr(u_int pos, u_int len);
95
class CSStringBuffer : public CSStringBuffer_, public CSObject {
97
CSStringBuffer(): CSStringBuffer_(){ }
98
CSStringBuffer(u_int grow): CSStringBuffer_(grow){ }
101
class CSRefStringBuffer : public CSStringBuffer_, public CSRefObject {
103
CSRefStringBuffer(): CSStringBuffer_(){ }
104
CSRefStringBuffer(u_int grow): CSStringBuffer_(grow){ }
107
class CSSyncStringBuffer : public CSStringBuffer, public CSSync {
109
CSSyncStringBuffer(u_int growSize): CSStringBuffer(growSize), CSSync() { }
110
CSSyncStringBuffer(): CSStringBuffer(), CSSync() { }
115
class CSString : public CSRefObject {
118
virtual ~CSString() { }
121
* Construct a string from a C-style UTF-8
124
static CSString *newString(const char *cstr);
126
/* Construct a string from a UTF-8 byte array: */
127
static CSString *newString(const char *bytes, u_int len);
129
/* Construct a string from string buffer: */
130
static CSString *newString(CSStringBuffer *sb);
133
* Returns a pointer to a UTF-8 string.
134
* The returned string must be
135
* not be freed by the caller.
137
virtual const char *getCString() = 0;
140
* Return the character at a certain point:
142
virtual CS_CHAR charAt(u_int pos) = 0;
143
virtual CS_CHAR upperCharAt(u_int pos) = 0;
144
virtual void setCharAt(u_int pos, CS_CHAR ch) = 0;
147
* Returns < 0 if this string is
148
* sorted before val, 0 if equal,
149
* > 0 if sortede after.
150
* The comparison is case-insensitive.
152
virtual int compare(CSString *val) = 0;
153
virtual int compare(const char *val, u_int len = ((u_int) 0xFFFFFFFF)) = 0;
156
* Case sensitive match.
158
virtual bool startsWith(u_int index, const char *) = 0;
160
/* Returns the string length in characters. */
161
virtual u_int length() = 0;
162
virtual void setLength(u_int len) = 0;
164
virtual bool equals(const char *str);
167
* Return a copy of this string.
169
virtual CSString *clone(u_int pos, u_int len) = 0;
172
* Concatinate 2 strings.
174
virtual CSString *concat(CSString *str);
175
virtual CSString *concat(const char *str);
177
/* Return an upper case version of the string: */
178
virtual CSString *toUpper();
181
* Returns a case-insensitive has
184
virtual u_int hashKey();
187
* Locate the count'th occurance of the given
188
* string, moving from left to right or right to
189
* left if count is negative.
191
* The index of the first character is zero.
192
* If not found, then index returned depends
193
* on the search direction.
195
* Search from left to right will return
196
* the length of the string, and search
197
* from right to left will return 0.
199
virtual u_int locate(const char *, s_int count);
200
virtual u_int locate(u_int pos, const char *);
201
virtual u_int locate(u_int pos, CS_CHAR ch);
203
virtual u_int skip(u_int pos, CS_CHAR ch);
205
virtual CSString *substr(u_int index, u_int size);
206
virtual CSString *substr(u_int index);
208
virtual CSString *left(const char *, s_int count);
209
virtual CSString *left(const char *);
211
virtual CSString *right(const char *, s_int count);
212
virtual CSString *right(const char *);
214
virtual bool startsWith(const char *);
215
virtual bool endsWith(const char *);
217
/* Return the next position in the string, but do
218
* not go past the length of the string.
220
virtual u_int nextPos(u_int pos);
222
virtual CSString *clone(u_int len);
223
virtual CSString *clone();
226
class CSCString : public CSString {
235
virtual const char *getCString();
237
virtual CS_CHAR charAt(u_int pos);
239
virtual CS_CHAR upperCharAt(u_int pos);
241
virtual void setCharAt(u_int pos, CS_CHAR ch);
243
virtual int compare(CSString *val);
244
virtual int compare(const char *val, u_int len = ((u_int) 0xFFFFFFFF));
246
virtual bool startsWith(u_int index, const char *);
248
virtual u_int length() { return myStrLen; }
250
virtual void setLength(u_int len);
252
virtual CSString *clone(u_int pos, u_int len);
254
virtual CSObject *getKey();
256
virtual int compareKey(CSObject *);
258
static CSString *newString(const char *cstr);
260
static CSString *newString(const char *bytes, u_int len);
262
static CSString *newString(CSStringBuffer *sb);