/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: AuUTF32.hpp Date: 2021-10-31 Author: Reece ***/ #pragma once namespace Aurora::Locale::Encoding::UTF32 { static void SwapU32(void *base, AuUInt32 count) { count *= 4; for (AuUInt32 i = 0; i < count; i += 4) { AuWriteU32BE(base, i, AuReadU32LE(base, i)); } } static AuUInt32 Count32(const void *base, AuUInt32 length, bool bytes = false) { return bytes ? length & ~3 : (length & ~3) / 4; } static AuStreamReadWrittenPair_t UTF8ToCp(const AuMemoryViewRead &utf8, const AuMemoryViewWrite &utf32) { const char *begin = utf8.Begin(); const char *end = utf8.End(); AuUInt32 *begin2 = utf32.Begin(); AuUInt32 *end2 = utf32.End(); UTF8::ReadUtf8ByteString(begin2, end2, begin, end); return AuStreamReadWrittenPair_t {begin - utf8.Begin(), (begin2 - utf32.Begin()) * sizeof(AuUInt32)}; } static AuStreamReadWrittenPair_t CPToUTF8(const AuMemoryViewRead &utf32, const AuMemoryViewWrite &utf8) { const AuUInt32 *begin = utf32.Begin(); const AuUInt32 *end = utf32.End(); char *dest = utf8.Begin(); char *destEnd = utf8.End(); AuUInt32 counter {}; const AuUInt32 *cur = begin; for (; cur < end; cur++) { UTF8::WriteCp(*cur, dest, counter, destEnd - dest); } return AuStreamReadWrittenPair_t {(cur - begin) * sizeof(AuUInt32), dest - utf8.Begin()}; } }