aboutsummaryrefslogtreecommitdiffstats
path: root/src/support.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/support.c')
-rw-r--r--src/support.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/support.c b/src/support.c
index ade5ee4eb..847178d9c 100644
--- a/src/support.c
+++ b/src/support.c
@@ -106,6 +106,7 @@ strcasestr(const char *haystack, const char *needle)
}
#endif /* HAVE_STRCASESTR */
+// FIXME: utf-8 length
char *
strscroll(char *str, char *separator, int width, scroll_state_t *st)
{
@@ -123,18 +124,28 @@ strscroll(char *str, char *separator, int width, scroll_state_t *st)
tmp = g_malloc(size);
g_strlcpy(tmp, str, size);
g_strlcat(tmp, separator, size);
- len = strlen(tmp);
+ len = my_strlen(tmp);
if( st->offset >= len )
st->offset = 0;
/* create the new scrolled string */
size = width+1;
- buf = g_malloc(size);
- g_strlcpy(buf, tmp+st->offset, size);
- if( strlen(buf) < width )
- g_strlcat(buf, tmp, size);
-
+ if (g_utf8_validate(tmp, -1, NULL) )
+ {
+ int ulen;
+ buf = g_malloc(size*6);// max length of utf8 char is 6
+ g_utf8_strncpy(buf, g_utf8_offset_to_pointer(tmp,st->offset), size);
+ if( (ulen = g_utf8_strlen(buf, -1)) < width )
+ g_utf8_strncpy(buf+strlen(buf), tmp, size - ulen - 1);
+ }
+ else
+ {
+ buf = g_malloc(size);
+ g_strlcpy(buf, tmp+st->offset, size);
+ if( strlen(buf) < width )
+ g_strlcat(buf, tmp, size);
+ }
if( time(NULL)-st->t >= 1 )
{
st->t = time(NULL);