public: utflib: simplify Q_EncodeUTF8
This commit is contained in:
parent
5378494199
commit
93ebddfba3
1 changed files with 16 additions and 20 deletions
|
@ -114,27 +114,35 @@ uint32_t Q_DecodeUTF16( utfstate_t *s, uint32_t in )
|
|||
return 0;
|
||||
}
|
||||
|
||||
size_t Q_EncodeUTF8( char dst[4], uint32_t ch )
|
||||
static size_t Q_CodepointLength( uint32_t ch )
|
||||
{
|
||||
if( ch <= 0x7fu )
|
||||
return 1;
|
||||
else if( ch <= 0x7ffu )
|
||||
return 2;
|
||||
else if( ch <= 0xffffu )
|
||||
return 3;
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
size_t Q_EncodeUTF8( char dst[4], uint32_t ch )
|
||||
{
|
||||
switch( Q_CodepointLength( ch ))
|
||||
{
|
||||
case 1:
|
||||
dst[0] = ch;
|
||||
return 1;
|
||||
}
|
||||
else if( ch <= 0x7ffu )
|
||||
{
|
||||
case 2:
|
||||
dst[0] = 0xc0u | (( ch >> 6 ) & 0x1fu );
|
||||
dst[1] = 0x80u | (( ch ) & 0x3fu );
|
||||
return 2;
|
||||
}
|
||||
else if( ch <= 0xffffu )
|
||||
{
|
||||
case 3:
|
||||
dst[0] = 0xe0u | (( ch >> 12 ) & 0x0fu );
|
||||
dst[1] = 0x80u | (( ch >> 6 ) & 0x3fu );
|
||||
dst[2] = 0x80u | (( ch ) & 0x3fu );
|
||||
return 3;
|
||||
}
|
||||
|
||||
dst[0] = 0xf0u | (( ch >> 18 ) & 0x07u );
|
||||
dst[1] = 0x80u | (( ch >> 12 ) & 0x3fu );
|
||||
dst[2] = 0x80u | (( ch >> 6 ) & 0x3fu );
|
||||
|
@ -163,18 +171,6 @@ size_t Q_UTF8Length( const char *s )
|
|||
return len;
|
||||
}
|
||||
|
||||
static size_t Q_CodepointLength( uint32_t ch )
|
||||
{
|
||||
if( ch <= 0x7fu )
|
||||
return 1;
|
||||
else if( ch <= 0x7ffu )
|
||||
return 2;
|
||||
else if( ch <= 0xffffu )
|
||||
return 3;
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
size_t Q_UTF16ToUTF8( char *dst, size_t dstsize, const uint16_t *src, size_t srcsize )
|
||||
{
|
||||
utfstate_t state = { 0 };
|
||||
|
|
Loading…
Add table
Reference in a new issue