NOTE:
These are a little sketchy...I'll fill in details 'soon'.
String::String(void) { string = nullptr; length = 0; clear(); seekg(); flags(case_on); }
String::String(const char s[]) { alloc_val(strlen(s)); copy_val(s); clear(); seekg(); flags(case_on); }
String::String(const char ch) { alloc_val((ch == EOS) ? (0) : (1)); copy_val(&ch); clear(); seekg(); flags(case_on); }
String::String(long new_len, const char ch) // default ch = EOS { alloc_val(new_len); for (i = 0; i < length; i++) { string[i] = ch; } if (string != nullptr) { string[length] = EOS; } clear(); seekg(); flags(case_on); }
String::String(const String & other) { alloc_val(other.length); copy_val(other.string); // should the flags and translation information // be exact or fresh? you decide! }
void String::alloc_val(long new_len) // private { if (new_len > 0) { string = new char [new_len+1]; if (string != nullptr) { length = new_len; } else { length = 0; } } else { string = nullptr; length = 0; } return; } void String::copy_val(const char s[]) // private { if ((s != nullptr) && (string != nullptr)) { strncpy(string, s, length); string[length] = EOS; } else if (string != nullptr) { for (i = 0; i <= length; i++) { string[i] = EOS; } } return; }
String::~String(void) { destroy(); }
void String::destroy(void) // private { if (string != nullptr) { delete [] string; string = nullptr; length = 0; } clear(); seekg(); flags(case_on); return; }
String & String::operator=(const String & right) { if (this != &right) { destroy(); alloc_val(right.length); copy_val(right.string); // should the flags and translation information // be exact or fresh? you decide! // (should you decide the same for here and // copy construction?) } return *this; }
String & String::operator=(const char right[]) { destroy(); alloc_val(strlen(right)); copy_val(right); return *this; }
String & String::operator=(const char right) { destroy(); alloc_val((right == EOS) ? (0) : (1)); copy_val(&right); return *this; }