From 6e3371649f2da291dc449cd040bdb3661e67c160 Mon Sep 17 00:00:00 2001 From: vczh Date: Tue, 27 Feb 2024 00:46:38 -0800 Subject: [PATCH] Update import --- Import/Vlpp.cpp | 10 +- Import/Vlpp.h | 85 +++-- Import/VlppOS.cpp | 323 +++++++++++++++---- Import/VlppOS.h | 217 ++++++++----- Tutorial/GacUI_HelloWorlds/UIRes/Xml.bin.x64 | Bin 25176 -> 25176 bytes Tutorial/GacUI_HelloWorlds/UIRes/Xml.bin.x86 | Bin 25176 -> 25176 bytes 6 files changed, 437 insertions(+), 198 deletions(-) diff --git a/Import/Vlpp.cpp b/Import/Vlpp.cpp index 6b94eee8..1297de00 100644 --- a/Import/Vlpp.cpp +++ b/Import/Vlpp.cpp @@ -660,7 +660,7 @@ String Conversions (buffer walkthrough) if (d == nullptr) { while (reader.Read()) size++; - return reader.HasIllegalChar() ? -1 : size + 1; + return size + 1; } else { @@ -673,7 +673,7 @@ String Conversions (buffer walkthrough) chars--; if (!c) break; } - return reader.HasIllegalChar() ? -1 : size; + return size; } } @@ -926,6 +926,12 @@ Licensed under https://github.com/vczh-libraries/License namespace vl { + template class ObjectString; + template class ObjectString; + template class ObjectString; + template class ObjectString; + template class ObjectString; + #if defined VCZH_GCC void _itoa_s(vint32_t value, char* buffer, size_t size, vint radix) { diff --git a/Import/Vlpp.h b/Import/Vlpp.h index a2757344..cfcc5e56 100644 --- a/Import/Vlpp.h +++ b/Import/Vlpp.h @@ -7090,6 +7090,12 @@ namespace vl template const T ObjectString::zero=0; + extern template class ObjectString; + extern template class ObjectString; + extern template class ObjectString; + extern template class ObjectString; + extern template class ObjectString; + /// Ansi string in local code page. typedef ObjectString AString; /// Unicode string, UTF-16 on Windows, UTF-32 on Linux and macOS. @@ -8690,8 +8696,17 @@ UtfConversion UtfReaderConsumer ***********************************************************************/ - template - class UtfReaderConsumer : public Object + template + class UtfEmptyConsumerRedirection : public Object + { + public: + UtfEmptyConsumerRedirection(TInternalConsumer&) + { + } + }; + + template class TConsumerRedirection> + class UtfReaderConsumer : public TConsumerRedirection { protected: TReader internalReader; @@ -8704,13 +8719,9 @@ UtfReaderConsumer template UtfReaderConsumer(TArguments&& ...arguments) : internalReader(std::forward(arguments)...) + , TConsumerRedirection(internalReader) { } - - bool HasIllegalChar() const - { - return internalReader.HasIllegalChar(); - } }; /*********************************************************************** @@ -8727,9 +8738,10 @@ UtfFrom32ReaderBase UtfCharCluster sourceCluster = { 0,0 }; vint readCounter = -1; - bool error = false; public: + using ConsumerType = TConsumer; + template UtfFrom32ReaderBase(TArguments&& ...arguments) : TConsumer(std::forward(arguments)...) @@ -8772,11 +8784,6 @@ UtfFrom32ReaderBase { return sourceCluster; } - - bool HasIllegalChar() const - { - return error || TConsumer::HasIllegalChar(); - } }; /*********************************************************************** @@ -8792,9 +8799,10 @@ UtfTo32ReaderBase UtfCharCluster sourceCluster = { 0,0 }; vint readCounter = -1; - bool error = false; public: + using ConsumerType = TConsumer; + template UtfTo32ReaderBase(TArguments&& ...arguments) : TConsumer(std::forward(arguments)...) @@ -8852,11 +8860,6 @@ UtfTo32ReaderBase { return sourceCluster; } - - bool HasIllegalChar() const - { - return error || TConsumer::HasIllegalChar(); - } }; /*********************************************************************** @@ -8866,10 +8869,12 @@ Utf32DirectReaderBase template class Utf32DirectReaderBase : public TConsumer { - UtfCharCluster sourceCluster = { -1,1 }; + vint readCounter = -1; bool ended = false; public: + using ConsumerType = TConsumer; + template Utf32DirectReaderBase(TArguments&& ...arguments) : TConsumer(std::forward(arguments)...) @@ -8882,24 +8887,22 @@ Utf32DirectReaderBase static_assert(sizeof(dest) == sizeof(char32_t)); if (dest || !ended) { - sourceCluster.index += 1; - if (!dest) - { - ended = true; - sourceCluster.size = 0; - } + readCounter++; } + ended = !dest; return static_cast(dest); } vint ReadingIndex() const { - return sourceCluster.index; + return readCounter; } UtfCharCluster SourceCluster() const { - return sourceCluster; + if (readCounter == -1) return { 0,0 }; + if (ended) return { readCounter,0 }; + return { readCounter,1 }; } }; @@ -8910,10 +8913,10 @@ UtfToUtfReaderBase template struct UtfToUtfReaderSelector { - template - class Reader : public UtfFrom32ReaderBase>> + template class TConsumerRedirection> + class Reader : public UtfFrom32ReaderBase, TConsumerRedirection>> { - using TBase = UtfFrom32ReaderBase>>; + using TBase = UtfFrom32ReaderBase, TConsumerRedirection>>; public: template Reader(TArguments&& ...arguments) @@ -8931,14 +8934,14 @@ UtfToUtfReaderBase template struct UtfToUtfReaderSelector { - template + template class> using Reader = UtfFrom32ReaderBase; }; template struct UtfToUtfReaderSelector { - template + template class> using Reader = UtfTo32ReaderBase; }; @@ -8946,7 +8949,7 @@ UtfToUtfReaderBase template<>\ struct UtfToUtfReaderSelector\ {\ - template\ + template class>\ using Reader = Utf32DirectReaderBase;\ }\ @@ -8960,8 +8963,8 @@ UtfToUtfReaderBase #undef DEFINE_UTF32_DIRECT_READER - template - using UtfToUtfReaderBase = typename UtfToUtfReaderSelector::template Reader; + template class TConsumerRedirection = UtfEmptyConsumerRedirection> + using UtfToUtfReaderBase = typename UtfToUtfReaderSelector::template Reader; /*********************************************************************** UtfStringConsumer @@ -8986,11 +8989,6 @@ UtfStringConsumer , consuming(_starting) { } - - bool HasIllegalChar() const - { - return false; - } }; template @@ -9035,11 +9033,6 @@ UtfStringRangeConsumer , consuming(_starting) { } - - bool HasIllegalChar() const - { - return false; - } }; template diff --git a/Import/VlppOS.cpp b/Import/VlppOS.cpp index 52417ba3..1970f3f2 100644 --- a/Import/VlppOS.cpp +++ b/Import/VlppOS.cpp @@ -591,6 +591,265 @@ ThreadLocalStorage } +/*********************************************************************** +.\ENCODING\BASE64ENCODING.CPP +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + + +namespace vl +{ + namespace stream + { + const char8_t Utf8Base64Codes[] = u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +/*********************************************************************** +Utf8Base64Encoder +***********************************************************************/ + + void Utf8Base64Encoder::WriteBytesToCharArray(uint8_t* fromBytes, char8_t(&toChars)[Base64CycleChars], vint bytes) + { + switch (bytes) + { + case 1: + { + toChars[0] = Utf8Base64Codes[fromBytes[0] >> 2]; + toChars[1] = Utf8Base64Codes[(fromBytes[0] % (1 << 2)) << 4]; + toChars[2] = u8'='; + toChars[3] = u8'='; + } + break; + case 2: + { + toChars[0] = Utf8Base64Codes[fromBytes[0] >> 2]; + toChars[1] = Utf8Base64Codes[((fromBytes[0] % (1 << 2)) << 4) | (fromBytes[1] >> 4)]; + toChars[2] = Utf8Base64Codes[(fromBytes[1] % (1 << 4)) << 2]; + toChars[3] = u8'='; + } + break; + case 3: + { + toChars[0] = Utf8Base64Codes[fromBytes[0] >> 2]; + toChars[1] = Utf8Base64Codes[((fromBytes[0] % (1 << 2)) << 4) | (fromBytes[1] >> 4)]; + toChars[2] = Utf8Base64Codes[((fromBytes[1] % (1 << 4)) << 2) | (fromBytes[2] >> 6)]; + toChars[3] = Utf8Base64Codes[fromBytes[2] % (1 << 6)]; + } + break; + default: + CHECK_FAIL(L"vl::stream::Utf8Base64Encoder::WriteBytesToCharArray(uint8_t*, char8_t(&)[Base64CycleChars], vint)#Parameter bytes should be 1, 2 or 3."); + } + } + + bool Utf8Base64Encoder::WriteCycle(uint8_t*& reading, vint& _size) + { + if (_size <= 0) return false; + vint bytes = _size < Base64CycleBytes ? _size : Base64CycleBytes; + + char8_t chars[Base64CycleChars]; + WriteBytesToCharArray(reading, chars, bytes); + vint writtenBytes = stream->Write(chars, Base64CycleChars); + CHECK_ERROR(writtenBytes == Base64CycleChars, L"vl::stream::Utf8Base64Encoder::WriteCycle(uint8_t*&, vint&)#The underlying stream failed to accept enough base64 characters."); + + reading += bytes; + _size -= bytes; + return true; + } + + bool Utf8Base64Encoder::WriteCache(uint8_t*& reading, vint& _size) + { + if (cacheSize > 0 || _size < Base64CycleBytes) + { + vint copiedBytes = Base64CycleBytes - cacheSize; + if (copiedBytes > _size) copiedBytes = _size; + if (copiedBytes > 0) + { + memcpy(cache + cacheSize, reading, copiedBytes); + reading += copiedBytes; + _size -= copiedBytes; + cacheSize += copiedBytes; + } + } + + if (cacheSize == 0) return _size > 0; + if (cacheSize == Base64CycleBytes) + { + uint8_t* cacheReading = cache; + return WriteCycle(cacheReading, cacheSize); + } + return true; + } + + vint Utf8Base64Encoder::Write(void* _buffer, vint _size) + { + uint8_t* reading = (uint8_t*)_buffer; + + // flush cache if any + if (!WriteCache(reading, _size)) goto FINISHED_WRITING; + + // run Base64 encoding + while (_size >= Base64CycleBytes) + { + if (!WriteCycle(reading, _size)) goto FINISHED_WRITING; + } + + // run the last Base64 encoding cycle and wrote a postfix to cache + WriteCache(reading, _size); + + FINISHED_WRITING: + return reading - (uint8_t*)_buffer; + } + + void Utf8Base64Encoder::Close() + { + if (cacheSize > 0) + { + char8_t chars[Base64CycleChars]; + WriteBytesToCharArray(cache, chars, cacheSize); + vint writtenBytes = stream->Write(chars, Base64CycleChars); + CHECK_ERROR(writtenBytes == Base64CycleChars, L"vl::stream::Utf8Base64Encoder::Close()#The underlying stream failed to accept enough base64 characters."); + + cacheSize = 0; + } + EncoderBase::Close(); + } + +/*********************************************************************** +Utf8Base64Decoder +***********************************************************************/ + + vint Utf8Base64Decoder::ReadBytesFromCharArray(char8_t(&fromChars)[Base64CycleChars], uint8_t* toBytes) + { + uint8_t nums[Base64CycleChars]; + for (vint i = 0; i < Base64CycleChars; i++) + { + char8_t c = fromChars[i]; + if (u8'A' <= c && c <= u8'Z') nums[i] = c - u8'A'; + else if (u8'a' <= c && c <= u8'z') nums[i] = c - u8'a' + 26; + else if (u8'0' <= c && c <= u8'9') nums[i] = c - u8'0' + 52; + else switch (c) + { + case '+':nums[i] = 62; break; + case '/':nums[i] = 63; break; + case '=':nums[i] = 0; break; + default: + CHECK_FAIL(L"vl::stream::Utf8Base64Decoder::ReadBytesFromCharArray(char(&)[Base64CycleChars], uint8_t*)#Illegal Base64 character."); + } + } + + toBytes[0] = (nums[0] << 2) | (nums[1] >> 4); + if (fromChars[2] == u8'=') return 1; + toBytes[1] = ((nums[1] % (1 << 4)) << 4) | (nums[2] >> 2); + if (fromChars[3] == u8'=') return 2; + toBytes[2] = ((nums[2] % (1 << 2)) << 6) | nums[3]; + return 3; + } + + vint Utf8Base64Decoder::ReadCycle(uint8_t*& writing, vint& _size) + { + char8_t chars[Base64CycleChars]; + vint readChars = stream->Read((void*)chars, Base64CycleChars); + if (readChars == 0) return 0; + CHECK_ERROR(readChars == Base64CycleChars, L"vl::stream::Utf8Base64Decoder::ReadCycle(uint8_t*&, vint&)#The underlying stream failed to provide enough base64 characters."); + + vint readBytes = ReadBytesFromCharArray(chars, writing); + writing += readBytes; + _size -= readBytes; + return readBytes; + } + + void Utf8Base64Decoder::ReadCache(uint8_t*& writing, vint& _size) + { + if (cacheSize > 0) + { + vint copiedBytes = cacheSize; + if (copiedBytes > _size) copiedBytes = _size; + if (copiedBytes > 0) + { + memcpy(writing, cache, copiedBytes); + writing += copiedBytes; + _size -= copiedBytes; + cacheSize -= copiedBytes; + if (cacheSize > 0) + { + memmove(cache, cache + copiedBytes, cacheSize); + } + } + } + } + + vint Utf8Base64Decoder::Read(void* _buffer, vint _size) + { + uint8_t* writing = (uint8_t*)_buffer; + + // write cache to buffer if any + ReadCache(writing, _size); + + // run Base64 decoding + while (_size >= Base64CycleBytes) + { + if (ReadCycle(writing, _size) == 0) goto FINISHED_READING; + } + + // run the last Base64 decoding cycle and write a prefix to buffer + if (_size > 0) + { + uint8_t* cacheWriting = cache; + vint temp = 0; + if ((cacheSize = ReadCycle(cacheWriting, temp)) == 0) goto FINISHED_READING; + ReadCache(writing, _size); + } + FINISHED_READING: + return writing - (uint8_t*)_buffer; + } + } +} + + +/*********************************************************************** +.\ENCODING\ENCODING.CPP +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + + +namespace vl +{ + namespace stream + { +/*********************************************************************** +EncoderBase +***********************************************************************/ + + void EncoderBase::Setup(IStream* _stream) + { + stream = _stream; + } + + void EncoderBase::Close() + { + } + +/*********************************************************************** +DecoderBase +***********************************************************************/ + + void DecoderBase::Setup(IStream* _stream) + { + stream = _stream; + } + + void DecoderBase::Close() + { + } + } +} + + /*********************************************************************** .\ENCODING\LZWENCODING.CPP ***********************************************************************/ @@ -745,11 +1004,6 @@ LzwEncoder { } - void LzwEncoder::Setup(IStream* _stream) - { - stream = _stream; - } - void LzwEncoder::Close() { if (prefix != root) @@ -765,6 +1019,7 @@ LzwEncoder WriteNumber(eofIndex, indexBits); } Flush(); + EncoderBase::Close(); } vint LzwEncoder::Write(void* _buffer, vint _size) @@ -890,15 +1145,6 @@ LzwDecoder { } - void LzwDecoder::Setup(IStream* _stream) - { - stream = _stream; - } - - void LzwDecoder::Close() - { - } - vint LzwDecoder::Read(void* _buffer, vint _size) { vint written = 0; @@ -1273,48 +1519,6 @@ BomDecoder } -/*********************************************************************** -.\ENCODING\CHARFORMAT\CHARENCODINGBASE.CPP -***********************************************************************/ -/*********************************************************************** -Author: Zihan Chen (vczh) -Licensed under https://github.com/vczh-libraries/License -***********************************************************************/ - - -namespace vl -{ - namespace stream - { -/*********************************************************************** -CharEncoderBase -***********************************************************************/ - - void CharEncoderBase::Setup(IStream* _stream) - { - stream = _stream; - } - - void CharEncoderBase::Close() - { - } - -/*********************************************************************** -CharDecoderBase -***********************************************************************/ - - void CharDecoderBase::Setup(IStream* _stream) - { - stream = _stream; - } - - void CharDecoderBase::Close() - { - } - } -} - - /*********************************************************************** .\ENCODING\CHARFORMAT\CHARFORMAT.CPP ***********************************************************************/ @@ -1743,11 +1947,6 @@ UtfGeneralEncoder CHECK_FAIL(L"UtfGeneralEncoder::Write(void*, vint)#Failed to write a complete string."); } } - if (reader.HasIllegalChar()) - { - Close(); - CHECK_FAIL(L"UtfGeneralEncoder::Write(void*, vint)#Failed to write a complete string."); - } availableChars = reader.SourceCluster().index; availableBytes = availableChars * sizeof(TExpect); } @@ -1771,7 +1970,7 @@ UtfGeneralDecoder template void UtfGeneralDecoder::Setup(IStream* _stream) { - CharDecoderBase::Setup(_stream); + DecoderBase::Setup(_stream); reader.Setup(_stream); } diff --git a/Import/VlppOS.h b/Import/VlppOS.h index 62c8f922..db39d053 100644 --- a/Import/VlppOS.h +++ b/Import/VlppOS.h @@ -1254,14 +1254,18 @@ Author: Zihan Chen (vczh) Licensed under https://github.com/vczh-libraries/License ***********************************************************************/ -#ifndef VCZH_STREAM_ENCODING -#define VCZH_STREAM_ENCODING +#ifndef VCZH_STREAM_ENCODING_ENCODING +#define VCZH_STREAM_ENCODING_ENCODING namespace vl { namespace stream { +/*********************************************************************** +IEncoder and IDecoder +***********************************************************************/ + /// Encoder interface. This interface defines a writable transformation from one stream to another stream. You can create a [T:vl.stream.EncoderStream] after you have an encoder. class IEncoder : public Interface { @@ -1303,11 +1307,98 @@ namespace vl /// The expected size of the content in bytes in "_buffer" to receive. virtual vint Read(void* _buffer, vint _size)=0; }; + +/*********************************************************************** +EncoderBase and DecoderBase +***********************************************************************/ + + /// Basic implementation of IEncoder. + class EncoderBase : public Object, public IEncoder + { + protected: + IStream* stream = nullptr; + + public: + + void Setup(IStream* _stream) override; + void Close() override; + }; + + /// Basic implementation of IDecoder. + class DecoderBase : public Object, public IDecoder + { + protected: + IStream* stream = nullptr; + + public: + + void Setup(IStream* _stream) override; + void Close() override; + }; } } #endif +/*********************************************************************** +.\ENCODING\BASE64ENCODING.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_STREAM_ENCODING_BASE64ENCODING +#define VCZH_STREAM_ENCODING_BASE64ENCODING + + +namespace vl +{ + namespace stream + { + constexpr const vint Base64CycleBytes = 3; + constexpr const vint Base64CycleChars = 4; + +/*********************************************************************** +Utf8Base64Encoder +***********************************************************************/ + + class Utf8Base64Encoder : public EncoderBase + { + protected: + uint8_t cache[Base64CycleBytes]; + vint cacheSize = 0; + + void WriteBytesToCharArray(uint8_t* fromBytes, char8_t(&toChars)[Base64CycleChars], vint bytes); + bool WriteCycle(uint8_t*& reading, vint& _size); + bool WriteCache(uint8_t*& reading, vint& _size); + public: + vint Write(void* _buffer, vint _size) override; + void Close() override; + }; + +/*********************************************************************** +Utf8Base64Decoder +***********************************************************************/ + + class Utf8Base64Decoder : public DecoderBase + { + protected: + uint8_t cache[Base64CycleBytes]; + vint cacheSize = 0; + + vint ReadBytesFromCharArray(char8_t(&fromChars)[Base64CycleChars], uint8_t* toBytes); + vint ReadCycle(uint8_t*& writing, vint& _size); + void ReadCache(uint8_t*& writing, vint& _size); + public: + vint Read(void* _buffer, vint _size) override; + }; + } +} + +#endif + + /*********************************************************************** .\ENCODING\CHARFORMAT\BOMENCODING.H ***********************************************************************/ @@ -1407,55 +1498,6 @@ Bom #endif -/*********************************************************************** -.\ENCODING\CHARFORMAT\CHARENCODINGBASE.H -***********************************************************************/ -/*********************************************************************** -Author: Zihan Chen (vczh) -Licensed under https://github.com/vczh-libraries/License -***********************************************************************/ - -#ifndef VCZH_STREAM_ENCODING_CHARFORMAT_CHARENCODINGBASE -#define VCZH_STREAM_ENCODING_CHARFORMAT_CHARENCODINGBASE - - -namespace vl -{ - namespace stream - { -/*********************************************************************** -CharEncoderBase and CharDecoderBase -***********************************************************************/ - - /// Base type of all character encoder. - class CharEncoderBase : public Object, public IEncoder - { - protected: - IStream* stream = nullptr; - - public: - - void Setup(IStream* _stream) override; - void Close() override; - }; - - /// Base type of all character decoder. - class CharDecoderBase : public Object, public IDecoder - { - protected: - IStream* stream = nullptr; - - public: - - void Setup(IStream* _stream) override; - void Close() override; - }; - } -} - -#endif - - /*********************************************************************** .\ENCODING\CHARFORMAT\MBCSENCODING.H ***********************************************************************/ @@ -1477,7 +1519,7 @@ MbcsEncoder ***********************************************************************/ /// Encoder to write text in the local code page. - class MbcsEncoder : public CharEncoderBase + class MbcsEncoder : public EncoderBase { protected: vuint8_t cacheBuffer[sizeof(char32_t)]; @@ -1494,7 +1536,7 @@ MbcsDecoder ***********************************************************************/ /// Decoder to read text in the local code page. - class MbcsDecoder : public CharDecoderBase + class MbcsDecoder : public DecoderBase { protected: vuint8_t cacheBuffer[sizeof(wchar_t)]; @@ -1557,30 +1599,35 @@ UtfStreamConsumer } }; + template + class UtfStreamConsumerApiRedirection : public Object + { + private: + T& internalConsumer; + + public: + UtfStreamConsumerApiRedirection(T& _internalConsumer) + : internalConsumer(_internalConsumer) + { + } + + void Setup(IStream* _stream) + { + internalConsumer.Setup(_stream); + } + + encoding::UtfCharCluster SourceCluster() const + { + return internalConsumer.SourceCluster(); + } + }; + /*********************************************************************** UtfStreamToStreamReader ***********************************************************************/ template - class UtfStreamToStreamReader : public encoding::UtfToUtfReaderBase> - { - public: - void Setup(IStream* _stream) - { - this->internalReader.Setup(_stream); - } - - encoding::UtfCharCluster SourceCluster() const - { - return this->internalReader.SourceCluster(); - } - }; - - template - requires(std::is_same_v || std::is_same_v) - class UtfStreamToStreamReader : public encoding::UtfToUtfReaderBase> - { - }; + using UtfStreamToStreamReader = encoding::UtfToUtfReaderBase, UtfStreamConsumerApiRedirection>; /*********************************************************************** Unicode General @@ -1599,7 +1646,7 @@ Unicode General }; template - class UtfGeneralEncoder : public CharEncoderBase + class UtfGeneralEncoder : public EncoderBase { using TStringRangeReader = encoding::UtfStringRangeToStringRangeReader; protected: @@ -1612,7 +1659,7 @@ Unicode General }; template - class UtfGeneralDecoder : public CharDecoderBase + class UtfGeneralDecoder : public DecoderBase { using TStreamReader = UtfStreamToStreamReader; protected: @@ -1631,14 +1678,14 @@ Unicode General (without conversion) ***********************************************************************/ template - class UtfGeneralEncoder : public CharEncoderBase + class UtfGeneralEncoder : public EncoderBase { public: vint Write(void* _buffer, vint _size) override; }; template - class UtfGeneralDecoder : public CharDecoderBase + class UtfGeneralDecoder : public DecoderBase { public: vint Read(void* _buffer, vint _size) override; @@ -1807,8 +1854,8 @@ Author: Zihan Chen (vczh) Licensed under https://github.com/vczh-libraries/License ***********************************************************************/ -#ifndef VCZH_STREAM_COMPRESSIONSTREAM -#define VCZH_STREAM_COMPRESSIONSTREAM +#ifndef VCZH_STREAM_ENCODING_LZWENCODING +#define VCZH_STREAM_ENCODING_LZWENCODING namespace vl @@ -1861,11 +1908,9 @@ Compression /// You are not recommended to compress data more than 1 mega bytes at once using the encoder directly. /// and is recommended. /// - class LzwEncoder : public LzwBase, public IEncoder + class LzwEncoder : public LzwBase, public EncoderBase { protected: - IStream* stream = 0; - vuint8_t buffer[lzw::BufferSize]; vint bufferUsedBits = 0; lzw::Code* prefix; @@ -1887,7 +1932,6 @@ Compression LzwEncoder(bool (&existingBytes)[256]); ~LzwEncoder(); - void Setup(IStream* _stream)override; void Close()override; vint Write(void* _buffer, vint _size)override; }; @@ -1897,10 +1941,9 @@ Compression /// You are not recommended to compress data more than 1 mega bytes at once using the encoder directly. /// and is recommended. /// - class LzwDecoder :public LzwBase, public IDecoder + class LzwDecoder :public LzwBase, public DecoderBase { protected: - IStream* stream = 0; collections::List dictionary; lzw::Code* lastCode = 0; @@ -1930,8 +1973,6 @@ Compression LzwDecoder(bool (&existingBytes)[256]); ~LzwDecoder(); - void Setup(IStream* _stream)override; - void Close()override; vint Read(void* _buffer, vint _size)override; }; @@ -2693,7 +2734,7 @@ Text Related /// The character type. /// /// To specify the encoding in the input stream, - /// you are recommended to create a with a , + /// you are recommended to create a with a implementation, /// like , , , or . /// /// The character type. /// /// To specify the encoding in the input stream, - /// you are recommended to create a with a , + /// you are recommended to create a with a implementation, /// like , , , or . /// /// d#@)zaQ`YgZi$X_9wB{sMQPesnof`T%lTUFBUE|DtPM~#ftC1NTgFJv0He)UM;$p z!yQIqm&ulkm+-~AjEr|2t}ltEH-{ho2}B%$GfD<4QI3boa~6de7{|fw9QOkgOdzgk z_#F_;gJ)`zg>Z)_Sr}F@!6JCW2grWqBV=R2ezHf&ZbLJeMOe| zSGf+Tab(prvTc@mk>-cVM)}||){!3Ef{t4+I;Emh>ym1RlsH#*>!+OgVyVHfFQhRQ zOxfXSw18d1^^lImP@EkiubEXstpXy?6|1U?bp*1%!p zxzy3xAvZrTIZ{U7-`F)yvL37&Q;dO|Q}{`${HT~q(xa(5GIX6ACT9xLmPY${D^s#! z2u{avn{*FRZtpC|OX~{l(-F>(bz)AMhUrWdQ=8Jg68!ybc0 m@dsO{pZv`}jZG&;^$B_qvUBT>$Bs_f6O@(RK2q_IP5l9igW-q( delta 746 zcmZ`%&ubGw6wYLKliA&vOi{9-#&nY+2BB$96+@ufUaBBQL}-cK-Rw$>25gd=p!OjC zKmDqVN9}FLbWe z8<+81I*5u?#b;>FV%g>@%=0TrXR>80x)%l_ZpqLceU=d6By79CV@rvhHq{=wurmB zi933h6=|0v?4NPt)mQ!4Su|~qb7aSD6X}{j*h=BPBk;xIXplXuie2&Bs-Q7P?30vD zA?XES+K3r1qZaflRgSY*Dc*TmPQ z&a#!pCpSgvCK$ttHBE=Y?P+Y0QrR)FWY2Byd*~*MV$3nn93=>-B z632Vz3bB}o)k;C^>lwjy(pT|>nh!L^@x8WykFG$29)?QOJa9{JC|-9>I@BNTDSAFW gdd16QlX`9t%TA_c&qRiY5Qg2$U7Ry9T(n3e5>82x!jBjcC7?k;Q%E8rD2casDiMufB5I*FYGEM+ zEZ!nuVHvO!t`Zb11j#=zVBrrC!Ab)bZv220Zn4k2JM+%$?&Cdsyk}R>4ou5Iw8~>B z$x-CwK6sQ4ROHF1r|DR&FyaI@@wwjOr3w3`9dy>ait3n$^Z_OB%U3; z_)yB|X(PMrEHT!KG18d^iw4CG$|9f+;+;ZBsR2x>K3uA9reH%2V}4mflDzm_Al#}m zFqa8MlQ7y+V-7H9yR`QWwvS_%jw4qWi;Ae5NqF=4>?hYy5(%#1!bym8KRPW9lHnKL zJHv;(K{!oo4eDAb84(_bnu#==|6kRQN=Ach>NpdYl83%d@tHS(*;E?N^3 Tg5odgZ_6(cb77178f>vIy8)FR delta 439 zcma)2ze_@46zzLI?0ahQq~X~QS~6U^JX9 zqPC`n;L#8?Gzbyxq0rzT5J6KJ5q+6cQ+K%M9ys@&dvCQusugls=kXwp;){=>&U=s- z#xO06<4TyviO`J?p$8+P*X?ZkjUOzQid$l+l$pSXj7dXfz7)DiElxKG8c7)iW50