Move some String methods impl into source from header
This commit is contained in:
@@ -21,6 +21,84 @@ String::String(const StringAnsiView& str)
|
|||||||
Set(str.Get(), str.Length());
|
Set(str.Get(), str.Length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void String::Set(const Char* chars, int32 length)
|
||||||
|
{
|
||||||
|
if (length != _length)
|
||||||
|
{
|
||||||
|
ASSERT(length >= 0);
|
||||||
|
Platform::Free(_data);
|
||||||
|
if (length != 0)
|
||||||
|
{
|
||||||
|
_data = (Char*)Platform::Allocate((length + 1) * sizeof(Char), 16);
|
||||||
|
_data[length] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_data = nullptr;
|
||||||
|
}
|
||||||
|
_length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
Platform::MemoryCopy(_data, chars, length * sizeof(Char));
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::Set(const char* chars, int32 length)
|
||||||
|
{
|
||||||
|
if (length != _length)
|
||||||
|
{
|
||||||
|
Platform::Free(_data);
|
||||||
|
if (length != 0)
|
||||||
|
{
|
||||||
|
_data = (Char*)Platform::Allocate((length + 1) * sizeof(Char), 16);
|
||||||
|
_data[length] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_data = nullptr;
|
||||||
|
}
|
||||||
|
_length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chars)
|
||||||
|
StringUtils::ConvertANSI2UTF16(chars, _data, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::Append(const Char* chars, int32 count)
|
||||||
|
{
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto oldData = _data;
|
||||||
|
const auto oldLength = _length;
|
||||||
|
|
||||||
|
_length = oldLength + count;
|
||||||
|
_data = (Char*)Platform::Allocate((_length + 1) * sizeof(Char), 16);
|
||||||
|
|
||||||
|
Platform::MemoryCopy(_data, oldData, oldLength * sizeof(Char));
|
||||||
|
Platform::MemoryCopy(_data + oldLength, chars, count * sizeof(Char));
|
||||||
|
_data[_length] = 0;
|
||||||
|
|
||||||
|
Platform::Free(oldData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void String::Append(const char* chars, int32 count)
|
||||||
|
{
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto oldData = _data;
|
||||||
|
const auto oldLength = _length;
|
||||||
|
|
||||||
|
_length = oldLength + count;
|
||||||
|
_data = (Char*)Platform::Allocate((_length + 1) * sizeof(Char), 16);
|
||||||
|
|
||||||
|
Platform::MemoryCopy(_data, oldData, oldLength * sizeof(Char));
|
||||||
|
StringUtils::ConvertANSI2UTF16(chars, _data + oldLength, count * sizeof(Char));
|
||||||
|
_data[_length] = 0;
|
||||||
|
|
||||||
|
Platform::Free(oldData);
|
||||||
|
}
|
||||||
|
|
||||||
String& String::operator+=(const StringView& str)
|
String& String::operator+=(const StringView& str)
|
||||||
{
|
{
|
||||||
Append(str.Get(), str.Length());
|
Append(str.Get(), str.Length());
|
||||||
@@ -149,6 +227,22 @@ bool String::EndsWith(const StringView& suffix, StringSearchCase searchCase) con
|
|||||||
return !StringUtils::Compare(&(*this)[Length() - suffix.Length()], *suffix);
|
return !StringUtils::Compare(&(*this)[Length() - suffix.Length()], *suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String String::ToLower() const
|
||||||
|
{
|
||||||
|
String result(*this);
|
||||||
|
for (int32 i = 0; i < result.Length(); i++)
|
||||||
|
result[i] = StringUtils::ToLower(result[i]);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String String::ToUpper() const
|
||||||
|
{
|
||||||
|
String result(*this);
|
||||||
|
for (int32 i = 0; i < result.Length(); i++)
|
||||||
|
result[i] = StringUtils::ToUpper(result[i]);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void String::TrimToNullTerminator()
|
void String::TrimToNullTerminator()
|
||||||
{
|
{
|
||||||
const int32 length = _length;
|
const int32 length = _length;
|
||||||
|
|||||||
@@ -617,100 +617,30 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets an array of characters to the string.
|
/// Sets an array of characters to the string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="chars">The pointer to the start of an array of characters to set. This array need not be null-terminated, and null characters are not treated specially.</param>
|
/// <param name="chars">The pointer to the start of an array of characters to set (UTF-16). This array need not be null-terminated, and null characters are not treated specially.</param>
|
||||||
/// <param name="length">The number of characters to assign.</param>
|
/// <param name="length">The number of characters to assign.</param>
|
||||||
void Set(const Char* chars, int32 length)
|
void Set(const Char* chars, int32 length);
|
||||||
{
|
|
||||||
if (length != _length)
|
|
||||||
{
|
|
||||||
ASSERT(length >= 0);
|
|
||||||
Platform::Free(_data);
|
|
||||||
if (length != 0)
|
|
||||||
{
|
|
||||||
_data = (Char*)Platform::Allocate((length + 1) * sizeof(Char), 16);
|
|
||||||
_data[length] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_data = nullptr;
|
|
||||||
}
|
|
||||||
_length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
Platform::MemoryCopy(_data, chars, length * sizeof(Char));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets an array of characters to the string.
|
/// Sets an array of characters to the string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="chars">The pointer to the start of an array of characters to set. This array need not be null-terminated, and null characters are not treated specially.</param>
|
/// <param name="chars">The pointer to the start of an array of characters to set (ANSI). This array need not be null-terminated, and null characters are not treated specially.</param>
|
||||||
/// <param name="length">The number of characters to assign.</param>
|
/// <param name="length">The number of characters to assign.</param>
|
||||||
void Set(const char* chars, int32 length)
|
void Set(const char* chars, int32 length);
|
||||||
{
|
|
||||||
if (length != _length)
|
|
||||||
{
|
|
||||||
Platform::Free(_data);
|
|
||||||
if (length != 0)
|
|
||||||
{
|
|
||||||
_data = (Char*)Platform::Allocate((length + 1) * sizeof(Char), 16);
|
|
||||||
_data[length] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_data = nullptr;
|
|
||||||
}
|
|
||||||
_length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chars)
|
|
||||||
StringUtils::ConvertANSI2UTF16(chars, _data, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Appends an array of characters to the string.
|
/// Appends an array of characters to the string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="chars">The array of characters to append. It does not need be null-terminated, and null characters are not treated specially.</param>
|
/// <param name="chars">The array of characters to append. It does not need be null-terminated, and null characters are not treated specially.</param>
|
||||||
/// <param name="count">The number of characters to append.</param>
|
/// <param name="count">The number of characters to append.</param>
|
||||||
void Append(const Char* chars, int32 count)
|
void Append(const Char* chars, int32 count);
|
||||||
{
|
|
||||||
if (count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto oldData = _data;
|
|
||||||
const auto oldLength = _length;
|
|
||||||
|
|
||||||
_length = oldLength + count;
|
|
||||||
_data = (Char*)Platform::Allocate((_length + 1) * sizeof(Char), 16);
|
|
||||||
|
|
||||||
Platform::MemoryCopy(_data, oldData, oldLength * sizeof(Char));
|
|
||||||
Platform::MemoryCopy(_data + oldLength, chars, count * sizeof(Char));
|
|
||||||
_data[_length] = 0;
|
|
||||||
|
|
||||||
Platform::Free(oldData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Appends an array of characters to the string.
|
/// Appends an array of characters to the string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="chars">The array of characters to append. It does not need be null-terminated, and null characters are not treated specially.</param>
|
/// <param name="chars">The array of characters to append. It does not need be null-terminated, and null characters are not treated specially.</param>
|
||||||
/// <param name="count">The number of characters to append.</param>
|
/// <param name="count">The number of characters to append.</param>
|
||||||
void Append(const char* chars, int32 count)
|
void Append(const char* chars, int32 count);
|
||||||
{
|
|
||||||
if (count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto oldData = _data;
|
|
||||||
const auto oldLength = _length;
|
|
||||||
|
|
||||||
_length = oldLength + count;
|
|
||||||
_data = (Char*)Platform::Allocate((_length + 1) * sizeof(Char), 16);
|
|
||||||
|
|
||||||
Platform::MemoryCopy(_data, oldData, oldLength * sizeof(Char));
|
|
||||||
StringUtils::ConvertANSI2UTF16(chars, _data + oldLength, count * sizeof(Char));
|
|
||||||
_data[_length] = 0;
|
|
||||||
|
|
||||||
Platform::Free(oldData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Appends the specified text to this string.
|
/// Appends the specified text to this string.
|
||||||
@@ -990,25 +920,13 @@ public:
|
|||||||
/// Converts all uppercase characters to lowercase.
|
/// Converts all uppercase characters to lowercase.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The lowercase string.</returns>
|
/// <returns>The lowercase string.</returns>
|
||||||
String ToLower() const
|
String ToLower() const;
|
||||||
{
|
|
||||||
String result(*this);
|
|
||||||
for (int32 i = 0; i < result.Length(); i++)
|
|
||||||
result[i] = StringUtils::ToLower(result[i]);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts all lowercase characters to uppercase.
|
/// Converts all lowercase characters to uppercase.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The uppercase string.</returns>
|
/// <returns>The uppercase string.</returns>
|
||||||
String ToUpper() const
|
String ToUpper() const;
|
||||||
{
|
|
||||||
String result(*this);
|
|
||||||
for (int32 i = 0; i < result.Length(); i++)
|
|
||||||
result[i] = StringUtils::ToUpper(result[i]);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the left most given number of characters.
|
/// Gets the left most given number of characters.
|
||||||
|
|||||||
Reference in New Issue
Block a user