// // Construct a string from the first number of characters in another string // STR_String::STR_String(rcSTR_String str, int len) : pData(new char [len+8]), Len(len), Max(len+8) { assertd(pData != NULL); assertd(str.pData != NULL); memcpy(pData, str.pData, str.Length()); pData[str.Length()] = 0; }
// // Construct a string from the first number of characters in another string // STR_String::STR_String(rcSTR_String str, int len) : m_data(new char[len + 8]), m_len(len), m_max(len + 8) { assertd(this->m_data != NULL); assertd(str.this->m_data != NULL); memcpy(this->m_data, str.ReadPtr(), str.Length()); this->m_data[str.Length()] = 0; }
// // Replace a substring of this string with another string // void STR_String::Replace(int pos, int num, rcSTR_String str) { //bounds(pos, 0, Length()-1); //bounds(pos+num, 0, Length()); assertd(num >= 1); if (str.Length() < num) { // Remove some data from the string by replacement memcpy(this->m_data + pos + str.Length(), this->m_data + pos + num, this->m_len - pos - num + 1); memcpy(this->m_data + pos, str.ReadPtr(), str.Length()); } else { // Insert zero or more characters into the string AllocBuffer(this->m_len + str.Length() - num, true); if (str.Length() != num) memcpy(this->m_data + pos + str.Length(), this->m_data + pos + num, Length() - pos - num + 1); memcpy(this->m_data + pos, str.ReadPtr(), str.Length()); } this->m_len += str.Length() - num; }
// // Replace a character in this string with another string // void STR_String::Replace(int pos, rcSTR_String str) { //bounds(pos, 0, Length()-1); if (str.Length() < 1) { // Remove one character from the string memcpy(this->m_data + pos, this->m_data + pos + 1, this->m_len - pos); } else { // Insert zero or more characters into the string AllocBuffer(this->m_len + str.Length() - 1, true); if (str.Length() != 1) memcpy(this->m_data + pos + str.Length(), this->m_data + pos + 1, Length() - pos); memcpy(this->m_data + pos, str.ReadPtr(), str.Length()); } this->m_len += str.Length() - 1; }