Skip to content

Commit

Permalink
Restore Q_DecodeUTF8
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanBaian committed Feb 1, 2025
1 parent 9baf3b3 commit e6c6713
Showing 1 changed file with 12 additions and 66 deletions.
78 changes: 12 additions & 66 deletions engine/client/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,71 +619,17 @@ Convert utf char to current font's single-byte encoding
*/
int Con_UtfProcessCharForce( int in )
{
static int m = -1, k = 0; //multibyte state
static int uc = 0; //unicode char
// TODO: get rid of global state where possible
static utfstate_t state = { 0 };

if( !in )
{
m = -1;
k = 0;
uc = 0;
return 0;
}

// Get character length
if(m == -1)
{
uc = 0;
if( in >= 0xF8 )
{
return 0;
}
else if( in >= 0xF0 )
{
uc = in & 0x07;
m = 3;
}
else if( in >= 0xE0 )
{
uc = in & 0x0F;
m = 2;
}
else if( in >= 0xC0 )
{
uc = in & 0x1F;
m = 1;
}
else if( in <= 0x7F )
{
return in; // ascii
}
// return 0 if we need more chars to decode one
k = 0;
return 0;
}
// get more chars
else if( k <= m )
{
uc <<= 6;
uc += in & 0x3F;
k++;
}
if( in > 0xBF || m < 0 )
{
m = -1;
return 0;
}

if( k == m )
{
k = m = -1;

return uc;
int ch = Q_DecodeUTF8( &state, in );

// not implemented yet
// return '?';
}
return 0;
if( g_codepage == 1251 )
return Q_UnicodeToCP1251( ch );
if( g_codepage == 1252 )
return Q_UnicodeToCP1252( ch );

return ch; // not implemented yet
}

int GAME_EXPORT Con_UtfProcessChar( int in )
Expand Down Expand Up @@ -2146,10 +2092,10 @@ void Con_RunConsole( void )
}
else
{
Con_Printf( S_WARN "Unknown charset %s, defaulting to cp1252", con_charset.string );
// Con_Printf( S_WARN "Unknown charset %s, defaulting to cp1252", con_charset.string );

Cvar_DirectSet( &con_charset, "cp1252" );
g_codepage = 1252;
// Cvar_DirectSet( &con_charset, "cp1252" );
g_codepage = 0;
}

cls.accept_utf8 = !Q_stricmp( cl_charset.string, "utf-8" );
Expand Down

0 comments on commit e6c6713

Please sign in to comment.