1
0
Fork 0
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:
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 )
{
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 {
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 ) );