diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-02 20:11:24 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-02 20:11:24 +0200 |
| commit | 59578978610f6af245f571a011694a51d94dc530 (patch) | |
| tree | 3553807ef1c8095248520ee823c1426aef8738d8 /Kernel/NewKit/String.hxx | |
| parent | 9afcd1c001703c32964fed5906f36a2d913e91e9 (diff) | |
[unstable] [META] refactor whole project.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Kernel/NewKit/String.hxx')
| -rw-r--r-- | Kernel/NewKit/String.hxx | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/Kernel/NewKit/String.hxx b/Kernel/NewKit/String.hxx new file mode 100644 index 00000000..a4c88a74 --- /dev/null +++ b/Kernel/NewKit/String.hxx @@ -0,0 +1,87 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.hxx> +#include <NewKit/ErrorOr.hxx> +#include <NewKit/Utils.hxx> +#include <NewKit/KernelCheck.hxx> + +namespace Kernel +{ + class StringView final + { + public: + explicit StringView() + { + fSz = 4096; + + fData = new Char[fSz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, fSz); + } + + explicit StringView(Size Sz) + : fSz(Sz) + { + MUST_PASS(Sz > 1); + fData = new Char[Sz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, Sz); + } + + ~StringView() + { + if (fData) + delete[] fData; + } + + StringView& operator=(const StringView&) = default; + StringView(const StringView&) = default; + + Char* Data(); + const Char* CData() const; + 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 fData; + } + + bool operator!() + { + return fData; + } + + private: + Char* fData{nullptr}; + Size fSz{0}; + Size fCur{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 Kernel |
