add Encoding::num_bytes_to_encode_code_point()

This commit is contained in:
Josh Holtrop 2016-10-05 23:10:41 -04:00
parent 99bbe81f6b
commit fdabf4432a
2 changed files with 40 additions and 0 deletions

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;
}

View File

@ -17,6 +17,8 @@ public:
static uint8_t num_bytes_in_code_point(Type type, const uint8_t * encoded);
static const uint8_t * beginning_of_code_point(Type type, const uint8_t * encoded);
static uint32_t decode(Type type, const uint8_t * encoded);
static uint8_t num_bytes_to_encode_code_point(uint32_t code_point, Type type);
static uint8_t encode(uint32_t code_point, Type type, uint8_t * buffer);
};
#endif