From f3d931aa7cfaf96baef8383b59a8938779541ee7 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Thu, 15 Aug 2024 18:35:34 +0200 Subject: [IMP] Moved source code into dev/ folder. Signed-off-by: Amlal EL Mahrouss --- dev/Kernel/NewKit/String.hxx | 87 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 dev/Kernel/NewKit/String.hxx (limited to 'dev/Kernel/NewKit/String.hxx') diff --git a/dev/Kernel/NewKit/String.hxx b/dev/Kernel/NewKit/String.hxx new file mode 100644 index 00000000..2f3d2096 --- /dev/null +++ b/dev/Kernel/NewKit/String.hxx @@ -0,0 +1,87 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +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 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 -- cgit v1.2.3