From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/Plugins/Library/ml_local/MLString.h | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Src/Plugins/Library/ml_local/MLString.h (limited to 'Src/Plugins/Library/ml_local/MLString.h') diff --git a/Src/Plugins/Library/ml_local/MLString.h b/Src/Plugins/Library/ml_local/MLString.h new file mode 100644 index 00000000..ddf98e58 --- /dev/null +++ b/Src/Plugins/Library/ml_local/MLString.h @@ -0,0 +1,54 @@ +#ifndef NULLOSFT_MLSTRING_HEADER +#define NULLOSFT_MLSTRING_HEADER + +#include + +class MLString +{ +public: + MLString(void); + ~MLString(void); + MLString(const wchar_t* string); + MLString(unsigned int cchBuffer); +protected: + MLString(const MLString ©); + + +public: + HRESULT Set(const wchar_t* string, unsigned int cchLength); + HRESULT Append(const wchar_t* string, unsigned int cchLength); + const wchar_t* Get(void) { return (cchLen) ? buffer : NULL; } + void Clear(void) { cchLen = 0; } + unsigned int GetLength(void) { return cchLen; } + HRESULT Format(const wchar_t *format, ...); + HRESULT CopyTo(MLString *destination); + + HRESULT Set(const wchar_t* string) { return Set(string, lstrlenW(string)); } + HRESULT Append(const wchar_t* string) { return Append(string, lstrlenW(string)); } + + // buffer + HRESULT Allocate(unsigned int cchNewSize); + void Compact(void); + wchar_t* GetBuffer(void) { return buffer; } + unsigned int GetBufferLength(void) { return allocated; } + void UpdateBuffer(void) { cchLen = lstrlenW(buffer); } + + operator const wchar_t *() { return buffer; } + operator wchar_t *() { return buffer; } + wchar_t& operator [](unsigned int index) { return buffer[index]; } + MLString& operator = (const wchar_t *source) { (source) ? Set(source, lstrlenW(source)) : Clear(); return *this;} + MLString& operator + (const wchar_t *source) { if (source) Append(source, lstrlenW(source)); return *this;} + MLString& operator += (const wchar_t *source) { if (source) Append(source, lstrlenW(source)); return *this;} + MLString& operator = (MLString *source) { (source) ? source->CopyTo(this) : Clear(); return *this;} + MLString& operator + (MLString *source) { if (source) Append(source->GetBuffer(), source->GetLength()); return *this;} + MLString& operator += (MLString *source) { if (source) Append(source->GetBuffer(), source->GetLength()); return *this;} + +protected: + wchar_t *buffer; + unsigned int cchLen; + unsigned int allocated; + + static void *heap; +}; + +#endif // NULLOSFT_STRING_HEADER \ No newline at end of file -- cgit