[Goodies-commits] r6064 - xfce4-dict/trunk/lib

Enrico Troeger enrico at xfce.org
Tue Nov 11 23:25:02 CET 2008


Author: enrico
Date: 2008-11-11 22:25:01 +0000 (Tue, 11 Nov 2008)
New Revision: 6064

Modified:
   xfce4-dict/trunk/lib/dictd.c
Log:
Parse also phonetic information endorsed by slashes.
Refactor some code.

Modified: xfce4-dict/trunk/lib/dictd.c
===================================================================
--- xfce4-dict/trunk/lib/dictd.c	2008-11-11 22:24:59 UTC (rev 6063)
+++ xfce4-dict/trunk/lib/dictd.c	2008-11-11 22:25:01 UTC (rev 6064)
@@ -102,6 +102,38 @@
 }
 
 
+static gchar *phon_find_start(gchar *buf, gchar *end_char, const gchar **end_str)
+{
+	gchar *start;
+
+	start = strchr(buf, '\\');
+	if (start != NULL)
+	{
+		*end_char = '\\';
+		*end_str = "\\";
+	}
+	else
+	{
+		start = strchr(buf, '/');
+		if (start != NULL)
+		{
+			*end_char = '/';
+			*end_str = "/";
+		}
+		else
+		{
+			start = strchr(buf, '[');
+			if (start != NULL)
+			{
+				*end_char = ']';
+				*end_str = "]";
+			}
+		}
+	}
+	return start;
+}
+
+
 /* We parse the first line differently as there are usually no links
  * but instead phonetic information */
 static void parse_header(DictData *dd, GString *buffer, GString *target)
@@ -109,26 +141,21 @@
 	gchar *start;
 	gchar *end;
 	gsize len;
-	gchar end_char = '\\';
+	gchar end_char;
+	const gchar *end_str;
 
 	while (buffer->len > 0)
 	{
-		start = strchr(buffer->str, '\\');
+		start = phon_find_start(buffer->str, &end_char, &end_str);
 		len = 0;
 
 		if (start == NULL)
 		{
-			start = strchr(buffer->str, '['); /* alternative way of specifiying phonetics */
-			if (start != NULL)
-				end_char = ']';
-			else
-			{
-				/* no phonetics at all, so add the text to the body to get at least possible
-				 * links parsed and return */
-				g_string_prepend(target, buffer->str);
-				g_string_erase(buffer, 0, -1); /* remove already handled text */
-				return;
-			}
+			/* no phonetics at all, so add the text to the body to get at least possible
+			 * links parsed and return */
+			g_string_prepend(target, buffer->str);
+			g_string_erase(buffer, 0, -1); /* remove already handled text */
+			return;
 		}
 		/* get length of text *before* the next '\' */
 		while (len < buffer->len && (buffer->str + len) != start)
@@ -143,8 +170,7 @@
 		if (start > end)
 		{
 			/* slashes don't match, skip this part */
-			gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter,
-				(end_char == ']') ? "\\" : "]", 1);
+			gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, end_str, 1);
 			continue;
 		}
 		len = end - buffer->str; /* length of the link */




More information about the Goodies-commits mailing list