mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Fix: #121 Print utf8 until invalid character.
This commit is contained in:
parent
e42a60f87a
commit
3a98c71fa1
1 changed files with 9 additions and 3 deletions
|
@ -156,13 +156,19 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
|
|||
void textbox_text ( textbox *tb, char *text )
|
||||
{
|
||||
g_free ( tb->text );
|
||||
|
||||
if ( g_utf8_validate ( text, -1, NULL ) ) {
|
||||
const gchar *last_pointer = NULL;
|
||||
if ( g_utf8_validate ( text, -1, &last_pointer ) ) {
|
||||
tb->text = g_strdup ( text );
|
||||
}
|
||||
else {
|
||||
if ( last_pointer != NULL ) {
|
||||
// Copy string up to invalid character.
|
||||
tb->text = g_strndup ( text, ( last_pointer - text ) );
|
||||
}
|
||||
else {
|
||||
tb->text = g_strdup ( "Invalid UTF-8 string." );
|
||||
}
|
||||
}
|
||||
pango_layout_set_text ( tb->layout, tb->text, strlen ( tb->text ) );
|
||||
|
||||
tb->cursor = MAX ( 0, MIN ( ( int ) strlen ( text ), tb->cursor ) );
|
||||
|
|
Loading…
Reference in a new issue