~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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
 
#pragma once
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
 
 
49
 
/* CSStringBufferImpl is the string buffer implementation.
50
 
 * Of this implementation we have various types.
51
 
 */
52
 
class CSStringBufferImpl {
53
 
public:
54
 
        CSStringBufferImpl();
55
 
        CSStringBufferImpl(uint32_t grow);
56
 
        ~CSStringBufferImpl();
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
 
 
70
 
        void append(uint64_t value);
71
 
 
72
 
        char *getCString();
73
 
 
74
 
        char *getBuffer(uint32_t pos) { return iBuffer ? iBuffer + pos : NULL; }
75
 
 
76
 
        char *take();
77
 
        
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);
91
 
 
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
 
 
100
 
private:
101
 
        char *iBuffer;
102
 
        uint32_t iGrow;
103
 
        uint32_t iSize;
104
 
        uint32_t myStrLen;
105
 
};
106
 
 
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() { }
125
 
};
126
 
 
127
 
class CSSyncStringBuffer : public CSStringBuffer, public CSSync {
128
 
public:
129
 
        CSSyncStringBuffer(uint32_t growSize): CSStringBuffer(growSize), CSSync() { }
130
 
        CSSyncStringBuffer(): CSStringBuffer(), CSSync() { }
131
 
};
132
 
 
133
 
#define CS_CHAR         int
134
 
 
135
 
class CSString : public CSRefObject {
136
 
public:
137
 
        CSString();
138
 
        CSString(const char *cstr);
139
 
        virtual ~CSString();
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: */
148
 
        static CSString *newString(const char *bytes, uint32_t len);
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
 
         */
158
 
        virtual const char *getCString();
159
 
 
160
 
        /*
161
 
         * Return the character at a certain point:
162
 
         */
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);
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
 
         */
173
 
        virtual int compare(CSString *val);
174
 
        virtual int compare(const char *val, uint32_t len = ((uint32_t) 0xFFFFFFFF));
175
 
 
176
 
        /*
177
 
         * Case sensitive match.
178
 
         */
179
 
        virtual bool startsWith(uint32_t index, const char *);
180
 
 
181
 
        /* Returns the string length in characters. */
182
 
        virtual uint32_t length() { return myStrLen; }
183
 
        virtual void setLength(uint32_t len);
184
 
 
185
 
        virtual bool equals(const char *str);
186
 
 
187
 
        /*
188
 
         * Return a copy of this string.
189
 
         */
190
 
        virtual CSString *clone(uint32_t pos, uint32_t len);
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
 
         */
205
 
        virtual uint32_t hashKey();
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
 
         */
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);
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);
228
 
 
229
 
        virtual CSString *left(const char *, int32_t count);
230
 
        virtual CSString *left(const char *);
231
 
 
232
 
        virtual CSString *right(const char *, int32_t count);
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
 
         */
241
 
        virtual uint32_t nextPos(uint32_t pos);
242
 
 
243
 
        virtual CSString *clone(uint32_t len);
244
 
        virtual CSString *clone();
245
 
 
246
 
        virtual CSObject *getKey();
247
 
 
248
 
        virtual int compareKey(CSObject *);
249
 
 
250
 
private:
251
 
        char *myCString;
252
 
        uint32_t myStrLen;
253
 
};
254
 
 
255
 
#endif
256