|
|
1.1 ! root 1: #include "String.h" ! 2: ! 3: Charfield *currfield; ! 4: Rep *nullRep; ! 5: Rep *oneChar; ! 6: ! 7: void ! 8: startUp() ! 9: { ! 10: static char abc[256]; ! 11: currfield = new Charfield; ! 12: currfield->next = currfield; ! 13: String::startedUp = TRUE; ! 14: nullRep = new Rep; ! 15: nullRep->start = ""; ! 16: nullRep->len = 0; ! 17: nullRep->immutable(); ! 18: nullRep->now_constant(); ! 19: oneChar = new Rep[256]; ! 20: for ( int i = 256; i--; ) { ! 21: abc[i] = i; ! 22: oneChar[i].start = &abc[i]; ! 23: oneChar[i].len = 1; ! 24: oneChar[i].immutable(); ! 25: oneChar[i].now_constant(); ! 26: } ! 27: } ! 28: ! 29: String::String() ! 30: { ! 31: if (!startedUp) ! 32: startUp(); ! 33: d = nullRep; ! 34: } ! 35: ! 36: String::String(char c) ! 37: { ! 38: if (!startedUp) ! 39: startUp(); ! 40: d = &oneChar[(unsigned char) c]; ! 41: } ! 42: ! 43: String::String(char c, char cc) ! 44: { ! 45: if (!startedUp) ! 46: startUp(); ! 47: d = new Rep(2); ! 48: register char *p = d->start; ! 49: *p++ = c; ! 50: *p = cc; ! 51: } ! 52: ! 53: String::String(char c, char cc, char ccc) ! 54: { ! 55: if (!startedUp) ! 56: startUp(); ! 57: d = new Rep(3); ! 58: register char *p = d->start; ! 59: *p++ = c; ! 60: *p++ = cc; ! 61: *p = ccc; ! 62: } ! 63: ! 64: String::String(char c, char cc, char ccc, char cccc) ! 65: { ! 66: if (!startedUp) ! 67: startUp(); ! 68: d = new Rep(4); ! 69: register char *p = d->start; ! 70: *p++ = c; ! 71: *p++ = cc; ! 72: *p++ = ccc; ! 73: *p = cccc; ! 74: } ! 75: ! 76: String::String(const char *s) ! 77: { ! 78: register len = strlen(s); ! 79: if (!startedUp) ! 80: startUp(); ! 81: switch (len) { ! 82: case 0: ! 83: d = nullRep; ! 84: break; ! 85: case 1: ! 86: d = &oneChar[(unsigned char) *s]; ! 87: break; ! 88: default: ! 89: if (len > MAXSTRINGLENGTH) { ! 90: error(1, "String::String(char *): overflow"); ! 91: len = MAXSTRINGLENGTH; ! 92: } ! 93: d = new Rep(s, len); ! 94: break; ! 95: } ! 96: } ! 97: ! 98: String::String(const char *s, unsigned len) ! 99: { ! 100: if (!startedUp) ! 101: startUp(); ! 102: switch (len) { ! 103: case 0: ! 104: d = nullRep; ! 105: break; ! 106: case 1: ! 107: d = &oneChar[(unsigned char) *s]; ! 108: break; ! 109: default: ! 110: if (len > MAXSTRINGLENGTH) { ! 111: error(1, "String::String(char *, unsigned): overflow"); ! 112: len = MAXSTRINGLENGTH; ! 113: } ! 114: d = new Rep(s, len); ! 115: break; ! 116: } ! 117: } ! 118: ! 119: String::String(const SubString& s) ! 120: { ! 121: if (s.length() == 0 ) ! 122: d = nullRep; ! 123: else if (s.length() == 1 ) ! 124: d = &oneChar[(unsigned char) s.it()->d->start[s.offset()]]; ! 125: else if ( !(d = s.it()->d->newSub(s.offset(), s.length()))) ! 126: d = new Rep(s.it()->d->start+s.offset(), s.length()); ! 127: /* delete &s; it's used up */ ! 128: } ! 129:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.