project_files/frontlib/util/util.h
changeset 7230 240620f46dd7
parent 7227 1c859f572d72
child 7269 5b0aeef8ba2a
--- a/project_files/frontlib/util/util.h	Tue Jun 12 21:10:11 2012 +0200
+++ b/project_files/frontlib/util/util.h	Fri Jun 15 19:57:25 2012 +0200
@@ -3,6 +3,7 @@
 
 #include <stddef.h>
 #include <stdarg.h>
+#include <stdbool.h>
 
 /**
  * Prints a format string to a newly allocated buffer of the required size.
@@ -46,6 +47,12 @@
 void *flib_calloc(size_t count, size_t elementsize);
 
 /**
+ * Simple realloc wrapper that automatically logs an error if no memory
+ * is available. Otherwise behaves exactly like realloc.
+ */
+void *flib_realloc(void *ptr, size_t size);
+
+/**
  * Replace all non-alphanumeric and non-ascii bytes with escape
  * sequences in the form %XX. Does not modify the original string,
  * but returns a newly allocated one that must be free()d. Returns
@@ -56,6 +63,17 @@
 char *flib_urlencode(const char *str);
 
 /**
+ * Replace some bytes with escape sequences in the form %XX.
+ * Does not modify the original string, but returns a newly allocated
+ * one that must be free()d.
+ *
+ * All bytes for which the predicate function returns true are escaped.
+ *
+ * Returns null on failure or if null was passed as argument.
+ */
+char *flib_urlencode_pred(const char *str, bool (*needsEscaping)(char c));
+
+/**
  * Replace escape sequences of the form %XX with their byte values.
  * Does not modify the original string, but returns a newly allocated
  * one that must be free()d. Returns null on failure or if null was