diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-23 19:13:48 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-23 19:15:17 +0100 |
| commit | a13e1c0911c0627184bc38f18c7fdda64447b3ad (patch) | |
| tree | 073a62c09bf216e85a3f310376640fa1805147f9 /dev/kernel/NewKit/KString.h | |
| parent | 149fa096eb306d03686b3b67e813cf1a78e08cd0 (diff) | |
meta(kernel): Reworked repository's filesystem structure.
Removing useless parts of the project too.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/kernel/NewKit/KString.h')
| -rw-r--r-- | dev/kernel/NewKit/KString.h | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/dev/kernel/NewKit/KString.h b/dev/kernel/NewKit/KString.h new file mode 100644 index 00000000..e7525a9c --- /dev/null +++ b/dev/kernel/NewKit/KString.h @@ -0,0 +1,94 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <CompilerKit/CompilerKit.h> +#include <NewKit/Defines.h> +#include <NewKit/ErrorOr.h> +#include <NewKit/Utils.h> +#include <NewKit/KernelPanic.h> + +#define cMinimumStringSize 8196 + +namespace NeOS +{ + /// @brief Kernel string class, not dynamic. + class KString final + { + public: + explicit KString() + { + fDataSz = cMinimumStringSize; + + fData = new Char[fDataSz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, fDataSz); + } + + explicit KString(const SizeT& Sz) + : fDataSz(Sz) + { + MUST_PASS(Sz > 1); + + fData = new Char[Sz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, Sz); + } + + ~KString() + { + if (fData) + { + delete[] fData; + fData = nullptr; + } + } + + NE_COPY_DEFAULT(KString); + + Char* Data(); + const Char* CData() const; + Size Length() const; + + bool operator==(const Char* rhs) const; + bool operator!=(const Char* rhs) const; + + bool operator==(const KString& rhs) const; + bool operator!=(const KString& rhs) const; + + KString& operator+=(const Char* rhs); + KString& operator+=(const KString& rhs); + + operator bool() + { + return fData; + } + + bool operator!() + { + return fData; + } + + private: + Char* fData{nullptr}; + Size fDataSz{0}; + Size fCur{0}; + + friend class KStringBuilder; + }; + + struct KStringBuilder final + { + static ErrorOr<KString> Construct(const Char* data); + 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); + static bool Equals(const WideChar* lhs, const WideChar* rhs); + }; +} // namespace NeOS |
