[*] Should've ran a clean build :(

This commit is contained in:
Reece Wilson 2021-09-15 02:14:29 +01:00
parent ca71401ba6
commit 2c68cf529a
10 changed files with 106 additions and 44 deletions

View File

@ -9,17 +9,17 @@
namespace Aurora::Locale::Encoding
{
AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const void *utf8, AuUInt32 ut8Length, void *binary, AuUInt32 binaryLength, ECodePage page = ECodePage::eUnsupported);
static inline AuStreamReadWrittenPair_t EncodeUTF8(const AuString &out, void *binary, AuUInt32 binaryLength, ECodePage page = ECodePage::eUnsupported)
AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(Aurora::Memory::MemoryViewRead utf8, Aurora::Memory::MemoryViewWrite binary, ECodePage page = ECodePage::eUnsupported);
static inline AuStreamReadWrittenPair_t EncodeUTF8(const AuString &utf8, Aurora::Memory::MemoryViewWrite binary, ECodePage page = ECodePage::eUnsupported)
{
return EncodeUTF8(out.data(), static_cast<AuUInt32>(out.size()), binary, binaryLength, page);
return EncodeUTF8(Aurora::Memory::MemoryViewRead(utf8), binary, page);
}
AUKN_SYM std::optional<AuPair<ECodePage, AuUInt8>> DecodeBOM(const void *binary, AuUInt32 binaryLength);
AUKN_SYM std::optional<AuPair<ECodePage, AuUInt8>> DecodeBOM(Aurora::Memory::MemoryViewRead binary);
/// Translates a buffer, possibly a slice of a stream, to UTF-8
/// Returns a pair; bytes consumed, bytes written
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const void *binary, AuUInt32 binaryLength, void *utf8, AuUInt32 utf8Max, ECodePage page = ECodePage::eUnsupported);
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(Aurora::Memory::MemoryViewRead binary, Aurora::Memory::MemoryViewWrite utf8, ECodePage page = ECodePage::eUnsupported);
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const void *binary, AuUInt32 binaryLength, AuString &out, ECodePage page = ECodePage::eUnsupported);
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(Aurora::Memory::MemoryViewRead binary, AuString &out, ECodePage page = ECodePage::eUnsupported);
}

View File

