Kernel: Shell backspace unicode detection cleanup

This commit is contained in:
Bananymous 2022-12-16 11:53:59 +02:00
parent f244728d33
commit 7efa5bfb75
1 changed files with 24 additions and 34 deletions

View File

@ -173,42 +173,32 @@ namespace Kernel
kprintln("unrecognized command '{}'", arguments.Front()); kprintln("unrecognized command '{}'", arguments.Front());
} }
static uint8_t GetLastLength(const BAN::String& string) static bool IsSingleUnicode(BAN::StringView sv)
{ {
if (string.Empty()) if (sv.Size() == 2 && ((uint8_t)sv[0] >> 5) != 0b110)
return 0; return false;
if (sv.Size() == 3 && ((uint8_t)sv[0] >> 4) != 0b1110)
if (!(string[string.Size() - 1] & 0x80)) return false;
return 1; if (sv.Size() == 4 && ((uint8_t)sv[0] >> 3) != 0b11110)
return false;
if (string.Size() < 2) for (uint32_t i = 1; i < sv.Size(); i++)
return 1; if (((uint8_t)sv[i] >> 6) != 0b10)
return false;
return true;
}
if (((uint8_t)string[string.Size() - 2] >> 5) == 0b110 && static uint32_t GetLastLength(BAN::StringView sv)
((uint8_t)string[string.Size() - 1] >> 6) == 0b10) {
if (sv.Size() < 2)
return sv.Size();
for (uint32_t len = 2; len <= 4; len++)
{ {
return 2; if (sv.Size() < len)
} return 1;
if (string.Size() < 3) if (IsSingleUnicode(sv.Substring(sv.Size() - len)))
return 1; return len;
if (((uint8_t)string[string.Size() - 3] >> 4) == 0b1110 &&
((uint8_t)string[string.Size() - 2] >> 6) == 0b10 &&
((uint8_t)string[string.Size() - 1] >> 6) == 0b10)
{
return 3;
}
if (string.Size() < 4)
return 1;
if ((string[string.Size() - 4] >> 3) == 0b11110 &&
(string[string.Size() - 3] >> 6) == 0b10 &&
(string[string.Size() - 2] >> 6) == 0b10 &&
(string[string.Size() - 1] >> 6) == 0b10)
{
return 3;
} }
return 1; return 1;
@ -227,8 +217,8 @@ namespace Kernel
{ {
kprint("\b \b", 3); kprint("\b \b", 3);
uint8_t last_len = GetLastLength(m_buffer); uint32_t last_len = GetLastLength(m_buffer);
for (uint8_t i = 0; i < last_len; i++) for (uint32_t i = 0; i < last_len; i++)
m_buffer.PopBack(); m_buffer.PopBack();
} }
break; break;