28 : ref(1234567), data(0), length(0), hash(0), sensitive(true)
31 data =
new(__FILE__,__LINE__)
char[4];
46 : ref(1), length(0), sensitive(true)
48 if (s) length = ::strlen(s);
51 data =
new(__FILE__,__LINE__)
char[length+1];
53 data =
new char[length+1];
57 if (s) ::strcpy(data, s);
58 else data[length] =
'\0';
65 : ref(1), length(len), sensitive(true)
67 if (length < 0) length = 0;
70 data =
new(__FILE__,__LINE__)
char[length+1];
72 data =
new char[length+1];
76 ::CopyMemory(data, s, length);
83 : ref(1), length(len), sensitive(true)
85 if (length < 0) length = 0;
88 data =
new(__FILE__,__LINE__)
char[length+1];
90 data =
new char[length+1];
94 ::FillMemory(data, length, c);
103 length = rep->length;
106 data =
new(__FILE__,__LINE__)
char[length+1];
108 data =
new char[length+1];
112 sensitive = rep->sensitive;
115 ::strcpy(data, rep->data);
140 inline static void mash(
unsigned& hash,
unsigned chars)
142 hash = (chars ^ ((hash << 5) | (hash >> (8*
sizeof(unsigned) - 5))));
148 unsigned hv = (unsigned)length;
149 unsigned i = length*
sizeof(char)/
sizeof(
unsigned);
150 const unsigned* p = (
const unsigned*)data;
156 i = length*
sizeof(char)%
sizeof(
unsigned);
159 const char* c = (
const char*)p;
161 h = ((h << 8*
sizeof(char)) | *c++);
172 rep = &TextRep::nullrep;
179 char buf[2]; buf[0] = c; buf[1] =
'\0';
182 rep =
new(__FILE__,__LINE__)
TextRep(buf);
188 rep = &TextRep::nullrep;
198 rep =
new(__FILE__,__LINE__)
TextRep(s);
204 rep = &TextRep::nullrep;
214 rep =
new(__FILE__,__LINE__)
TextRep(s, len);
220 rep = &TextRep::nullrep;
230 rep =
new(__FILE__,__LINE__)
TextRep(c, len);
236 rep = &TextRep::nullrep;
252 if (rep->deref() == 0)
delete rep;
254 rep = &TextRep::nullrep;
261 if (rep->deref() == 0)
delete rep;
263 rep =
new(__FILE__,__LINE__)
TextRep(s);
269 rep = &TextRep::nullrep;
278 if (rep->deref() == 0)
delete rep;
288 char* buf =
new(__FILE__,__LINE__)
char[rep->length + 2];
290 char* buf =
new char[rep->length + 2];
295 buf[rep->length] = c;
296 buf[rep->length+1] =
'\0';
311 char* buf =
new(__FILE__,__LINE__)
char[::strlen(s) + rep->length + 1];
313 char* buf =
new char[::strlen(s) + rep->length + 1];
333 char* buf =
new(__FILE__,__LINE__)
char[s.rep->length + rep->length + 1];
335 char* buf =
new char[s.rep->length + rep->length + 1];
340 ::strcat(buf, s.sym);
354 return rep->sensitive;
367 char* buf =
new(__FILE__,__LINE__)
char[rep->length + 2];
369 char* buf =
new char[rep->length + 2];
374 buf[rep->length] = c;
375 buf[rep->length+1] =
'\0';
376 if (rep->deref() == 0)
delete rep;
379 rep =
new(__FILE__,__LINE__)
TextRep(buf);
385 rep = &TextRep::nullrep;
398 char* buf =
new(__FILE__,__LINE__)
char[::strlen(s) + rep->length + 1];
400 char* buf =
new char[::strlen(s) + rep->length + 1];
406 if (rep->deref() == 0)
delete rep;
409 rep =
new(__FILE__,__LINE__)
TextRep(buf);
415 rep = &TextRep::nullrep;
428 char* buf =
new(__FILE__,__LINE__)
char[s.rep->length + rep->length + 1];
430 char* buf =
new char[s.rep->length + rep->length + 1];
434 int lenA = rep->length;
435 int lenB = s.rep->length;
437 CopyMemory(buf, sym, lenA);
438 CopyMemory(buf + lenA, s.sym, lenB);
439 buf[lenA + lenB] = 0;
441 if (rep->deref() == 0)
delete rep;
444 rep =
new(__FILE__,__LINE__)
TextRep(buf, lenA + lenB);
450 rep = &TextRep::nullrep;
474 rep = &TextRep::nullrep;
483 if (index < (
int) rep->length)
486 throw "BOUNDS ERROR";
500 if (index < (
int) rep->length) {
502 return (
char&) sym[index];
505 throw "BOUNDS ERROR";
507 return (
char&) sym[0];
514 return (
char&) sym[index];
520 if (start > rep->length || len <= 0)
523 if (start + len > rep->length)
524 len = rep->length - start;
527 char* buf =
new(__FILE__,__LINE__)
char[len+1];
529 char* buf =
new char[len+1];
533 ::strncpy(buf, sym+start, len);
547 if (rep->length > 0) {
548 if (!rep->sensitive) {
550 if (islower(alt)) alt = toupper(alt);
551 else if (isupper(alt)) alt = tolower(alt);
553 if (strchr(rep->data, alt) != 0)
557 if (strchr(rep->data, c) != 0)
567 if (rep->length > 0 && pattern && *pattern) {
568 if (rep->sensitive) {
569 if (strstr(rep->data, pattern) != 0)
575 Text smash2(pattern);
578 if (strstr(smash1.
data(), smash2.
data()) != 0)
589 if (rep->length > 0 && charSet && *charSet) {
590 if (rep->sensitive) {
591 if (strpbrk(rep->data, charSet) != 0)
597 Text smash2(charSet);
600 if (strpbrk(smash1.
data(), smash2.
data()) != 0)
611 if (rep->length > 0) {
612 if (!rep->sensitive) {
614 if (islower(alt)) alt = toupper(alt);
615 else if (isupper(alt)) alt = tolower(alt);
617 const char* p = strchr(rep->data, alt);
620 return (p - rep->data);
623 const char* p = strchr(rep->data, c);
626 return (p - rep->data);
635 if (rep->length > 0 && pattern && *pattern) {
636 if (rep->sensitive) {
637 const char* p = strstr(rep->data, pattern);
638 if (p)
return (p - rep->data);
643 Text smash2(pattern);
646 const char* p = strstr(smash1.
data(), smash2.
data());
647 if (p)
return (p - smash1.
data());
658 size_t n = rep->length;
659 char* p = (
char*) sym;
661 *p = tolower((
unsigned char)*p);
672 size_t n = rep->length;
673 char* p = (
char*) sym;
675 *p = toupper((
unsigned char)*p);
687 if (start >= 0 && start < (
int) rep->length && length > 0) {
688 if (start + length > (
int) rep->length)
689 length = (int) rep->length - start;
691 const char* s = sym + start;
694 result.rep =
new(__FILE__,__LINE__)
TextRep(s, length);
696 result.rep =
new TextRep(s, length);
700 result.rep = &TextRep::nullrep;
702 result.sym = result.rep->data;
715 const char* q = sym + rep->length-1;
717 while (p && *p && isspace(*p)) p++;
718 while (q>p && *q && isspace(*q)) q--;
731 if (rep->length && pattern && *pattern) {
733 int skip = strlen(pattern);
735 const char* p = strstr(rep->data + index, pattern);
737 int len = (p - rep->data + index);
739 result.
append(substitution);
742 else if (index < rep->
length) {
747 while (index >= 0 && index < rep->
length);