BAN: Implement more basic functionality

String has more features
StringView was implemented
Basic move semantics are now working
Added file for forward declarations
This commit is contained in:
Bananymous
2022-12-13 20:41:32 +02:00
parent 174daa3e02
commit cb6dee9d91
7 changed files with 284 additions and 12 deletions

View File

@@ -1,6 +1,8 @@
#pragma once
#include <BAN/Errors.h>
#include <BAN/Forward.h>
#include <BAN/Formatter.h>
namespace BAN
{
@@ -12,9 +14,15 @@ namespace BAN
public:
String();
String(const char*);
String(const String&);
String(String&&);
String(const StringView&);
String(const char*, size_type = -1);
~String();
String& operator=(const String&);
String& operator=(String&&);
ErrorOr<void> PushBack(char);
ErrorOr<void> Insert(char, size_type);
ErrorOr<void> Append(const char*);
@@ -23,12 +31,18 @@ namespace BAN
void PopBack();
void Remove(size_type);
void Clear();
char operator[](size_type) const;
char& operator[](size_type);
bool operator==(const String&) const;
ErrorOr<void> Resize(size_type, char = '\0');
ErrorOr<void> Reserve(size_type);
StringView SV() const;
bool Empty() const;
size_type Size() const;
size_type Capasity() const;
@@ -38,10 +52,24 @@ namespace BAN
private:
ErrorOr<void> EnsureCapasity(size_type);
ErrorOr<void> copy_impl(const char*, size_type);
void move_impl(String&&);
private:
char* m_data = nullptr;
size_type m_capasity = 0;
size_type m_size = 0;
};
}
}
namespace BAN::Formatter
{
template<void(*PUTC_LIKE)(char)> void print_argument_impl(const String& string, const ValueFormat&)
{
for (String::size_type i = 0; i < string.Size(); i++)
PUTC_LIKE(string[i]);
}
}