string& string::operator=(const TinySTL::string &str){ if(this != &str){ destroyAndDeallocate(); allocateAndCopy(str.start_, str.finish_); } return *this; }
void string::resize(size_t n, char c) { if (n < size()) { dataAllocator::destroy(start_ + n, finish_); finish_ = start_ + n; } else if (n > size() && n <= capacity()) { auto lengthOfInsert = n - size(); finish_ = mystl::uninitialized_fill_n(finish_, lengthOfInsert, c); } else if (n > capacity()) { auto lengthOfInsert = n - size(); iterator newStart = dataAllocator::allocate(getNewCapacity(lengthOfInsert)); iterator newFinish = mystl::uninitialized_copy(begin(), end(), newStart); newFinish = mystl::uninitialized_fill_n(newFinish, lengthOfInsert, c); destroyAndDeallocate(); start_ = newStart; finish_ = newFinish; endOfStorage_ = start_ + n; } }
void string::reserve(size_t n){ if(n <= capacity()){ return ; } iterator newStart = dataAllocator::allocate(n); iterator newFinish = std::uninitialized_copy(begin(), end(), newStart); destroyAndDeallocate(); start_ = newStart; finish_ = newFinish; endOfStorage_ = start_ + n; }
string::iterator string::insert_aux_filln(iterator p, size_t n, value_type c){ auto newCapacity = getNewCapacity(n); iterator newStart = dataAllocator::allocate(newCapacity); iterator newFinish = std::uninitialized_fill_n(start_, n, c); auto res = newFinish; newFinish = std::uninitialized_copy(p,finish_,newFinish); destroyAndDeallocate(); start_ = newStart; finish_ = newFinish; endOfStorage_ = start_ + newCapacity; return res; }
string& string::operator=(const char *s){ destroyAndDeallocate(); allocateAndCopy(s, s+strlen(s)); return *this; }
string& string::operator=(char c){ destroyAndDeallocate(); allocateAndFillN(1, c); return *this; }
string::~string(){ destroyAndDeallocate(); }