From 738833a0470ce93b7809ca4bdea253677f27fb57 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 21 Aug 2025 13:37:34 +0200 Subject: feat!: Breaking changes, reworked the KString API inside the ne_kernel. Signed-off-by: Amlal El Mahrouss --- dev/kernel/NeKit/KString.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'dev/kernel/NeKit/KString.h') diff --git a/dev/kernel/NeKit/KString.h b/dev/kernel/NeKit/KString.h index 16b09a78..35bdce97 100644 --- a/dev/kernel/NeKit/KString.h +++ b/dev/kernel/NeKit/KString.h @@ -16,10 +16,11 @@ namespace Kernel { /// @brief Kernel string class, not dynamic. -class KString final { +template +class BasicKString final { public: - explicit KString() { - fDataSz = kMinimumStringSize; + explicit BasicKString() { + fDataSz = MinSz; fData = new Char[fDataSz]; MUST_PASS(fData); @@ -27,7 +28,7 @@ class KString final { rt_set_memory(fData, 0, fDataSz); } - explicit KString(SizeT Sz) : fDataSz(Sz) { + explicit BasicKString(SizeT Sz) : fDataSz(Sz) { MUST_PASS(Sz > 1); fData = new Char[Sz]; @@ -36,14 +37,14 @@ class KString final { rt_set_memory(fData, 0, Sz); } - ~KString() { + ~BasicKString() { if (fData) { delete[] fData; fData = nullptr; } } - NE_COPY_DEFAULT(KString) + NE_COPY_DEFAULT(BasicKString) Char* Data(); const Char* CData() const; @@ -52,11 +53,13 @@ class KString final { bool operator==(const Char* rhs) const; bool operator!=(const Char* rhs) const; - bool operator==(const KString& rhs) const; - bool operator!=(const KString& rhs) const; + bool operator==(const BasicKString<>& rhs) const; + bool operator!=(const BasicKString<>& rhs) const; - KString& operator+=(const Char* rhs); - KString& operator+=(const KString& rhs); + BasicKString<>& operator+=(const Char* rhs); + BasicKString<>& operator+=(const BasicKString<>& rhs); + + operator const char*() { return fData; } operator bool() { return fData; } @@ -70,6 +73,8 @@ class KString final { friend class KStringBuilder; }; +using KString = BasicKString<>; + class KStringBuilder final { public: static ErrorOr Construct(const Char* data); @@ -77,6 +82,7 @@ class KStringBuilder final { static const Char* Format(const Char* fmt, const Char* from); static bool Equals(const Char* lhs, const Char* rhs); static bool Equals(const Utf8Char* lhs, const Utf8Char* rhs); - static bool Equals(const WideChar* lhs, const WideChar* rhs); }; } // namespace Kernel + +#include -- cgit v1.2.3