add Encoding::num_bytes_to_encode_code_point()
This commit is contained in:
parent
99bbe81f6b
commit
fdabf4432a
@ -156,3 +156,41 @@ uint32_t Encoding::decode(Type type, const uint8_t * encoded)
|
|||||||
|
|
||||||
return 0u;
|
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;
|
||||||
|
}
|
||||||
|
@ -17,6 +17,8 @@ public:
|
|||||||
static uint8_t num_bytes_in_code_point(Type type, const uint8_t * encoded);
|
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 const uint8_t * beginning_of_code_point(Type type, const uint8_t * encoded);
|
||||||
static uint32_t decode(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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user