[tracker/libtracker-sparql: 20/56] libtracker-sparql: Added utils file for escaping mostly



commit 5540a7b302c06099f2328cb6779c0b70a7ef5788
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Jul 13 17:35:40 2010 +0100

    libtracker-sparql: Added utils file for escaping mostly

 src/libtracker-sparql/Makefile.am        |    3 +-
 src/libtracker-sparql/tracker-utils.vala |   59 ++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-sparql/Makefile.am b/src/libtracker-sparql/Makefile.am
index c97f598..fdaf172 100644
--- a/src/libtracker-sparql/Makefile.am
+++ b/src/libtracker-sparql/Makefile.am
@@ -14,11 +14,12 @@ lib_LTLIBRARIES = libtracker-sparql- TRACKER_API_VERSION@.la
 libtracker_sparqlincludedir = $(includedir)/tracker-$(TRACKER_API_VERSION)/libtracker-sparql
 
 libtracker_sparql_la_VALASOURCES = 			\
+	tracker-builder.vala					\
 	tracker-connection.vala					\
 	tracker-cursor.vala						\
 	tracker-plugin-loader.vala				\
 	tracker-query.vala						\
-	tracker-builder.vala
+	tracker-utils.vala
 
 libtracker_sparql_ TRACKER_API_VERSION@_la_SOURCES = 	\
 	libtracker-sparql.vala.stamp			\
diff --git a/src/libtracker-sparql/tracker-utils.vala b/src/libtracker-sparql/tracker-utils.vala
new file mode 100644
index 0000000..198a3c5
--- /dev/null
+++ b/src/libtracker-sparql/tracker-utils.vala
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+public unowned string tracker_sparql_escape_string (string literal) {
+	StringBuilder str = new StringBuilder ();
+	char *p = literal;
+
+	while (*p != '\0') {
+		size_t len = Posix.strcspn ((string) p, "\t\n\r\"\\");
+		str.append_len ((string) p, (long) len);
+		p += len;
+
+		switch (*p) {
+		case '\t':
+			str.append ("\\t");
+			break;
+		case '\n':
+			str.append ("\\n");
+			break;
+		case '\r':
+			str.append ("\\r");
+			break;
+		case '\b':
+			str.append ("\\b");
+			break;
+		case '\f':
+			str.append ("\\f");
+			break;
+		case '"':
+			str.append ("\\\"");
+			break;
+		case '\\':
+			str.append ("\\\\");
+			break;
+		default:
+			continue;
+		}
+
+		p++;
+	}
+
+	return str.str;
+}



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