summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/NewKit/KString.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-02 19:38:46 +0200
committerGitHub <noreply@github.com>2025-05-02 19:38:46 +0200
commit997be16e5ac9a68d54882ab69529815860d62955 (patch)
tree19d6129c2d776bb1edc5d4a7325e39ca176c3403 /dev/kernel/NewKit/KString.h
parent618104e74c195d7508a18450524f8ed7f9af8cc6 (diff)
parentb3b4b1ebdcd6adeac914869017c86d892b7a8ced (diff)
Merge pull request #28 from nekernel-org/dev
0.0.2
Diffstat (limited to 'dev/kernel/NewKit/KString.h')
-rw-r--r--dev/kernel/NewKit/KString.h152
1 files changed, 70 insertions, 82 deletions
diff --git a/dev/kernel/NewKit/KString.h b/dev/kernel/NewKit/KString.h
index 938096d5..08f783c0 100644
--- a/dev/kernel/NewKit/KString.h
+++ b/dev/kernel/NewKit/KString.h
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -9,86 +9,74 @@
#include <CompilerKit/CompilerKit.h>
#include <NewKit/Defines.h>
#include <NewKit/ErrorOr.h>
-#include <NewKit/Utils.h>
#include <NewKit/KernelPanic.h>
+#include <NewKit/Utils.h>
+
+#define kMinimumStringSize (8196U)
+
+namespace Kernel {
+/// @brief Kernel string class, not dynamic.
+class KString final {
+ public:
+ explicit KString() {
+ fDataSz = kMinimumStringSize;
+
+ fData = new Char[fDataSz];
+ MUST_PASS(fData);
+
+ rt_set_memory(fData, 0, fDataSz);
+ }
+
+ explicit KString(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;
+};
-#define cMinimumStringSize 8196
-
-namespace Kernel
-{
- /// @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(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 Kernel
+class KStringBuilder final {
+ public:
+ 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 Utf8Char* lhs, const Utf8Char* rhs);
+ static bool Equals(const WideChar* lhs, const WideChar* rhs);
+};
+} // namespace Kernel