1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
18 |
*
|
19 |
* Original author: Paul McCullagh (H&G2JCtL)
|
|
20 |
* Continued development: Barry Leslie
|
|
21 |
*
|
|
22 |
* 2007-06-15
|
|
23 |
*
|
|
24 |
* CORE SYSTEM STORAGE
|
|
25 |
* Basic storage structures.
|
|
26 |
*
|
|
27 |
*/
|
|
28 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
29 |
#include "CSConfig.h" |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
30 |
#include <inttypes.h> |
31 |
||
32 |
#include <assert.h> |
|
33 |
#include <string.h> |
|
34 |
#include <ctype.h> |
|
35 |
||
36 |
#include "CSGlobal.h" |
|
37 |
#include "CSUTF8.h" |
|
38 |
#include "CSStorage.h" |
|
39 |
#include "CSMemory.h" |
|
40 |
#include "CSString.h" |
|
41 |
#include "CSStrUtil.h" |
|
42 |
#include "CSGlobal.h" |
|
43 |
||
44 |
||
45 |
/*
|
|
46 |
* ---------------------------------------------------------------
|
|
47 |
* Core System String Buffers
|
|
48 |
*/
|
|
49 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
50 |
CSStringBufferImpl::CSStringBufferImpl(): |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
51 |
iBuffer(NULL), |
52 |
iGrow(0), |
|
53 |
iSize(0), |
|
54 |
myStrLen(0) |
|
55 |
{
|
|
56 |
iGrow = 20; |
|
57 |
}
|
|
58 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
59 |
CSStringBufferImpl::CSStringBufferImpl(uint32_t grow): |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
60 |
iBuffer(NULL), |
61 |
iGrow(0), |
|
62 |
iSize(0), |
|
63 |
myStrLen(0) |
|
64 |
{
|
|
65 |
iGrow = grow; |
|
66 |
}
|
|
67 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
68 |
CSStringBufferImpl::~CSStringBufferImpl() |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
69 |
{
|
70 |
clear(); |
|
71 |
}
|
|
72 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
73 |
void CSStringBufferImpl::clear() |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
74 |
{
|
75 |
if (iBuffer) |
|
76 |
cs_free(iBuffer); |
|
77 |
iBuffer = NULL; |
|
78 |
iSize = 0; |
|
79 |
myStrLen = 0; |
|
80 |
}
|
|
81 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
82 |
void CSStringBufferImpl::append(char ch) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
83 |
{
|
84 |
if (iSize == myStrLen) { |
|
85 |
cs_realloc((void **) &iBuffer, iSize + iGrow); |
|
86 |
iSize += iGrow; |
|
87 |
}
|
|
88 |
iBuffer[myStrLen] = ch; |
|
89 |
myStrLen++; |
|
90 |
}
|
|
91 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
92 |
void CSStringBufferImpl::append(const char *str, size_t len) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
93 |
{
|
94 |
if (myStrLen + len > iSize) { |
|
95 |
size_t add = len; |
|
96 |
||
97 |
if (add < iGrow) |
|
98 |
add = iGrow; |
|
99 |
cs_realloc((void **) &iBuffer, iSize + add); |
|
100 |
iSize += add; |
|
101 |
}
|
|
102 |
memcpy(iBuffer + myStrLen, str, len); |
|
103 |
myStrLen += len; |
|
104 |
}
|
|
105 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
106 |
void CSStringBufferImpl::append(int value) |
107 |
{
|
|
108 |
char buffer[100]; |
|
109 |
||
110 |
snprintf(buffer, 100, "%d", value); |
|
111 |
append(buffer); |
|
112 |
}
|
|
113 |
||
114 |
void CSStringBufferImpl::append(uint32_t value) |
|
115 |
{
|
|
116 |
char buffer[100]; |
|
117 |
||
118 |
snprintf(buffer, 100, "%"PRIu32, value); |
|
119 |
append(buffer); |
|
120 |
}
|
|
121 |
||
122 |
void CSStringBufferImpl::append(uint64_t value) |
|
123 |
{
|
|
124 |
char buffer[100]; |
|
125 |
||
126 |
snprintf(buffer, 100, "%"PRIu64, value); |
|
127 |
append(buffer); |
|
128 |
}
|
|
129 |
||
130 |
char *CSStringBufferImpl::getCString() |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
131 |
{
|
132 |
if (iSize == myStrLen) { |
|
133 |
cs_realloc((void **) &iBuffer, iSize + 1); |
|
134 |
iSize++; |
|
135 |
}
|
|
136 |
iBuffer[myStrLen] = 0; |
|
137 |
return iBuffer; |
|
138 |
}
|
|
139 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
140 |
char *CSStringBufferImpl::take() |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
141 |
{
|
142 |
char *buf; |
|
143 |
||
144 |
cs_realloc((void **) &iBuffer, myStrLen + 1); |
|
145 |
iSize = myStrLen + 1; |
|
146 |
iBuffer[myStrLen] = 0; |
|
147 |
||
148 |
buf = iBuffer; |
|
149 |
iBuffer = NULL; |
|
150 |
iSize = 0; |
|
151 |
myStrLen = 0; |
|
152 |
return buf; |
|
153 |
}
|
|
154 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
155 |
void CSStringBufferImpl::setLength(uint32_t len) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
156 |
{
|
157 |
if (len > iSize) { |
|
158 |
cs_realloc((void **) &iBuffer, len + 1); |
|
159 |
iSize = len+1; |
|
160 |
}
|
|
161 |
myStrLen = len; |
|
162 |
}
|
|
163 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
164 |
uint32_t CSStringBufferImpl::ignore(uint32_t pos, char ch) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
165 |
{
|
166 |
while (pos < myStrLen && iBuffer[pos] == ch) |
|
167 |
pos++; |
|
168 |
return pos; |
|
169 |
}
|
|
170 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
171 |
uint32_t CSStringBufferImpl::find(uint32_t pos, char ch) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
172 |
{
|
173 |
while (pos < myStrLen && iBuffer[pos] != ch) |
|
174 |
pos++; |
|
175 |
return pos; |
|
176 |
}
|
|
177 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
178 |
uint32_t CSStringBufferImpl::trim(uint32_t pos, char ch) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
179 |
{
|
180 |
while (pos > 0 && iBuffer[pos-1] == ch) |
|
181 |
pos--; |
|
182 |
return pos; |
|
183 |
}
|
|
184 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
185 |
CSString *CSStringBufferImpl::substr(uint32_t pos, uint32_t len) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
186 |
{
|
187 |
CSString *s = CSString::newString(iBuffer + pos, len); |
|
188 |
||
189 |
return s; |
|
190 |
}
|
|
191 |
||
192 |
/*
|
|
193 |
* ---------------------------------------------------------------
|
|
194 |
* Generic Strings
|
|
195 |
*/
|
|
196 |
||
197 |
CSString *CSString::concat(CSString *cat_str) |
|
198 |
{
|
|
199 |
CSString *new_str = NULL; |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
200 |
uint32_t len_a, len_b; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
201 |
|
202 |
enter_(); |
|
203 |
len_a = length(); |
|
204 |
len_b = cat_str->length(); |
|
205 |
new_str = clone(len_a + len_b); |
|
1548.2.19
by Barry.Leslie at PrimeBase
Fixes for longjmp clobber problem, (Hopefully) |
206 |
push_(new_str); |
207 |
||
208 |
for (uint32_t i=0; i<len_b; i++) |
|
209 |
new_str->setCharAt(len_a+i, cat_str->charAt(i)); |
|
210 |
||
211 |
pop_(new_str); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
212 |
return_(new_str); |
213 |
}
|
|
214 |
||
215 |
CSString *CSString::concat(const char *cat_str) |
|
216 |
{
|
|
217 |
CSString *new_str = NULL; |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
218 |
uint32_t len_a, len_b; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
219 |
|
220 |
enter_(); |
|
221 |
len_a = length(); |
|
222 |
len_b = strlen(cat_str); |
|
223 |
new_str = clone(len_a + len_b); |
|
1548.2.19
by Barry.Leslie at PrimeBase
Fixes for longjmp clobber problem, (Hopefully) |
224 |
push_(new_str); |
225 |
||
226 |
for (uint32_t i=0; i<len_b; i++) |
|
227 |
new_str->setCharAt(len_a+i, cat_str[i]); |
|
228 |
||
229 |
pop_(new_str); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
230 |
return_(new_str); |
231 |
}
|
|
232 |
||
233 |
CSString *CSString::toUpper() |
|
234 |
{
|
|
235 |
CSString *new_str = NULL; |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
236 |
uint32_t len; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
237 |
|
238 |
enter_(); |
|
1548.2.19
by Barry.Leslie at PrimeBase
Fixes for longjmp clobber problem, (Hopefully) |
239 |
new_str = clone(); |
240 |
push_(new_str); |
|
241 |
||
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
242 |
len = new_str->length(); |
1548.2.19
by Barry.Leslie at PrimeBase
Fixes for longjmp clobber problem, (Hopefully) |
243 |
for (uint32_t i=0; i<len; i++) |
244 |
new_str->setCharAt(i, upperCharAt(i)); |
|
245 |
||
246 |
pop_(new_str); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
247 |
return_(new_str); |
248 |
}
|
|
249 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
250 |
uint32_t CSString::hashKey() |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
251 |
{
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
252 |
register uint32_t h = 0, g; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
253 |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
254 |
for (uint32_t i=0; i<length(); i++) { |
255 |
h = (h << 4) + (uint32_t) upperCharAt(i); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
256 |
if ((g = (h & 0xF0000000))) |
257 |
h = (h ^ (g >> 24)) ^ g; |
|
258 |
}
|
|
259 |
||
260 |
return (h); |
|
261 |
}
|
|
262 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
263 |
uint32_t CSString::locate(const char *w_cstr, int32_t count) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
264 |
{
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
265 |
int32_t len = length(); |
266 |
int32_t i; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
267 |
|
268 |
if (count >= 0) { |
|
269 |
i = 0; |
|
270 |
while (i < len) { |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
271 |
if (startsWith((uint32_t) i, w_cstr)) { |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
272 |
count--; |
273 |
if (!count) |
|
274 |
return i; |
|
275 |
}
|
|
276 |
i++; |
|
277 |
}
|
|
278 |
}
|
|
279 |
else { |
|
280 |
count = -count; |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
281 |
i = len - (int32_t) strlen(w_cstr); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
282 |
while (i >= 0) { |
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
283 |
if (startsWith((uint32_t) i, w_cstr)) { |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
284 |
count--; |
285 |
if (!count) |
|
286 |
return i; |
|
287 |
}
|
|
288 |
i--; |
|
289 |
}
|
|
290 |
}
|
|
291 |
return i; |
|
292 |
}
|
|
293 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
294 |
uint32_t CSString::locate(uint32_t pos, const char *w_cstr) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
295 |
{
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
296 |
uint32_t len = length(); |
297 |
uint32_t i; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
298 |
|
299 |
if (pos > len) |
|
300 |
return len; |
|
301 |
i = pos; |
|
302 |
while (i < len) { |
|
303 |
if (startsWith(i, w_cstr)) |
|
304 |
return i; |
|
305 |
i++; |
|
306 |
}
|
|
307 |
return i; |
|
308 |
}
|
|
309 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
310 |
uint32_t CSString::locate(uint32_t pos, CS_CHAR ch) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
311 |
{
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
312 |
uint32_t len = length(); |
313 |
uint32_t i; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
314 |
|
315 |
if (pos > len) |
|
316 |
return len; |
|
317 |
i = pos; |
|
318 |
while (i < len) { |
|
319 |
if (charAt(i) == ch) |
|
320 |
return i; |
|
321 |
i++; |
|
322 |
}
|
|
323 |
return i; |
|
324 |
}
|
|
325 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
326 |
uint32_t CSString::skip(uint32_t pos, CS_CHAR ch) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
327 |
{
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
328 |
uint32_t len = length(); |
329 |
uint32_t i; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
330 |
|
331 |
if (pos > len) |
|
332 |
return len; |
|
333 |
i = pos; |
|
334 |
while (i < len) { |
|
335 |
if (charAt(i) != ch) |
|
336 |
return i; |
|
337 |
i++; |
|
338 |
}
|
|
339 |
return i; |
|
340 |
}
|
|
341 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
342 |
CSString *CSString::substr(uint32_t index, uint32_t size) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
343 |
{
|
344 |
return clone(index, size); |
|
345 |
}
|
|
346 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
347 |
CSString *CSString::substr(uint32_t index) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
348 |
{
|
349 |
return clone(index, length() - index); |
|
350 |
||
351 |
}
|
|
352 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
353 |
CSString *CSString::left(const char *w_cstr, int32_t count) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
354 |
{
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
355 |
uint32_t idx = locate(w_cstr, count); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
356 |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
357 |
if (idx == (uint32_t)-1) |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
358 |
return CSString::newString(""); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
359 |
return substr(0, idx); |
360 |
}
|
|
361 |
||
362 |
CSString *CSString::left(const char *w_cstr) |
|
363 |
{
|
|
364 |
return left(w_cstr, 1); |
|
365 |
}
|
|
366 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
367 |
CSString *CSString::right(const char *w_cstr, int32_t count) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
368 |
{
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
369 |
uint32_t idx = locate(w_cstr, count); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
370 |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
371 |
if (idx == (uint32_t)-1) { |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
372 |
return RETAIN(this); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
373 |
}
|
374 |
||
375 |
if (idx == length()) |
|
376 |
return newString(""); |
|
377 |
||
378 |
return substr(idx + strlen(w_cstr)); |
|
379 |
}
|
|
380 |
||
381 |
CSString *CSString::right(const char *w_cstr) |
|
382 |
{
|
|
383 |
return right(w_cstr, 1); |
|
384 |
}
|
|
385 |
||
386 |
bool CSString::startsWith(const char *w_str) |
|
387 |
{
|
|
388 |
return startsWith(0, w_str); |
|
389 |
}
|
|
390 |
||
391 |
bool CSString::endsWith(const char *w_str) |
|
392 |
{
|
|
393 |
return startsWith(length() - strlen(w_str), w_str); |
|
394 |
}
|
|
395 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
396 |
uint32_t CSString::nextPos(uint32_t pos) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
397 |
{
|
398 |
if (pos >= length()) |
|
399 |
return length(); |
|
400 |
return pos + 1; |
|
401 |
}
|
|
402 |
||
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
403 |
CSString *CSString::clone(uint32_t len) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
404 |
{
|
405 |
return clone(0, len); |
|
406 |
}
|
|
407 |
||
408 |
CSString *CSString::clone() |
|
409 |
{
|
|
410 |
return clone(0, length()); |
|
411 |
}
|
|
412 |
||
413 |
bool CSString::equals(const char *str) |
|
414 |
{
|
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
415 |
uint32_t len = length(); |
416 |
uint32_t i; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
417 |
|
418 |
for (i=0; i<len && *str; i++) { |
|
419 |
if (charAt(i) != *str) |
|
420 |
return false; |
|
421 |
str++; |
|
422 |
}
|
|
423 |
return i==len && !*str; |
|
424 |
}
|
|
425 |
||
426 |
/*
|
|
427 |
* ---------------------------------------------------------------
|
|
428 |
* Standard C String
|
|
429 |
*/
|
|
430 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
431 |
CSString::CSString(): |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
432 |
myCString(NULL), |
433 |
myStrLen(0) |
|
434 |
{
|
|
435 |
}
|
|
436 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
437 |
CSString::CSString(const char *cstr): |
438 |
myCString(cs_strdup(cstr)), |
|
439 |
myStrLen(strlen(cstr)) |
|
440 |
{
|
|
441 |
}
|
|
442 |
||
443 |
CSString::~CSString() |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
444 |
{
|
445 |
if (myCString) |
|
446 |
cs_free(myCString); |
|
447 |
}
|
|
448 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
449 |
const char *CSString::getCString() |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
450 |
{
|
451 |
return myCString; |
|
452 |
}
|
|
453 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
454 |
CS_CHAR CSString::charAt(uint32_t pos) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
455 |
{
|
456 |
if (pos < myStrLen) |
|
457 |
return (CS_CHAR) (unsigned char) myCString[pos]; |
|
458 |
return (CS_CHAR) 0; |
|
459 |
}
|
|
460 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
461 |
CS_CHAR CSString::upperCharAt(uint32_t pos) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
462 |
{
|
463 |
if (pos < myStrLen) |
|
464 |
return (CS_CHAR) (unsigned char) toupper(myCString[pos]); |
|
465 |
return (CS_CHAR) 0; |
|
466 |
}
|
|
467 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
468 |
void CSString::setCharAt(uint32_t pos, CS_CHAR ch) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
469 |
{
|
470 |
if (pos < myStrLen) |
|
471 |
myCString[pos] = (unsigned char) ch; |
|
472 |
}
|
|
473 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
474 |
int CSString::compare(const char *val, uint32_t len) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
475 |
{
|
476 |
const char *pa = myCString, *pb = val; |
|
477 |
int r = 0; |
|
478 |
||
479 |
enter_(); |
|
480 |
||
481 |
if (pa && pb) { |
|
482 |
while (*pa && *pb && len) { |
|
483 |
r = toupper(*pa) - toupper(*pb); |
|
484 |
if (r != 0) |
|
485 |
break; |
|
486 |
pa++; |
|
487 |
pb++; |
|
488 |
len--; |
|
489 |
}
|
|
490 |
if (len) |
|
491 |
r = toupper(*pa) - toupper(*pb); |
|
492 |
}
|
|
493 |
||
494 |
return_(r); |
|
495 |
}
|
|
496 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
497 |
int CSString::compare(CSString *val) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
498 |
{
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
499 |
return compare(val->getCString(), (uint32_t)-1); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
500 |
}
|
501 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
502 |
bool CSString::startsWith(uint32_t index, const char *w_str) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
503 |
{
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
504 |
uint32_t len = strlen(w_str); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
505 |
char *str; |
506 |
||
507 |
if (index > myStrLen) |
|
508 |
index = myStrLen; |
|
509 |
str = myCString + index; |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
510 |
for (uint32_t i=0; i<len && *str; i++) { |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
511 |
if (*str != *w_str) |
512 |
return false; |
|
513 |
str++; |
|
514 |
w_str++; |
|
515 |
}
|
|
516 |
return (*w_str == 0); |
|
517 |
}
|
|
518 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
519 |
void CSString::setLength(uint32_t len) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
520 |
{
|
521 |
cs_realloc((void **) &myCString, len+1); |
|
522 |
myCString[len] = 0; |
|
523 |
myStrLen = len; |
|
524 |
}
|
|
525 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
526 |
CSString *CSString::clone(uint32_t pos, uint32_t len) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
527 |
{
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
528 |
CSString *str = NULL; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
529 |
|
530 |
enter_(); |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
531 |
new_(str, CSString()); |
1548.2.19
by Barry.Leslie at PrimeBase
Fixes for longjmp clobber problem, (Hopefully) |
532 |
push_(str); |
533 |
||
534 |
str->myCString = (char *) cs_malloc(len + 1); |
|
535 |
str->myStrLen = len; |
|
536 |
if (pos > myStrLen) |
|
537 |
pos = myStrLen; |
|
538 |
if (len > myStrLen - pos) { |
|
539 |
/* More space has been allocated than required.
|
|
540 |
* It may be that this space will be used up.
|
|
541 |
* Set the zero terminator at the end
|
|
542 |
* of the space!
|
|
543 |
*/
|
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
544 |
str->myCString[len] = 0; |
1548.2.19
by Barry.Leslie at PrimeBase
Fixes for longjmp clobber problem, (Hopefully) |
545 |
len = myStrLen - pos; |
546 |
}
|
|
547 |
memcpy(str->myCString, myCString+pos, len); |
|
548 |
str->myCString[len] = 0; |
|
549 |
||
550 |
pop_(str); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
551 |
return_(str); |
552 |
}
|
|
553 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
554 |
CSObject *CSString::getKey() |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
555 |
{
|
556 |
return (CSObject *) this; |
|
557 |
}
|
|
558 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
559 |
int CSString::compareKey(CSObject *key) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
560 |
{
|
561 |
return compare((CSString *) key); |
|
562 |
}
|
|
563 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
564 |
CSString *CSString::newString(const char *cstr) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
565 |
{
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
566 |
CSString *str; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
567 |
|
568 |
enter_(); |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
569 |
new_(str, CSString()); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
570 |
push_(str); |
571 |
str->myCString = cs_strdup(cstr); |
|
572 |
str->myStrLen = strlen(cstr); |
|
573 |
pop_(str); |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
574 |
return_(str); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
575 |
}
|
576 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
577 |
CSString *CSString::newString(const char *bytes, uint32_t len) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
578 |
{
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
579 |
CSString *str; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
580 |
|
581 |
enter_(); |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
582 |
new_(str, CSString()); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
583 |
push_(str); |
584 |
str->myStrLen = len; |
|
585 |
str->myCString = (char *) cs_malloc(len+1); |
|
586 |
memcpy(str->myCString, bytes, len); |
|
587 |
str->myCString[len] = 0; |
|
588 |
pop_(str); |
|
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
589 |
return_(str); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
590 |
}
|
591 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
592 |
CSString *CSString::newString(CSStringBuffer *sb) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
593 |
{
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
594 |
CSString *str; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
595 |
|
596 |
enter_(); |
|
597 |
push_(sb); |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
598 |
new_(str, CSString()); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
599 |
push_(str); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
600 |
str->myStrLen = sb->length(); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
601 |
str->myCString = sb->take(); |
602 |
pop_(str); |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
603 |
pop_(sb); // pop this do not release it because CSStringBuffer is NOT a CSRefObject. |
1548.2.2
by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle. |
604 |
return_(str); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
605 |
}
|
606 |