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:
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 )
|
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 {
|
||||||
|
if ( last_pointer != NULL ) {
|
||||||
|
// Copy string up to invalid character.
|
||||||
|
tb->text = g_strndup ( text, ( last_pointer - text ) );
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
tb->text = g_strdup ( "Invalid UTF-8 string." );
|
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 ) );
|
||||||
|
|
||||||
tb->cursor = MAX ( 0, MIN ( ( int ) strlen ( text ), tb->cursor ) );
|
tb->cursor = MAX ( 0, MIN ( ( int ) strlen ( text ), tb->cursor ) );
|
||||||
|
|
Loading…
Reference in a new issue