String: is_empty + proper initialization
This commit is contained in:
parent
b6c35124d6
commit
ee60ab78b3
@ -30,6 +30,11 @@ class String
|
||||
return m_length;
|
||||
}
|
||||
|
||||
bool is_empty() const
|
||||
{
|
||||
return m_length == 0;
|
||||
}
|
||||
|
||||
const char& operator[](usize) const;
|
||||
|
||||
private:
|
||||
|
@ -5,6 +5,7 @@
|
||||
String::String()
|
||||
{
|
||||
m_inline = true;
|
||||
m_length = 0;
|
||||
memset(m_inline_storage, 0, sizeof(m_inline_storage));
|
||||
}
|
||||
|
||||
@ -22,14 +23,15 @@ String::String(String&& other)
|
||||
|
||||
String::String(char* c_str)
|
||||
{
|
||||
check(c_str);
|
||||
m_string = c_str;
|
||||
m_inline = false;
|
||||
|
||||
if (m_string) { m_length = strlen(m_string); }
|
||||
m_length = strlen(m_string);
|
||||
}
|
||||
|
||||
String::String(char* c_str, usize length)
|
||||
{
|
||||
check(c_str);
|
||||
m_string = c_str;
|
||||
m_inline = false;
|
||||
m_length = length;
|
||||
@ -61,10 +63,12 @@ const char& String::operator[](usize index) const
|
||||
|
||||
Result<String> String::from_string_literal(const char* str)
|
||||
{
|
||||
if (strlen(str) < sizeof(m_inline_storage))
|
||||
usize len = strlen(str);
|
||||
if (len < sizeof(m_inline_storage))
|
||||
{
|
||||
String result;
|
||||
result.m_inline = true;
|
||||
result.m_length = len;
|
||||
strncpy(result.m_inline_storage, str, sizeof(m_inline_storage));
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user