2016-10-23 13:27:00 +00:00
|
|
|
#include "Char.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Char::operator char() const
|
|
|
|
{ return _string._str->operator[](_index); }
|
|
|
|
|
2016-10-29 09:39:18 +00:00
|
|
|
// copy-on-write magic happens here
|
2016-10-23 13:27:00 +00:00
|
|
|
Char& Char::operator=(char other)
|
|
|
|
{
|
2016-10-25 13:38:32 +00:00
|
|
|
auto data = new char[_string.size() + 1]; // space for old string & null-terminator
|
2016-10-23 13:27:00 +00:00
|
|
|
std::strcpy(data, _string.c_str());
|
2016-10-23 13:41:32 +00:00
|
|
|
data[_index] = other; // set the desired char
|
2016-10-23 13:27:00 +00:00
|
|
|
|
|
|
|
|
2016-10-23 13:41:32 +00:00
|
|
|
_string._str->operator--(); // release old StringValue
|
|
|
|
_string._str = new StringValue(data); // make a new one
|
2016-10-23 13:27:00 +00:00
|
|
|
|
|
|
|
return *this;
|
2016-10-25 13:38:32 +00:00
|
|
|
}
|