add Encoding::num_bytes_to_encode_code_point()

This commit is contained in:
josh committed 2016-10-05 23:10:41 -04:00
1 parent 99bbe81f6b
commit fdabf4432a
2 files changed
+40

No files matched your search

+38
View File
@@ -156,3 +156,41 @@ uint32_t Encoding::decode(Type type, const uint8_t * encoded)
return 0u;
}
uint8_t Encoding::num_bytes_to_encode_code_point(uint32_t code_point, Type type)
{
switch (type)
{
case UTF_8:
if (code_point <= 0x7Fu)
{
return 1u;
}
else if (code_point <= 0x7FFu)
{
return 2u;
}
else if (code_point <= 0xFFFFu)
{
return 3u;
}
else if (code_point <= 0x1FFFFFu)
{
return 4u;
}
else if (code_point <= 0x3FFFFFFu)
{
return 5u;
}
else
{
return 6u;
}
break;
case CP_1252:
return 1u;
break;
}
return 0u;
}