From 83d870e58457a1d335a1d9b9966a6a1887cc297b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 24 Nov 2025 03:02:43 +0100 Subject: feat! breaking changes on kernel sources. Signed-off-by: Amlal El Mahrouss --- src/kernel/NeKit/KString.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/kernel/NeKit/KString.h (limited to 'src/kernel/NeKit/KString.h') diff --git a/src/kernel/NeKit/KString.h b/src/kernel/NeKit/KString.h new file mode 100644 index 00000000..fa83fed4 --- /dev/null +++ b/src/kernel/NeKit/KString.h @@ -0,0 +1,92 @@ +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace Kernel { +inline auto kMinimumStringSize = 8196; + +/// @brief Kernel string class, not dynamic. +template +class KBasicString final { + public: + explicit KBasicString() { + fDataSz = kMinimumStringSize; + + fData = new CharKind[fDataSz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, fDataSz); + } + + explicit KBasicString(SizeT Sz) : fDataSz(Sz) { + MUST_PASS(Sz > 1); + + fData = new CharKind[Sz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, Sz); + } + + ~KBasicString() { + if (fData) { + delete[] fData; + fData = nullptr; + } + } + + NE_COPY_DEFAULT(KBasicString) + + CharKind* Data(); + const CharKind* CData() const; + Size Length() const; + + bool operator==(const CharKind* rhs) const; + bool operator!=(const CharKind* rhs) const; + + bool operator==(const KBasicString& rhs) const; + bool operator!=(const KBasicString& rhs) const; + + KBasicString& operator+=(const CharKind* rhs); + KBasicString& operator+=(const KBasicString& rhs); + + operator const char*() { return fData; } + + operator bool() { return fData; } + + bool operator!() { return fData; } + + private: + CharKind* fData{nullptr}; + Size fDataSz{0}; + Size fCur{0}; + + friend class KStringBuilder; +}; + +using KString = KBasicString<>; +using KStringOr = ErrorOr; + +class KStringBuilder final { + public: + template + static ErrorOr> Construct(const CharKind* data); + template + static const CharKind* FromBool(const CharKind* fmt, bool n); + template + static const CharKind* Format(const CharKind* fmt, const CharKind* from); + template + static bool Equals(const CharKind* lhs, const CharKind* rhs); +}; +} // namespace Kernel + +#include -- cgit v1.2.3