[tracker] libtracker: Add tracker_sparql_escape



commit dd7bf2852db08be69f030b8f93089c6bc0370f35
Author: Jürg Billeter <j bitron ch>
Date:   Wed May 27 14:25:47 2009 +0200

    libtracker: Add tracker_sparql_escape
---
 src/libtracker/tracker.c |   53 +++++++++++++++++++++++++++++++++++++++++++++-
 src/libtracker/tracker.h |    2 +
 2 files changed, 54 insertions(+), 1 deletions(-)

diff --git a/src/libtracker/tracker.c b/src/libtracker/tracker.c
index c484249..0a9581a 100644
--- a/src/libtracker/tracker.c
+++ b/src/libtracker/tracker.c
@@ -136,7 +136,58 @@ tracker_void_reply (DBusGProxy *proxy, GError *error, gpointer user_data)
 }
 
 
+/* copied from tracker-module-metadata.c */
+gchar *
+tracker_sparql_escape (const gchar *str)
+{
+	gchar       *escaped_string;
+	const gchar *p;
+	gchar       *q;
+
+	escaped_string = g_malloc (2 * strlen (str) + 1);
+
+	p = str;
+	q = escaped_string;
+	while (*p != '\0') {
+		switch (*p) {
+		case '\t':
+			*q++ = '\\';
+			*q++ = 't';
+			break;
+		case '\n':
+			*q++ = '\\';
+			*q++ = 'n';
+			break;
+		case '\r':
+			*q++ = '\\';
+			*q++ = 'r';
+			break;
+		case '\b':
+			*q++ = '\\';
+			*q++ = 'b';
+			break;
+		case '\f':
+			*q++ = '\\';
+			*q++ = 'f';
+			break;
+		case '"':
+			*q++ = '\\';
+			*q++ = '"';
+			break;
+		case '\\':
+			*q++ = '\\';
+			*q++ = '\\';
+			break;
+		default:
+			*q++ = *p;
+			break;
+		}
+		p++;
+	}
+	*q = '\0';
 
+	return escaped_string;
+}
 
 
 TrackerClient *
diff --git a/src/libtracker/tracker.h b/src/libtracker/tracker.h
index 9e9f0f9..499cad5 100644
--- a/src/libtracker/tracker.h
+++ b/src/libtracker/tracker.h
@@ -52,6 +52,8 @@ typedef struct {
 
 void	tracker_cancel_last_call (TrackerClient *client);
 
+gchar * tracker_sparql_escape (const gchar *str);
+
 /* you can make multiple connections with tracker_connect and free them with tracker_disconnect */
 TrackerClient * tracker_connect (gboolean enable_warnings);
 void		tracker_disconnect (TrackerClient *client);



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