4 data = (
char *) malloc(1);
28 data = (
char *) malloc(len + 1);
34 memcpy(data, src, len);
42 data = (
char *) malloc(len + 1);
48 memcpy(data, str.data, len + 1);
60 data = (
char *) realloc(data, len + str.len + 1);
63 memcpy(data + len, str.data, str.len + 1);
75 data = strdup(s.data);
97 return (strcmp(data, str.data) == 0);
102 return (strcmp(data, str.data) != 0);
107 return (strcmp(data, str.data) > 0);
112 return (strcmp(data, str.data) < 0);
125 char *buf = (
char *) malloc(len << 1);
133 if (*data ==
'\'' || *data ==
'\"' || *data ==
'\\')
142 buf = (
char *) realloc(buf, i + 1);
155 int s_len = strlen(search);
156 int r_len = strlen(replace);
158 int delta = r_len - s_len;
159 unsigned int count = 0;
160 while (pos <
int (len) && (limit == 0 || (limit > 0 && count < limit)))
162 if (!strncmp(data + pos, search, s_len))
165 char *buf = (
char *) malloc(len + 1);
171 memcpy(buf, data, pos);
172 memcpy(buf + pos, replace, r_len);
173 memcpy(buf + pos + r_len, data + pos + s_len, len - delta - pos - s_len + 1);
187 register int start, slen, delta, dlen, rlen;
189 unsigned int count = 0;
191 slen = strlen(search);
192 rlen = strlen(replace);
195 while ((start =
fastStrPos(data + idx, search)) >= 0 && !(limit > 0 && limit <= count))
197 buf = (
char *) malloc(dlen + delta + 1);
204 memcpy(buf, data, start);
205 memcpy(buf + start, replace, rlen);
206 memcpy(buf + start + rlen, data + start + slen, dlen - (start + slen));
220 char *start = strstr(data + offset, search);
223 return int (start - data);
236 char *data_res = data + offset;
237 plen = strlen(search);
238 for (c = 0; c < 256; c++)
242 for (c = 0; c < plen - 1; c++)
244 d[search[c] & 0377] = plen - 1 - c;
246 for (endpos = plen - 1; endpos < int (len);)
248 for (cmppos = endpos, pindx = (plen - 1); pindx >= 0; cmppos--, pindx--)
250 if (data_res[cmppos] != search[pindx])
252 endpos += d[data_res[endpos] & 0377];
258 return endpos - (plen - 1) + offset;
264 int String::fastStrPos(
const unsigned char *haystack,
int hlen,
const unsigned char *needle,
int nlen,
unsigned int offset)
267 size_t bad_char_skip[UCHAR_MAX + 1];
268 if (nlen <= 0 || !haystack || !needle)
271 const unsigned char *start = haystack;
273 for (scan = 0; scan <= UCHAR_MAX; scan = scan + 1)
275 bad_char_skip[scan] = nlen;
277 size_t last = nlen - 1;
278 for (scan = 0; scan < last; scan = scan + 1)
280 bad_char_skip[(
unsigned int)(needle[scan])] = last - scan;
284 for (scan = last; haystack[scan] == needle[scan]; scan = scan - 1)
286 return int(haystack - start) + offset;
287 hlen -= bad_char_skip[(
unsigned int)(haystack[last])];
288 haystack += bad_char_skip[(
unsigned int)(haystack[last])];
294 int len = strlen(data_tmp);
301 plen = strlen(search);
302 for (c = 0; c < 256; c++)
306 for (c = 0; c < plen - 1; c++)
308 d[search[c] & 0377] = plen - 1 - c;
310 for (endpos = plen - 1; endpos < len;)
312 for (cmppos = endpos, pindx = (plen - 1); pindx >= 0; cmppos--, pindx--)
314 if (data_tmp[cmppos] != search[pindx])
316 endpos += d[data_tmp[endpos] & 0377];
322 return endpos - (plen - 1);
330 char symbols[]=
"0123456789ABCDEF";
331 char *encoded = NULL;
332 register int enc_len = 0;
333 encoded = (
char *) malloc(len * 3 + 1);
338 for (
unsigned int i = 0; i < len; i++)
340 if (data[i] < 45 || (data[i] == 47) || (data[i] > 57 && data[i] < 65)
341 || (data[i] > 90 && data[i] < 95) || (data[i] == 96)
344 encoded[enc_len++] =
'%';
345 encoded[enc_len++] = symbols[(((u_int8_t)data[i]) >> 4) & 0xF];
346 encoded[enc_len++] = symbols[u_int8_t(data[i]) & 0xF];
350 encoded[enc_len] = data[i];
354 encoded = (
char *) realloc(encoded, enc_len + 1);
357 encoded[enc_len] = 0;
366 #define FROM_HEX( x ) ((((x)>=0x30) && ((x)<=0x39))? ((x) - 0x30) : ((x) - 'A' + 0xA))
367 char *decoded = (
char *) malloc(len + 1);
383 *(cur++) = *url ==
'+' ?
' ' : *url;
389 len = (
unsigned int) (cur - decoded);
405 if (pos >= this->len)
409 if (len + pos > this->len)
411 len = this->len - pos;
417 buf->data = (
char *) malloc(len + 1);
423 memcpy(buf->data, data+pos, len);
424 buf->data[len] =
'\0';
436 unsigned int plen = strlen(pattern);
437 List < String * >res;
438 unsigned int start = 0;
441 for (
unsigned int i = 0; i < len - plen;)
443 while (strncmp(data + i, pattern, plen) == 0 && i < len)
448 while (strncmp(data + i, pattern, plen) && i < len)
452 if (i > start && i <= len)
454 res.pushDown(
new(std::nothrow)
String(data + start, i - start));
457 String **result =
new(std::nothrow)
String *[res.getCount() + 1];
460 result[res.getCount()] = NULL;
461 for (
unsigned int i = 0; i < res.getCount(); i++)
472 unsigned int count = 0;
476 data = (
char *) malloc(15);
484 char *numeric = data;
494 buf[count++] = (char) ((x % 10) + 0x30);
501 *numeric = buf[--count];
510 unsigned int count = 0;
514 data = (
char *) malloc(21);
522 char *numeric = data;
532 buf[count++] = (char) ((x % 10) + 0x30);
539 *numeric = buf[--count];
548 unsigned int count = 0;
552 data = (
char *) malloc(15);
560 char *numeric = data;
563 buf[count++] = (char) ((x % 10) + 0x30);
570 *numeric = buf[--count];
579 unsigned int count = 0;
583 data = (
char *) malloc(21);
591 char *numeric = data;
594 buf[count++] = (char) ((x % 10) + 0x30);
601 *numeric = buf[--count];
619 unsigned int slen = 0;
620 unsigned int glen = 0;
629 data = (
char *) malloc(1);
637 str = va_arg(ap,
char *);
641 data = (
char *) realloc(data, len + slen + glen + 1);
647 memcpy(data + len, str, slen);
648 memcpy(data + len + slen, glue, glen);
653 data = (
char *) realloc(data, len + slen + 1);
659 memcpy(data + len, str, slen);
669 unsigned int slen = 0;
670 unsigned int glen = 0;
679 data = (
char *) malloc(1);
690 data = (
char *) realloc(data, len + slen + glen + 1);
696 memcpy(data + len, *str, slen);
697 memcpy(data + len + slen, glue, glen);
702 data = (
char *) realloc(data, len + slen + 1);
708 memcpy(data + len, *str, slen);
719 while( (*
string) && (*wild !=
'*'))
721 if( (*wild != *
string) && (*wild !=
'?') )
740 if( (*wild == *
string) || (*wild ==
'?') )
751 while( *wild ==
'*' )
755 return *wild ==
'\0';
760 return this->
wildcmp(pattern.data);
765 static char hexmap[] =
"0123456789abcdef";
766 unsigned int outLen = 0;
767 u_int8_t *src = (u_int8_t*)input;
768 for(
unsigned int i = 0; i < len; )
781 case '\t':outLen += 2;
break;
788 if((src[i] & 0xF0) == 0xF0) i += 4;
789 else if((src[i] & 0xE0) == 0xE0) i += 3;
796 char *dst = (
char*)malloc(outLen + 1);
797 for(
unsigned int i = 0, j = 0; i < len; )
835 default: dst[j++] = src[i];
841 if((src[i] & 0xF0) == 0xF0)
850 if((src[i] & 0xE0) == 0xE0)
852 symb = ((src[i] & 0xF) << 12) | ((src[i + 1] & 0x3F) << 6) | (src[i + 2] & 0x3F);
857 symb = ((src[i] & 0x1F) << 6) | (src[i + 1] & 0x3F);
860 dst[j++] = hexmap[(symb >> 12) & 0xf];
861 dst[j++] = hexmap[(symb >> 8) & 0xf];
862 dst[j++] = hexmap[(symb >> 4) & 0xf];
863 dst[j++] = hexmap[symb & 0xf];