@ -13,14 +13,45 @@ namespace Aurora::Memory
struct MemoryView
{
using Void_t = std::conditional_t<Readonly_b, const void *, void *>;
/*
YadaYada(MemoryView(tempstring/array/etc)) should be legal, right?
---------------------
Temporary objects are destroyed as the last step in evaluating the full-expression that (lexically) contains the point where they were created.
---------------------
A full-expression is:
[...]
* an expression that is not a subexpression of another expression and that is not otherwise part of a full-expression.
---------------------
*/
template<typename T>
constexpr MemoryView(const AuList<T> &list)
MemoryView()
{
this->ptr = nullptr;
this->length = 0;
}
template<typename T, typename std::enable_if<AuIsBaseOfTemplate<AURORA_RUNTIME_AU_LIST, T>::value>::type* = nullptr>
MemoryView(T &list)
{
this->ptr = list.data();
this->length = list.size() * sizeof(T);
}
MemoryView(const AuString &str)
{
this->ptr = str.data();
this->length = str.size();
}
template<typename T, int Z>
constexpr MemoryView(T(&a)[Z])
{
this->ptr = &a[0];
this->length = Z * sizeof(T);
}
template<typename T>
constexpr MemoryView(T *start, T *end)
{
@ -42,12 +73,6 @@ namespace Aurora::Memory
this->length = length;
}
MemoryView()
{
this->ptr = nullptr;
this->length = 0;
}
AuUInt ToPointer()
{
return reinterpret_cast<AuUInt>(ptr);
@ -86,12 +111,17 @@ namespace Aurora::Memory
template<bool Readonly_b>
struct MemoryViewStream : MemoryView<Readonly_b>
{
template<typename T>
constexpr MemoryViewStream(const AuList<T> &list, AuUInt &length) : MemoryView<Readonly_b>(list), outVariable(length)
template<typename T, typename std::enable_if<AuIsBaseOfTemplate<AURORA_RUNTIME_AU_LIST, T>::value>::type* = nullptr>
constexpr MemoryViewStream(T &list, AuUInt &length) : MemoryView<Readonly_b>(list), outVariable(length)
{
outVariable = 0;
}
constexpr MemoryViewStream(const AuString &str, AuUInt &length) : MemoryView<Readonly_b>(str), outVariable(length)
{
outVariable = 0;
}
template<typename T>
constexpr MemoryViewStream(T *start, T *end, AuUInt &length) : MemoryView<Readonly_b>(start, end), outVariable(length)
{
@ -104,7 +134,31 @@ namespace Aurora::Memory
outVariable = 0;
}
template<typename T, typename std::enable_if<AuIsBaseOfTemplate<AURORA_RUNTIME_AU_LIST, T>::value>::type* = nullptr>
constexpr MemoryViewStream(T &list) : MemoryView<Readonly_b>(list), outVariable(unused)
{
outVariable = 0;
}
constexpr MemoryViewStream(const AuString &str) : MemoryView<Readonly_b>(str), outVariable(unused)
{
outVariable = 0;
}
template<typename T>
constexpr MemoryViewStream(T *start, T *end) : MemoryView<Readonly_b>(start, end), outVariable(unused)
{
outVariable = 0;
}
template<typename T, int Z>
constexpr MemoryViewStream(T(&a)[Z]) : MemoryView<Readonly_b>(a), outVariable(unused)
{
outVariable = 0;
}
AuUInt &outVariable;
AuUInt unused;
};
using MemoryViewStreamRead = MemoryViewStream<true>;

View File

@ -25,6 +25,7 @@
#include <intrin.h>
#include "../AuroraTypedefs.hpp"
#include "../AuroraUtils.hpp"
#if defined(_AUHAS_FMT)
#include <fmt/core.h>
@ -62,7 +63,6 @@
#include "Time/Time.hpp"
#include "Loop/Loop.hpp"
#include "../AuroraUtils.hpp"
namespace Aurora
{

View File

@ -34,7 +34,7 @@ static inline auto AuMakePair(Args... args)
return AURORA_RUNTIME_MAKE_PAIR(args...);
}
#if defined(AURORA_PLATFORM_WIN32)
#if defined(AURORA_IS_MODERNNT_DERIVED) && defined(_WINDOWS_)
static inline void AuWin32CloseHandle(HANDLE &handle)
{
HANDLE local;
@ -60,6 +60,9 @@ static constexpr int AuArraySize(const T(&array)[Z])
#if defined(DEBUG) || defined(STAGING)
template<typename ... T>
static inline void __declspec(noreturn) SysPanic(T... args);
template<typename Z, typename T>
static void inline SafeDelete(T *in)
{
@ -419,6 +422,11 @@ static inline bool AuTryInsertNoEnd(Container *container, const Type &value) //
}
}
namespace Aurora::Memory
{
struct ByteBuffer;
}
template<typename T>
static inline bool AuTryResize(T &list, AuUInt length)
{

View File

@ -137,8 +137,8 @@ namespace Aurora::Compression
while (read != input)
{
AuUInt32 request = std::min(input, length);
if (this->reader_->Read(din_, request) != IO::EStreamError::eErrorNone)
AuUInt request = std::min(input, length);
if (this->reader_->Read(Memory::MemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone)
{
return AuMakePair(read, done);
}
@ -218,8 +218,8 @@ namespace Aurora::Compression
while (read < input)
{
AuUInt32 request = std::min(input, AuUInt32(AuArraySize(din_)));
if (this->reader_->Read(din_, request) != IO::EStreamError::eErrorNone)
AuUInt request = std::min(input, AuUInt32(AuArraySize(din_)));
if (this->reader_->Read(Memory::MemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone)
{
return AuMakePair(read, done);
}
@ -308,8 +308,8 @@ namespace Aurora::Compression
AuUInt32 done{}, read{};
while (read < input)
{
AuUInt32 request = std::min(input, AuUInt32(AuArraySize(din_)));
if (this->reader_->Read(din_, request) != IO::EStreamError::eErrorNone)
AuUInt request = std::min(input, AuUInt32(AuArraySize(din_)));
if (this->reader_->Read(Memory::MemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone)
{
return AuMakePair(read, done);
}
@ -412,9 +412,9 @@ namespace Aurora::Compression
if (frameSize)
{
AuUInt32 request = frameSize;
AuUInt request = frameSize;
if ((input < (inputStat + request)) ||
(this->reader_->Read(bufferIn.get(), request) != IO::EStreamError::eErrorNone) ||
(this->reader_->Read(Memory::MemoryViewStreamWrite(bufferIn.get(), request)) != IO::EStreamError::eErrorNone) ||
(request != frameSize))
{
ret = request == 0 && inputStat;

View File

@ -104,7 +104,8 @@ namespace Aurora::Console::ConsoleFIO
if (gFileHandle)
{
gFileHandle->Write(gLogBuffer.data(), gLogBuffer.size());
AuUInt idc;
gFileHandle->Write(Aurora::Memory::MemoryViewStreamRead(gLogBuffer));
}
gLogBuffer.clear();

View File

@ -230,8 +230,8 @@ namespace Aurora::IO::FS
}
bool ok {};
ok = stream->Write(bom, 3);
ok &= stream->Write(str.data(), str.size()) == str.size();
ok = stream->Write(Memory::MemoryViewStreamRead{bom});
ok &= stream->Write(Memory::MemoryViewStreamRead{str});
stream->Flush();
return ok;

View File

@ -44,7 +44,6 @@ namespace Aurora::Locale::Encoding
{
return {};
}
if (((page == ECodePage::eSysUnk) &&
(GetInternalCodePage() == ECodePage::eUTF8)) ||

View File

@ -11,7 +11,7 @@
namespace Aurora::Locale::Encoding
{
AUKN_SYM AuOptional<AuPair<ECodePage, AuUInt8>> DecodeBOM(const void *binary, AuUInt32 binaryLength)
AUKN_SYM AuOptional<AuPair<ECodePage, AuUInt8>> DecodeBOM(Aurora::Memory::MemoryViewRead binary)
{
#define ADD_PATTERN(str, code) {str, AuArraySize(str) - 1, ECodePage::code}
AuList<std::tuple<const char *, int, ECodePage>> bows =
@ -32,8 +32,8 @@ namespace Aurora::Locale::Encoding
for (const auto &[string, length, category] : bows)
{
if (binaryLength < length) continue;
if (std::memcmp(binary, string, length) != 0) continue;
if (binary.length < length) continue;
if (std::memcmp(binary.ptr, string, length) != 0) continue;
return AuMakePair(category, length);
}
@ -41,32 +41,32 @@ namespace Aurora::Locale::Encoding
return {};
}
AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const void *utf8, AuUInt32 utf8Length, void *binary, AuUInt32 binaryLength, ECodePage page)
AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(Aurora::Memory::MemoryViewRead utf8, Aurora::Memory::MemoryViewWrite binary, ECodePage page)
{
TextStreamEncoder re(page);
return re.DecodeUTF8(utf8, utf8Length, binary, binaryLength);
return re.DecodeUTF8(utf8.ptr, utf8.length, binary.ptr, binary.length);
}
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const void *binary, AuUInt32 binaryLength, void *utf8, AuUInt32 utf8Max, ECodePage page)
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(Aurora::Memory::MemoryViewRead binary, Aurora::Memory::MemoryViewWrite utf8, ECodePage page)
{
TextStreamProcessor re(page);
return re.EncodeUTF8(binary, binaryLength, utf8, utf8Max);
return re.EncodeUTF8(binary.ptr, binary.length, utf8.ptr, utf8.length);
}
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const void *binary, AuUInt32 binaryLength, AuString &out, ECodePage page)
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(Aurora::Memory::MemoryViewRead binary, AuString &out, ECodePage page)
{
auto aaa = DecodeUTF8(binary, binaryLength, nullptr, 0, page);
auto aaa = DecodeUTF8(binary, {}, page);
out.resize(aaa.second);
auto ret = DecodeUTF8(binary, binaryLength, out.data(), out.size(), page);
auto ret = DecodeUTF8(binary, Memory::MemoryViewWrite(out.data(), out.size()), page);
out.resize(ret.second);
return ret;
}
AuStreamReadWrittenPair_t DecodeUTF8(void *binary, AuUInt32 binaryLength, AuString &out, ECodePage page)
{
auto aaa = DecodeUTF8(binary, binaryLength, nullptr, 0, page);
auto aaa = DecodeUTF8(Aurora::Memory::MemoryViewRead(binary, binaryLength), {}, page);
out.resize(aaa.second);
auto ret = DecodeUTF8(binary, binaryLength, out.data(), out.size(), page);
auto ret = DecodeUTF8(Aurora::Memory::MemoryViewRead(binary, binaryLength), Aurora::Memory::MemoryViewWrite(out.data(), out.size()), page);
out.resize(ret.second);
return ret;
}

View File

@ -128,7 +128,7 @@ namespace Aurora::Locale::Encoding
{
if (page == ECodePage::eUnsupported)
{
auto header = DecodeBOM(binary, binaryLength);
auto header = DecodeBOM(Aurora::Memory::MemoryViewRead(binary, binaryLength));
if (header)
{
page = header->first;