From e2b7eeadbf5e7b61e31f392622c974e9de2d21e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonathan=20Neusch=C3=A4fer?= Date: Wed, 4 Jan 2012 18:33:30 +0100 Subject: [PATCH] screen_text: (API) use (char *) for strings Reduce some unneeded complexity when adding strings returned by other libraries than glib. --- src/screen_lyrics.c | 2 +- src/screen_text.c | 23 +++++++++++------------ src/screen_text.h | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index ef230c8..604a051 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -172,7 +172,7 @@ delete_lyr_hd(void) static void screen_lyrics_set(const GString *str) { - screen_text_set(&text, str); + screen_text_set(&text, str->str); /* paint new data */ diff --git a/src/screen_text.c b/src/screen_text.c index 21e73aa..244903d 100644 --- a/src/screen_text.c +++ b/src/screen_text.c @@ -37,44 +37,43 @@ screen_text_clear(struct screen_text *text) } void -screen_text_set(struct screen_text *text, const GString *str) +screen_text_set(struct screen_text *text, const char *str) { - const char *p, *eol, *next; + const char *eol, *next; assert(str != NULL); screen_text_clear(text); - p = str->str; - while ((eol = strchr(p, '\n')) != NULL) { + while ((eol = strchr(str, '\n')) != NULL) { char *line; next = eol + 1; /* strip whitespace at end */ - while (eol > p && (unsigned char)eol[-1] <= 0x20) + while (eol > str && (unsigned char)eol[-1] <= 0x20) --eol; /* create copy and append it to text->lines */ - line = g_malloc(eol - p + 1); - memcpy(line, p, eol - p); - line[eol - p] = 0; + line = g_malloc(eol - str + 1); + memcpy(line, str, eol - str); + line[eol - str] = 0; g_ptr_array_add(text->lines, line); /* reset control characters */ - for (eol = line + (eol - p); line < eol; ++line) + for (eol = line + (eol - str); line < eol; ++line) if ((unsigned char)*line < 0x20) *line = ' '; - p = next; + str = next; } - if (*p != 0) - g_ptr_array_add(text->lines, g_strdup(p)); + if (*str != 0) + g_ptr_array_add(text->lines, g_strdup(str)); list_window_set_length(text->lw, text->lines->len); } diff --git a/src/screen_text.h b/src/screen_text.h index 0e681da..3d9327c 100644 --- a/src/screen_text.h +++ b/src/screen_text.h @@ -66,7 +66,7 @@ screen_text_is_empty(const struct screen_text *text) } void -screen_text_set(struct screen_text *text, const GString *str); +screen_text_set(struct screen_text *text, const char *str); const char * screen_text_list_callback(unsigned idx, void *data); -- 2.30.2