[tracker] Moved the coalesce function to libtracker-common



commit 0b27c398dbed97380aa6b87eff21abb4294872e7
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Sep 2 13:04:07 2009 +0200

    Moved the coalesce function to libtracker-common

 src/libtracker-common/tracker-utils.c     |   29 +++++++
 src/libtracker-common/tracker-utils.h     |    2 +
 src/tracker-extract/tracker-extract-mp3.c |  114 +++++++++++------------------
 3 files changed, 74 insertions(+), 71 deletions(-)
---
diff --git a/src/libtracker-common/tracker-utils.c b/src/libtracker-common/tracker-utils.c
index f80a6c3..051756c 100644
--- a/src/libtracker-common/tracker-utils.c
+++ b/src/libtracker-common/tracker-utils.c
@@ -483,3 +483,32 @@ tracker_uri_printf_escaped (const gchar *format, ...)
 
   return result;
 }
+
+
+gchar *
+tracker_coalesce (gint n_values,
+                  ...)
+{
+	va_list args;
+	gint    i;
+	gchar *result = NULL;
+
+	va_start (args, n_values);
+
+	for (i = 0; i < n_values; i++) {
+		gchar *value;
+
+		value = va_arg (args, gchar *);
+		if (value) {
+			if (!result) {
+				result = value;
+			} else {
+				g_free (value);
+			}
+		}
+	}
+
+	va_end (args);
+
+	return result;
+}
diff --git a/src/libtracker-common/tracker-utils.h b/src/libtracker-common/tracker-utils.h
index 1d2e7f2..de8a518 100644
--- a/src/libtracker-common/tracker-utils.h
+++ b/src/libtracker-common/tracker-utils.h
@@ -44,6 +44,8 @@ gchar*   tracker_uri_vprintf_escaped        (const gchar *format,
 					     va_list      args);
 gchar*   tracker_uri_printf_escaped         (const gchar *format,
 					     ...);
+gchar *  tracker_coalesce                   (gint n_values,
+					     ...);
 
 /* Temporary: Just here until we upgrade to GLib 2.18. */
 G_CONST_RETURN gchar *
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 9032fec..694ff91 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -1808,34 +1808,6 @@ parse_id3v2 (const gchar *data,
 	return offset;
 }
 
-static gchar *
-coalesce (gint n_values,
-          ...)
-{
-	va_list args;
-	gint    i;
-	gchar *result = NULL;
-
-	va_start (args, n_values);
-
-	for (i = 0; i < n_values; i++) {
-		gchar *value;
-
-		value = va_arg (args, gchar *);
-		if (value) {
-			if (!result) {
-				result = value;
-			} else {
-				g_free (value);
-			}
-		}
-	}
-
-	va_end (args);
-
-	return result;
-}
-
 static void
 extract_mp3 (const gchar *uri,
 	     TrackerSparqlBuilder  *metadata)
