Core lib building

This commit is contained in:
jmsgrogan 2024-01-02 16:14:23 +00:00
parent 3ed195d7dd
commit 94fcc42aed
73 changed files with 625 additions and 661 deletions

View file

@ -1,5 +1,6 @@
#include "String.h"
#include "Char.h"
#include <stdio.h>
#include <stdarg.h>
@ -107,6 +108,22 @@ void String::eraseIf(erasePredicate func)
m_data[count] = '\0';
}
bool String::is_whitespace() const
{
if (empty())
{
return true;
}
for(size_t idx=0;idx<size();idx++)
{
if (!Char::is_space(m_data[idx]))
{
return false;
}
}
return true;
}
const Vector<char>& String::data() const
{
return m_data;
@ -117,6 +134,18 @@ bool String::empty() const
return m_data.empty() || m_data[0] == '\0';
}
void String::to_bytes(Vector<Byte>& bytes) const
{
if (m_data.empty())
{
return;
}
for(size_t idx=0; idx<m_data.size() - 1; idx++)
{
bytes.push_back(m_data[idx]);
}
}
void String::append(const Vector<Byte>& data)
{
if (data.empty())
@ -229,6 +258,34 @@ void String::reverse()
}
}
void String::split(Vector<String>& output, char delimiter) const
{
String working_string;
bool last_was_non_delimiter{ false };
for (size_t idx = 0; idx<size(); idx++)
{
const auto c = m_data[idx];
if (c == delimiter)
{
if (last_was_non_delimiter)
{
output.push_back(working_string);
working_string = "";
last_was_non_delimiter = false;
}
}
else
{
last_was_non_delimiter = true;
working_string += c;
}
}
if (!working_string.empty())
{
output.push_back(working_string);
}
}
String String::to_string(size_t input)
{
String conv;
@ -276,6 +333,12 @@ String& String::operator<<(size_t idx)
return *this;
}
String& String::operator<<(const int idx)
{
*this += to_string(idx);
return *this;
}
void String::push_back(char c)
{
if (m_data.empty())
@ -286,6 +349,25 @@ void String::push_back(char c)
m_data[m_data.size()-2] = c;
}
void String::to_lower()
{
if (empty())
{
return;
}
for(size_t idx=0; idx<size(); idx++)
{
m_data[idx] = Char::to_lower(m_data[idx]);
}
}
String String::to_lower(const String& input)
{
String ret = input;
ret.to_lower();
return ret;
}
String& String::operator+=(const String& str)
{
if (m_data.empty())