Fix operator+ semantics in CBotString
parent
82ece357d6
commit
eeea31408b
|
@ -397,8 +397,8 @@ public:
|
|||
const CBotString& operator=(const CBotString& stringSrc);
|
||||
const CBotString& operator=(const char ch);
|
||||
const CBotString& operator=(const char* pString);
|
||||
const CBotString& operator+(const CBotString& str);
|
||||
friend CBotString operator+(const CBotString& string, const char* lpsz);
|
||||
CBotString operator+(const CBotString& str);
|
||||
|
||||
const CBotString& operator+=(const char ch);
|
||||
const CBotString& operator+=(const CBotString& str);
|
||||
|
|
|
@ -344,19 +344,11 @@ CBotString operator+(const CBotString& string, const char * lpsz)
|
|||
return s;
|
||||
}
|
||||
|
||||
const CBotString& CBotString::operator+(const CBotString& stringSrc)
|
||||
CBotString CBotString::operator+(const CBotString& stringSrc)
|
||||
{
|
||||
char* p = new char[m_lg+stringSrc.m_lg+1];
|
||||
|
||||
if (m_ptr!=nullptr) strcpy(p, m_ptr);
|
||||
char* pp = p + m_lg;
|
||||
if (stringSrc.m_ptr!=nullptr) strcpy(pp, stringSrc.m_ptr);
|
||||
|
||||
delete[] m_ptr;
|
||||
m_ptr = p;
|
||||
m_lg += stringSrc.m_lg;
|
||||
|
||||
return *this;
|
||||
CBotString s(*this);
|
||||
s += stringSrc;
|
||||
return s;
|
||||
}
|
||||
|
||||
const CBotString& CBotString::operator=(const char ch)
|
||||
|
|
|
@ -271,10 +271,13 @@ TEST(CBotString_Test, operatorAdd)
|
|||
CBotString botStr4("Colobot");
|
||||
|
||||
//-- C string
|
||||
const char cStr1[7] = "olobot";
|
||||
const char* cStr1 = "olobot";
|
||||
|
||||
botStr1 + botStr2;
|
||||
botStr1 + botStr3;
|
||||
botStr1 = botStr1 + botStr2;
|
||||
botStr1 = botStr1 + botStr3;
|
||||
EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
|
||||
|
||||
botStr1 = "C" + botStr3;
|
||||
EXPECT_STREQ(botStr1.CStr(), botStr4.CStr());
|
||||
|
||||
botStr1.Empty();
|
||||
|
|
Loading…
Reference in New Issue