diff options
author | Kalle Wallin <kaw@linux.se> | 2006-03-28 08:40:56 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2006-03-28 08:40:56 +0000 |
commit | e36572093917e163e608195b559017e7bbe09347 (patch) | |
tree | 34df0adbe9c5ab68cf73d242101340b3c6ec23a2 /src/support.c | |
parent | 1525d2bba9555fee56de49eac583c129363f5407 (diff) | |
download | mpd-e36572093917e163e608195b559017e7bbe09347.tar.gz mpd-e36572093917e163e608195b559017e7bbe09347.tar.xz mpd-e36572093917e163e608195b559017e7bbe09347.zip |
unicode fixes from Dmitry Baryshkov/René van Bevern
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@3960 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/support.c')
-rw-r--r-- | src/support.c | 23 |
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); |