~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSString.h

Merged bug600635-table-proto-default-null-false into varchar-text-keylength-in-proto-as-characters-not-bytes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
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
 
 
48
// CSStringBuffer_ is just a base class to define
 
49
// referenced and non referenced versions on.
 
50
class CSStringBuffer_ {
 
51
public:
 
52
        CSStringBuffer_();
 
53
        CSStringBuffer_(uint32_t grow);
 
54
        ~CSStringBuffer_();
 
55
 
 
56
        void clear();
 
57
 
 
58
        void append(char ch);
 
59
 
 
60
        void append(const char *str, size_t len);
 
61
 
 
62
        void append(const char *str) {append(str, strlen(str));}
 
63
 
 
64
        void append(int value);
 
65
 
 
66
        void append(uint32_t value);
 
67
 
 
68
        char *getCString();
 
69
 
 
70
        char *getBuffer(uint32_t pos) { return iBuffer ? iBuffer + pos : NULL; }
 
71
 
 
72
        char *take();
 
73
        
 
74
        void setLength(uint32_t len);
 
75
 
 
76
        void setGrowSize(uint32_t size) { iGrow = size; }
 
77
 
 
78
        uint32_t length() { return myStrLen; }
 
79
 
 
80
        uint32_t ignore(uint32_t pos, char ch);
 
81
 
 
82
        uint32_t find(uint32_t pos, char ch);
 
83
 
 
84
        uint32_t trim(uint32_t pos, char ch);
 
85
 
 
86
        CSString *substr(uint32_t pos, uint32_t len);
 
87
 
 
88
private:
 
89
        char *iBuffer;
 
90
        uint32_t iGrow;
 
91
        uint32_t iSize;
 
92
        uint32_t myStrLen;
 
93
};
 
94
 
 
95
class CSStringBuffer : public CSStringBuffer_, public CSObject {
 
96
public:
 
97
        CSStringBuffer(): CSStringBuffer_(){ }
 
98
        CSStringBuffer(uint32_t grow): CSStringBuffer_(grow){ }
 
99
};
 
100
 
 
101
class CSRefStringBuffer : public CSStringBuffer_, public CSRefObject {
 
102
public:
 
103
        CSRefStringBuffer(): CSStringBuffer_(){ }
 
104
        CSRefStringBuffer(uint32_t grow): CSStringBuffer_(grow){ }
 
105
};
 
106
 
 
107
class CSSyncStringBuffer : public CSStringBuffer, public CSSync {
 
108
public:
 
109
        CSSyncStringBuffer(uint32_t growSize): CSStringBuffer(growSize), CSSync() { }
 
110
        CSSyncStringBuffer(): CSStringBuffer(), CSSync() { }
 
111
};
 
112
 
 
113
#define CS_CHAR         int
 
