From d2e0888194442fe09a3f099f149e3d4fb3884bc9 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Sat, 24 May 2008 20:01:59 +0000 Subject: [PATCH] Allow to escape star characters in the template string with a \. One can insert a \ by escaping it with another \. Fix deletion of empty parts when using | trick. Append the separator " - " only if data is neither NULL nor empty. Patch by Uwe Ohse and Laurent Monin. --- src/image-overlay.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/image-overlay.c b/src/image-overlay.c index 0cf4ed3d..839c97a7 100644 --- a/src/image-overlay.c +++ b/src/image-overlay.c @@ -306,7 +306,9 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v if (data && *data) { /* Display data between left and right parts of extra string - * the data is expressed by a '*' character. + * the data is expressed by a '*' character. A '*' may be escaped + * by a \. You should escape all '*' characters, do not rely on the + * current implementation which only replaces the first unescaped '*'. * If no "*" is present, the extra string is just appended to data string. * Pango mark up is accepted in left and right parts. * Any \n is replaced by a newline @@ -314,6 +316,8 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v * "*\n" -> data is displayed in italics ended with a newline * "\n" -> ended with newline * "ISO *" -> prefix data with "ISO " (ie. "ISO 100") + * "\**\*" -> prefix data with a star, and append a star (ie. "*100*") + * "\\*" -> prefix data with an anti slash (ie "\100") * "Collection *\n" -> display data in bold prefixed by "Collection " and a newline is appended * * FIXME: using background / foreground colors lead to weird results. @@ -324,25 +328,26 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v gchar *p; guint len = strlen(extra); - /* Search and replace "\n" by a newline character */ + /* Search for left and right parts and unescape characters */ for (p = extra; *p; p++, len--) - if (p[0] == '\\' && p[1] == 'n') + if (p[0] == '\\') { - memmove(p+1, p+2, --len); - *p = '\n'; + if (p[1] == 'n') + { + memmove(p+1, p+2, --len); + p[0] = '\n'; + } + else if (p[1] != '\0') + memmove(p, p+1, len--); // includes \0 } - - /* Search for left and right parts */ - for (p = extra; *p; p++) - if (*p == '*') + else if (p[0] == '*' && !left) { - *p = '\0'; - p++; - right = p; + right = p + 1; left = extra; - break; } - + + if (left) right[-1] = '\0'; + new_data = g_strdup_printf("%s%s%s", left ? left : "", data, right); g_free(data); data = new_data; @@ -354,10 +359,10 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v if (data) g_string_insert(new, pos, data); - if (pos-prev == 2 && new->str[pos-1] == imp) + if (pos-prev >= 2 && new->str[pos-1] == imp) { g_string_erase(new, --pos, 1); - if (last && data) + if (last && data && *data) { g_string_insert(new, pos, sep); pos += strlen(sep); -- 2.20.1