summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 690cdf4)
raw | patch | inline | side by side (parent: 690cdf4)
author | Max Kellermann <max@duempel.org> | |
Tue, 3 Nov 2009 08:17:04 +0000 (09:17 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Tue, 3 Nov 2009 08:17:04 +0000 (09:17 +0100) |
Pre-convert the strings, instead of converting on demand.
src/screen_song.c | patch | blob | history |
diff --git a/src/screen_song.c b/src/screen_song.c
index f065552ec34997226f9a5b266d09a8178e6ab8c9..b56b5510d2331f2bee6774d0893258e82929ccb1 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
static const char *
screen_song_list_callback(unsigned idx, G_GNUC_UNUSED void *data)
{
- static char buffer[256];
- char *value;
-
assert(idx < current.lines->len);
- value = utf8_to_locale(g_ptr_array_index(current.lines, idx));
- g_strlcpy(buffer, value, sizeof(buffer));
- g_free(value);
-
- return buffer;
+ return g_ptr_array_index(current.lines, idx);
}
static void
screen_song_append(const char *label, const char *value, unsigned label_col)
{
- int value_col, entry_size, label_size;
+ unsigned label_width = locale_width(label) + 2;
+ int value_col, label_size;
gchar *entry, *entry_iter;
const gchar *value_iter;
- char *p;
+ char *p, *q;
unsigned width;
assert(label != NULL);
- assert(g_utf8_validate(label, -1, NULL));
assert(value != NULL);
assert(g_utf8_validate(value, -1, NULL));
value_col = lw->cols - label_col;
/* calculate the number of required linebreaks */
value_iter = value;
- label_size = strlen(label) + label_col - utf8_width(label);
- entry_size = label_size + strlen(value) + 2;
+ label_size = strlen(label) + label_col;
while (*value_iter != 0) {
- entry = g_malloc(entry_size);
+ entry = g_malloc(label_size);
if (value_iter == value) {
entry_iter = entry + g_sprintf(entry, "%s: ", label);
/* fill the label column with whitespaces */
- memset(entry_iter, ' ',
- entry + label_size - entry_iter);
- entry_iter = entry + label_size;
+ memset(entry_iter, ' ', label_col - label_width);
+ entry_iter += label_col - label_width;
}
else {
/* fill the label column with whitespaces */
/* not enough room for anything - bail out */
break;
+ *entry_iter = 0;
+
value_iter += strlen(p);
- strcpy(entry_iter, p);
+ p = replace_utf8_to_locale(p);
+ q = g_strconcat(entry, p, NULL);
+ g_free(entry);
g_free(p);
- g_ptr_array_add(current.lines, entry);
+ g_ptr_array_add(current.lines, q);
}
}