summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8e9691d)
raw | patch | inline | side by side (parent: 8e9691d)
author | Max Kellermann <max@duempel.org> | |
Tue, 20 Oct 2009 05:59:14 +0000 (07:59 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Tue, 20 Oct 2009 05:59:14 +0000 (07:59 +0200) |
Convert the input strings to UTF-8 before applying UTF-8 functions on
them. Convert back to the locale before returning.
them. Convert back to the locale before returning.
src/hscroll.c | patch | blob | history |
diff --git a/src/hscroll.c b/src/hscroll.c
index 481683c847a8f490820a8b6b7991a3e045c45d21..109293d3364254666aae645fb1c1c756fa739bf3 100644 (file)
--- a/src/hscroll.c
+++ b/src/hscroll.c
unsigned width)
{
gchar *tmp, *buf;
- gsize len, size;
+ gsize len, size, ulen;
assert(hscroll != NULL);
assert(str != NULL);
return g_strdup(str);
/* create a buffer containing the string and the separator */
- tmp = g_strconcat(str, separator, NULL);
+ tmp = replace_locale_to_utf8(g_strconcat(str, separator, NULL));
len = utf8_width(tmp);
if (hscroll->offset >= len)
/* create the new scrolled string */
size = width+1;
- if (g_utf8_validate(tmp, -1, NULL) ) {
- size_t ulen;
- buf = g_malloc(size*6);// max length of utf8 char is 6
- g_utf8_strncpy(buf, g_utf8_offset_to_pointer(tmp, hscroll->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 + hscroll->offset, size);
- if (strlen(buf) < (size_t)width)
- g_strlcat(buf, tmp, size);
- }
+ buf = g_malloc(size * 6);// max length of utf8 char is 6
+ g_utf8_strncpy(buf, g_utf8_offset_to_pointer(tmp,
+ hscroll->offset), size);
+ if ((ulen = g_utf8_strlen(buf, -1)) < width)
+ g_utf8_strncpy(buf + strlen(buf), tmp, size - ulen - 1);
g_free(tmp);
- return buf;
+ tmp = utf8_to_locale(buf);
+ g_free(buf);
+ return tmp;
}