diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-18 14:13:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-18 14:13:02 +0100 |
| commit | c9fd682f3662e0eec09de49a36a4ea199656da34 (patch) | |
| tree | f6e0c4c52724cd2af4cc6f469506b5552db13c3d /dev/lib/core/chunk_string.hpp | |
| parent | 4fd646501b75cb1d94a6e17d2387372d72ce797b (diff) | |
| parent | 54940e80e0a259f748d483291e0e7aef7dd98353 (diff) | |
Merge pull request #11 from amlel-el-mahrouss/develop
develop->stable: fixes and improvements.
Diffstat (limited to 'dev/lib/core/chunk_string.hpp')
| -rw-r--r-- | dev/lib/core/chunk_string.hpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/dev/lib/core/chunk_string.hpp b/dev/lib/core/chunk_string.hpp index 4fe5cc2..7e5360c 100644 --- a/dev/lib/core/chunk_string.hpp +++ b/dev/lib/core/chunk_string.hpp @@ -9,6 +9,7 @@ #define OCL_UTILITY_CHUNK_STRING_HPP #include <lib/core/includes.hpp> +#include <lib/io/print.hpp> namespace ocl { @@ -45,6 +46,19 @@ namespace ocl basic_chunk_string(const basic_chunk_string&) = delete; public: + /// @brief Append a std::basic_string to the chunk string. + basic_chunk_string& operator+=(const char_type* in) + { + if (in == nullptr || bad_) + return *this; + + const auto& sz = std::strlen(in); + + this->operator+=(std::basic_string<char_type>(in, sz)); + + return *this; + } + basic_chunk_string& operator+=(const std::basic_string<char_type>& in) { if (in.empty() || bad_) @@ -75,14 +89,18 @@ namespace ocl return *this; } + /// @brief Convert to basic_string or return from cache. std::basic_string<char_type> str() const noexcept { static std::basic_string<char_type> ret; + const auto& sz = ret.size(); - if (ret.size() > 0) + if (chunk_total_ > sz) ret.clear(); + else + return ret; - ret += packed_chunks_; + ret = packed_chunks_; return ret; } |
