Skip to content

Commit

Permalink
image_osd_mkinfo(): pipe replacement by " - " separator was fixed to …
Browse files Browse the repository at this point in the history
…work correctly with

empty first element.
  • Loading branch information
Laurent Monin committed Jun 27, 2008
1 parent 6b6574b commit bfc848f
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/image-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
gchar delim = '%', imp = '|', sep[] = " - ";
gchar *start, *end;
guint pos, prev;
guint last;
gboolean want_separator = FALSE;
gchar *name, *data;
GString *new;
gchar *ret;
Expand All @@ -220,7 +220,6 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
new = g_string_new(str);

prev = 0;
last = FALSE;

while (TRUE)
{
Expand Down Expand Up @@ -294,6 +293,7 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
data = exif_get_data_as_text(exif, name);
exif_free_fd(imd->image_fd, exif);
}

if (data && *data && limit > 0 && strlen(data) > limit + 3)
{
gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data);
Expand Down Expand Up @@ -364,21 +364,31 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
}

g_string_erase(new, pos, end-start+1);
if (data)
g_string_insert(new, pos, data);

if (pos-prev >= 2 && new->str[pos-1] == imp)
if (data && *data)
{
g_string_erase(new, --pos, 1);
if (last && data && *data)
if (want_separator)
{
/* insert separator */
g_string_insert(new, pos, sep);
pos += strlen(sep);
}

g_string_insert(new, pos, data);
pos += strlen(data);
}

want_separator = FALSE;

if (pos-prev >= 1 && new->str[pos] == imp)
{
/* pipe character is replaced by a separator, delete it
* and raise a flag if needed */
g_string_erase(new, pos--, 1);
want_separator = (data && *data);
}

prev = pos - 1;

prev = data ? pos+strlen(data)-1 : pos-1;
last = data ? TRUE : last;
g_free(name);
g_free(data);
}
Expand Down

0 comments on commit bfc848f

Please sign in to comment.