114
 
 
115
class CSString : public CSRefObject {
 
116
public:
 
117
        CSString() { }
 
118
        virtual ~CSString() { }
 
119
 
 
120
        /*
 
121
         * Construct a string from a C-style UTF-8
 
122
         * string.
 
123
         */
 
124
        static CSString *newString(const char *cstr);
 
125
 
 
126
        /* Construct a string from a UTF-8 byte array: */
 
127
        static CSString *newString(const char *bytes, uint32_t len);
 
128
 
 
129
        /* Construct a string from string buffer: */
 
130
        static CSString *newString(CSStringBuffer *sb);
 
131
 
 
132
        /*
 
133
         * Returns a pointer to a UTF-8 string.
 
134
         * The returned string must be
 
135
         * not be freed by the caller.
 
136
         */
 
137
        virtual const char *getCString() = 0;
 
138
 
 
139
        /*
 
140
         * Return the character at a certain point:
 
141
         */
 
142
        virtual CS_CHAR charAt(uint32_t pos) = 0;
 
143
        virtual CS_CHAR upperCharAt(uint32_t pos) = 0;
 
144
        virtual void setCharAt(uint32_t pos, CS_CHAR ch) = 0;
 
145
 
 
146
        /*
 
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.
 
151
         */
 
152
        virtual int compare(CSString *val) = 0;
 
153
        virtual int compare(const char *val, uint32_t len = ((uint32_t) 0xFFFFFFFF)) = 0;
 
154
 
 
155
        /*
 
156
         * Case sensitive match.
 
157
         */
 
158
        virtual bool startsWith(uint32_t index, const char *) = 0;
 
159
 
 
160
        /* Returns the string length in characters. */
 
161
        virtual uint32_t length() = 0;
 
162
        virtual void setLength(uint32_t len) = 0;
 
163
 
 
164
        virtual bool equals(const char *str);
 
165
 
 
166
        /*
 
167
         * Return a copy of this string.
 
168
         */
 
169
        virtual CSString *clone(uint32_t pos, uint32_t len) = 0;
 
170
 
 
171
        /*
 
172
         * Concatinate 2 strings.
 
173
         */
 
174
        virtual CSString *concat(CSString *str);
 
175
        virtual CSString *concat(const char *str);
 
176
 
 
177
        /* Return an upper case version of the string: */
 
178
        virtual CSString *toUpper();
 
179
 
 
180
        /*
 
181
         * Returns a case-insensitive has
 
182
         * value.
 
183
         */
 
184
        virtual uint32_t hashKey();
 
185
 
 
186
        /*
 
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.
 
190
         *
 
191
         * The index of the first character is zero.
 
192
         * If not found, then index returned depends
 
193
         * on the search direction.
 
194
         *
 
195
         * Search from left to right will return
 
196
         * the length of the string, and search
 
197
         * from right to left will return 0.
 
198
         */
 
199
        virtual uint32_t locate(const char *, s_int count);
 
200
        virtual uint32_t locate(uint32_t pos, const char *);
 
201
        virtual uint32_t locate(uint32_t pos, CS_CHAR ch);
 
202
 
 
203
        virtual uint32_t skip(uint32_t pos, CS_CHAR ch);
 
204
 
 
205
        virtual CSString *substr(uint32_t index, uint32_t size);
 
206
        virtual CSString *substr(uint32_t index);
 
207
 
 
208
        virtual CSString *left(const char *, s_int count);
 
209
        virtual CSString *left(const char *);
 
210
 
 
211
        virtual CSString *right(const char *, s_int count);
 
212
        virtual CSString *right(const char *);
 
213
 
 
214
        virtual bool startsWith(const char *);
 
215
        virtual bool endsWith(const char *);
 
216
 
 
217
        /* Return the next position in the string, but do
 
218
         * not go past the length of the string.
 
219
         */
 
220
        virtual uint32_t nextPos(uint32_t pos);
 
221
 
 
222
        virtual CSString *clone(uint32_t len);
 
223
        virtual CSString *clone();
 
224
};
 
225
 
 
226
class CSCString : public CSString {
 
227
public:
 
228
        char *myCString;
 
229
        uint32_t myStrLen;
 
230
 
 
231
        CSCString();
 
232
        ~CSCString();
 
233
 
 
234
 
 
235
        virtual const char *getCString();
 
236
 
 
237
        virtual CS_CHAR charAt(uint32_t pos);
 
238
 
 
239
        virtual CS_CHAR upperCharAt(uint32_t pos);
 
240
 
 
241
        virtual void setCharAt(uint32_t pos, CS_CHAR ch);
 
242
 
 
243
        virtual int compare(CSString *val);
 
244
        virtual int compare(const char *val, uint32_t len = ((uint32_t) 0xFFFFFFFF));
 
245
 
 
246
        virtual bool startsWith(uint32_t index, const char *);
 
247
        virtual bool startsWith(const char *str) { return CSString::startsWith(str);}
 
248
 
 
249
        virtual uint32_t length() { return myStrLen; }
 
250
 
 
251
        virtual void setLength(uint32_t len);
 
252
 
 
253
        virtual CSString *clone(uint32_t pos, uint32_t len);
 
254
        virtual CSString *clone(uint32_t len){ return CSString::clone(len);}
 
255
        virtual CSString *clone(){ return CSString::clone();}
 
256
 
 
257
        virtual CSObject *getKey();
 
258
 
 
259
        virtual int compareKey(CSObject *);
 
260
 
 
261
        static CSCString *newString(const char *cstr);
 
262
 
 
263
        static CSCString *newString(const char *bytes, uint32_t len);
 
264
 
 
265
        static CSCString *newString(CSStringBuffer *sb);
 
266
};
 
267
 
 
268
#endif
 
269