diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-26 22:26:48 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-26 22:27:09 +0100 |
| commit | eba8b7ddd0a455d9e49f32dcae712c5612c0093c (patch) | |
| tree | 749a3d34546d055507a920bce4ab10e8a9945719 /Private/NewKit/String.hpp | |
| parent | dd192787a70a973f2474720aea49af3f6ddabb7a (diff) | |
Kernel: Major repository refactor.
Rework the repo into Private and Public modules.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewKit/String.hpp')
| -rw-r--r-- | Private/NewKit/String.hpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/Private/NewKit/String.hpp b/Private/NewKit/String.hpp new file mode 100644 index 00000000..265b6de0 --- /dev/null +++ b/Private/NewKit/String.hpp @@ -0,0 +1,80 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include <NewKit/ErrorOr.hpp> +#include <NewKit/Defines.hpp> +#include <NewKit/Panic.hpp> + +namespace hCore +{ + class StringView final + { + public: + explicit StringView() = default; + + explicit StringView(Size Sz) : m_Sz(Sz) + { + MUST_PASS(Sz > 1); + m_Data = new Char[Sz]; + MUST_PASS(m_Data); + } + + ~StringView() + { + if (m_Data) + delete[] m_Data; + } + + StringView &operator=(const StringView &) = default; + StringView(const StringView &) = default; + + Char *Data(); + const Char *CData(); + Size Length() const; + + bool operator==(const Char *rhs) const; + bool operator!=(const Char *rhs) const; + + bool operator==(const StringView &rhs) const; + bool operator!=(const StringView &rhs) const; + + StringView &operator+=(const Char *rhs); + StringView &operator+=(const StringView &rhs); + + operator bool() + { + return m_Data; + } + + bool operator!() + { + return m_Data; + } + + private: + Char *m_Data{ nullptr }; + Size m_Sz{ 0 }; + Size m_Cur{ 0 }; + + friend class StringBuilder; + + }; + + struct StringBuilder final + { + static ErrorOr<StringView> Construct(const Char *data); + static const char* FromInt(const char *fmt, int n); + static const char* FromBool(const char *fmt, bool n); + static const char* Format(const char *fmt, const char* from); + static bool Equals(const char *lhs, const char *rhs); + + }; +} // namespace hCore |
