1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00

Fix: #121 Print utf8 until invalid character.

This commit is contained in:
QC 2015-02-02 16:44:08 +01:00
parent e42a60f87a
commit 3a98c71fa1

View file

@ -156,12 +156,18 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
void textbox_text ( textbox *tb, char *text ) void textbox_text ( textbox *tb, char *text )
{ {
g_free ( tb->text ); g_free ( tb->text );
const gchar *last_pointer = NULL;
if ( g_utf8_validate ( text, -1, NULL ) ) { if ( g_utf8_validate ( text, -1, &last_pointer ) ) {
tb->text = g_strdup ( text ); tb->text = g_strdup ( text );
} }
else { else {
tb->text = g_strdup ( "Invalid UTF-8 string." ); 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 ) ); pango_layout_set_text ( tb->layout, tb->text, strlen ( tb->text ) );