changeset 752:85c9412d77d2

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.
author zas_
date Sat, 24 May 2008 20:01:59 +0000
parents f73df252aa05
children 477f48ba28d8
files src/image-overlay.c
diffstat 1 files changed, 23 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/image-overlay.c	Sat May 24 09:18:09 2008 +0000
+++ b/src/image-overlay.c	Sat May 24 20:01:59 2008 +0000
@@ -306,7 +306,9 @@
 			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 @@
 				 * "<i>*</i>\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 <b>*</b>\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 @@
 				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
+						}
+					else if (p[0] == '*' && !left)
+						{
+						right = p + 1;
+						left = extra;
 						}
 
-				/* Search for left and right parts */
-				for (p = extra; *p; p++)
-					if (*p == '*')
-						{
-						*p = '\0';
-						p++;
-						right = p;
-						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 @@
 		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);