[*] Made the UTF8/32 implementation less wrong

This commit is contained in:
Reece Wilson 2021-11-06 07:52:28 +00:00
parent 320d6b95ce
commit 7211c25936

View File

@ -55,7 +55,7 @@ namespace Aurora::Locale::Encoding::UTF32
*(result++) = static_cast<AuUInt8>(((cp >> 6) & 0x3f) | 0x80);
*(result++) = static_cast<AuUInt8>((cp & 0x3f) | 0x80);
}
else if (cp < 200000)
else if (cp < 0x200000)
{
if (counter + 4 > max)
{
@ -67,7 +67,7 @@ namespace Aurora::Locale::Encoding::UTF32
*(result++) = static_cast<AuUInt8>(((cp >> 6) & 0x3f) | 0x80);
*(result++) = static_cast<AuUInt8>((cp & 0x3f) | 0x80);
}
else if (cp < 400000)
else if (cp < 0x4000000)
{
if (counter + 5 > max)
{
@ -80,7 +80,7 @@ namespace Aurora::Locale::Encoding::UTF32
*(result++) = static_cast<AuUInt8>(((cp >> 6) & 0x3f) | 0x80);
*(result++) = static_cast<AuUInt8>((cp & 0x3f) | 0x80);
}
else if (cp < 80000000)
else if (cp < 0x80000000)
{
if (counter + 6 > max)
{
@ -101,22 +101,17 @@ namespace Aurora::Locale::Encoding::UTF32
return true;
}
static bool ReadUtf8ByteString(AuUInt32 *cp, AuUInt32 *&cpEnd, const char *&s, const char *end)
static bool ReadUtf8ByteString(AuUInt32 *&cp, AuUInt32 *cpEnd, const char *&it, const char *end)
{
if (!s)
if (!it)
{
return false;
}
if (!cp)
{
cpEnd = cp;
}
bool bUpdate = cp;
auto &it = s;
while ((it < end) && // can coomsome
(cp && cp < cpEnd))
while ((it < end) && // can coonsome
(bUpdate && cp < cpEnd))
{
AuUInt32 c = 0;
if (*it <= 0x7FU)
@ -160,14 +155,15 @@ namespace Aurora::Locale::Encoding::UTF32
it += nby;
}
if (cp)
if (bUpdate)
{
*cp = c;
cp++;
}
cpEnd++;
cp++;
}
return true;
}
static AuUInt32 CountU8Overhead(AuUInt32 cp)
@ -178,11 +174,11 @@ namespace Aurora::Locale::Encoding::UTF32
return 2;
else if (cp < 0x10000)
return 3;
else if (cp < 200000)
else if (cp < 0x200000)
return 4;
else if (cp < 400000)
else if (cp < 0x400000)
return 5;
else if (cp < 80000000)
else if (cp < 0x80000000)
return 6;
}
}