BAN: Better ASSERT()

This commit is contained in:
Bananymous
2023-01-10 17:43:18 +02:00
parent 73cd08fa51
commit 1a65ea977d
5 changed files with 21 additions and 20 deletions

View File

@@ -67,7 +67,7 @@ namespace BAN
ErrorOr<void> String::Insert(char ch, size_type index)
{
assert(index <= m_size);
ASSERT(index <= m_size);
TRY(EnsureCapasity(m_size + 2));
memmove(m_data + index + 1, m_data + index, m_size - index);
m_data[index] = ch;
@@ -94,14 +94,14 @@ namespace BAN
void String::PopBack()
{
assert(m_size > 0);
ASSERT(m_size > 0);
m_data[m_size - 1] = '\0';
m_size--;
}
void String::Remove(size_type index)
{
assert(index < m_size);
ASSERT(index < m_size);
memmove(m_data + index, m_data + index + 1, m_size - index - 1);
m_data[m_size - 1] = '\0';
m_size--;
@@ -115,13 +115,13 @@ namespace BAN
char String::operator[](size_type index) const
{
assert(index < m_size);
ASSERT(index < m_size);
return m_data[index];
}
char& String::operator[](size_type index)
{
assert(index < m_size);
ASSERT(index < m_size);
return m_data[index];
}

View File

@@ -25,7 +25,7 @@ namespace BAN
char StringView::operator[](size_type index) const
{
assert(index < m_size);
ASSERT(index < m_size);
return m_data[index];
}
@@ -52,10 +52,10 @@ namespace BAN
StringView StringView::Substring(size_type index, size_type len) const
{
assert(index <= m_size);
ASSERT(index <= m_size);
if (len == size_type(-1))
len = m_size - index;
assert(len <= m_size - index); // weird order to avoid overflow
ASSERT(len <= m_size - index); // weird order to avoid overflow
StringView result;
result.m_data = m_data + index;
result.m_size = len;