Merge branch 'string_set_fix' of https://github.com/GoaLitiuM/FlaxEngine into GoaLitiuM-string_set_fix
This commit is contained in:
@@ -34,22 +34,26 @@ String::String(const StringAnsiView& str)
|
||||
|
||||
void String::Set(const Char* chars, int32 length)
|
||||
{
|
||||
if (length != _length)
|
||||
ASSERT(length >= 0);
|
||||
if (length == _length)
|
||||
{
|
||||
ASSERT(length >= 0);
|
||||
Platform::Free(_data);
|
||||
if (_data == chars)
|
||||
return;
|
||||
Platform::MemoryCopy(_data, chars, length * sizeof(Char));
|
||||
}
|
||||
else
|
||||
{
|
||||
Char* alloc = nullptr;
|
||||
if (length != 0)
|
||||
{
|
||||
_data = (Char*)Platform::Allocate((length + 1) * sizeof(Char), 16);
|
||||
_data[length] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_data = nullptr;
|
||||
alloc = (Char*)Platform::Allocate((length + 1) * sizeof(Char), 16);
|
||||
alloc[length] = 0;
|
||||
Platform::MemoryCopy(alloc, chars, length * sizeof(Char));
|
||||
}
|
||||
Platform::Free(_data);
|
||||
_data = alloc;
|
||||
_length = length;
|
||||
}
|
||||
Platform::MemoryCopy(_data, chars, length * sizeof(Char));
|
||||
}
|
||||
|
||||
void String::Set(const char* chars, int32 length)
|
||||
|
||||
Reference in New Issue
Block a user