/// Set SimpleString equal to a single character. void SimpleString::operator=(char c) { char* old_S = S; n = 1; S = new char [2]; if (!S) Throw(Bad_alloc()); S[0] = c; S[1] = 0; delete [] old_S; }
/// Construct SimpleString equal to a C character string. SimpleString::SimpleString(const char* c) { const char* s2 = c; n = 0; while (*s2++ != 0) ++n; S = new char [n+1]; if (!S) Throw(Bad_alloc()); char* s1 = S; s2 = c; unsigned int i = n+1; while (i--) *s1++ = *s2++; }
/// Set SimpleString equal to a SimpleString. void SimpleString::operator=(const SimpleString& s) { char* old_S = S; n = s.n; S = new char [n+1]; if (!S) Throw(Bad_alloc()); char* s1 = S; const char* s2 = s.S; unsigned int i = n+1; while (i--) *s1++ = *s2++; delete [] old_S; }
/// Append character to SimpleString. void SimpleString::operator+=(char c) { char* old_S = S; unsigned int old_n = n; ++n; S = new char [n+1]; if (!S) Throw(Bad_alloc()); char* s1 = S; const char* s2 = old_S; unsigned int i = old_n; while (i--) *s1++ = *s2++; *s1++ = c; *s1 = 0; delete [] old_S; }
/// Set SimpleString equal to a C character string. void SimpleString::operator=(const char* c) { const char* s2 = c; n = 0; while (*s2++ != 0) ++n; char* old_S = S; S = new char [n+1]; if (!S) Throw(Bad_alloc()); char* s1 = S; s2 = c; unsigned int i = n+1; while (i--) *s1++ = *s2++; delete [] old_S; }
/// Append C character string to SimpleString. void SimpleString::operator+=(const char* c) { char* old_S = S; unsigned int old_n = n; const char* s2 = c; int n2 = 0; while (*s2++ != 0) ++n2; n += n2; S = new char [n+1]; if (!S) Throw(Bad_alloc()); char* s1 = S; s2 = old_S; unsigned int i = old_n; while (i--) *s1++ = *s2++; s2 = c; i = n2+1; while (i--) *s1++ = *s2++; delete [] old_S; }
/// Construct SimpleString equal to i copies of a character, c. SimpleString::SimpleString(unsigned int i, char c) : n(i) { S = new char [n+1]; if (!S) Throw(Bad_alloc()); char* s1 = S; while (i--) *s1++ = c; *s1 = 0; }
/// Construct SimpleString equal to a SimpleString. SimpleString::SimpleString(const SimpleString& s) : n(s.n) { S = new char [n+1]; if (!S) Throw(Bad_alloc()); char* s1 = S; const char* s2 = s.S; unsigned int i = n+1; while (i--) *s1++ = *s2++; }
/// Construct an empty SimpleString. SimpleString::SimpleString() : n(0) { S = new char [1]; if (!S) Throw(Bad_alloc()); *S = 0; }
void MatrixErrorNoSpace(const void* v) { if (!v) Throw(Bad_alloc()); }