@@ -1911,49 +1883,49 @@ extract_mp3 (const gchar *uri,
 	/* Get other embedded tags */
 	audio_offset = parse_id3v2 (buffer, buffer_size, &filedata.id3v1_info, uri, metadata, &filedata);
 
-	filedata.title = coalesce (4, filedata.id3v24_info.title2,
-	                              filedata.id3v23_info.title2,
-	                              filedata.id3v22_info.title2,
-	                              filedata.id3v1_info.title);
-	filedata.performer = coalesce (7, filedata.id3v24_info.performer1,
-	                                  filedata.id3v24_info.performer2,
-	                                  filedata.id3v23_info.performer1,
-	                                  filedata.id3v23_info.performer2,
-	                                  filedata.id3v22_info.performer1,
-	                                  filedata.id3v22_info.performer2,
-	                                  filedata.id3v1_info.artist);
-	filedata.album = coalesce (4, filedata.id3v24_info.album,
-	                              filedata.id3v23_info.album,
-	                              filedata.id3v22_info.album,
-	                              filedata.id3v1_info.album);
-	filedata.genre = coalesce (7, filedata.id3v24_info.content_type,
-	                                  filedata.id3v24_info.title1,
-	                                  filedata.id3v23_info.content_type,
-	                                  filedata.id3v23_info.title1,
-	                                  filedata.id3v22_info.content_type,
-	                                  filedata.id3v22_info.title1,
-	                                  filedata.id3v1_info.genre);
-	filedata.recording_time = coalesce (5, filedata.id3v24_info.recording_time,
-	                                    filedata.id3v24_info.release_time,
-	                                    filedata.id3v23_info.recording_time,
-	                                    filedata.id3v22_info.recording_time,
-	                                    filedata.id3v1_info.year);
-	filedata.publisher = coalesce (3, filedata.id3v24_info.publisher,
-	                              filedata.id3v23_info.publisher,
-	                              filedata.id3v22_info.publisher);
-	filedata.text = coalesce (3, filedata.id3v24_info.text,
-	                              filedata.id3v23_info.text,
-	                              filedata.id3v22_info.text);
-	filedata.copyright = coalesce (3, filedata.id3v24_info.copyright,
-	                              filedata.id3v23_info.copyright,
-	                              filedata.id3v22_info.copyright);
-	filedata.comment = coalesce (7, filedata.id3v24_info.title3,
-	                             filedata.id3v24_info.comment,
-	                             filedata.id3v23_info.title3,
-	                             filedata.id3v23_info.comment,
-	                             filedata.id3v22_info.title3,
-	                             filedata.id3v22_info.comment,
-	                             filedata.id3v1_info.comment);
+	filedata.title = tracker_coalesce (4, filedata.id3v24_info.title2,
+	                                   filedata.id3v23_info.title2,
+	                                   filedata.id3v22_info.title2,
+	                                   filedata.id3v1_info.title);
+	filedata.performer = tracker_coalesce (7, filedata.id3v24_info.performer1,
+	                                       filedata.id3v24_info.performer2,
+	                                       filedata.id3v23_info.performer1,
+	                                       filedata.id3v23_info.performer2,
+	                                       filedata.id3v22_info.performer1,
+	                                       filedata.id3v22_info.performer2,
+	                                       filedata.id3v1_info.artist);
+	filedata.album = tracker_coalesce (4, filedata.id3v24_info.album,
+	                                   filedata.id3v23_info.album,
+	                                   filedata.id3v22_info.album,
+	                                   filedata.id3v1_info.album);
+	filedata.genre = tracker_coalesce (7, filedata.id3v24_info.content_type,
+	                                   filedata.id3v24_info.title1,
+	                                   filedata.id3v23_info.content_type,
+	                                   filedata.id3v23_info.title1,
+	                                   filedata.id3v22_info.content_type,
+	                                   filedata.id3v22_info.title1,
+	                                   filedata.id3v1_info.genre);
+	filedata.recording_time = tracker_coalesce (5, filedata.id3v24_info.recording_time,
+	                                            filedata.id3v24_info.release_time,
+	                                            filedata.id3v23_info.recording_time,
+	                                            filedata.id3v22_info.recording_time,
+	                                            filedata.id3v1_info.year);
+	filedata.publisher = tracker_coalesce (3, filedata.id3v24_info.publisher,
+	                                       filedata.id3v23_info.publisher,
+	                                       filedata.id3v22_info.publisher);
+	filedata.text = tracker_coalesce (3, filedata.id3v24_info.text,
+	                                  filedata.id3v23_info.text,
+	                                  filedata.id3v22_info.text);
+	filedata.copyright = tracker_coalesce (3, filedata.id3v24_info.copyright,
+	                                       filedata.id3v23_info.copyright,
+	                                       filedata.id3v22_info.copyright);
+	filedata.comment = tracker_coalesce (7, filedata.id3v24_info.title3,
+	                                     filedata.id3v24_info.comment,
+	                                     filedata.id3v23_info.title3,
+	                                     filedata.id3v23_info.comment,
+	                                     filedata.id3v22_info.title3,
+	                                     filedata.id3v22_info.comment,
+	                                     filedata.id3v1_info.comment);
 
 	if (filedata.performer) {
 		filedata.performer_uri = tracker_uri_printf_escaped ("urn:artist:%s", filedata.performer);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]