ace5bde9e4b4876cc33c98b7cf9ae719c768b6fc
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2009 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #include "hscroll.h"
21 #include "charset.h"
23 #include <assert.h>
24 #include <string.h>
26 char *
27 strscroll(struct hscroll *hscroll, const char *str, const char *separator,
28 unsigned width)
29 {
30 gchar *tmp, *buf;
32 assert(hscroll != NULL);
33 assert(str != NULL);
34 assert(separator != NULL);
36 /* create a buffer containing the string and the separator */
37 tmp = replace_locale_to_utf8(g_strconcat(str, separator,
38 str, separator, NULL));
40 if (hscroll->offset >= (unsigned)g_utf8_strlen(tmp, -1) / 2)
41 hscroll->offset = 0;
43 /* create the new scrolled string */
44 buf = g_utf8_offset_to_pointer(tmp, hscroll->offset);
45 utf8_cut_width(buf, width);
47 /* convert back to locale */
48 buf = utf8_to_locale(buf);
49 g_free(tmp);
50 return buf;
51 }