Permalink
Browse files

Added str_replace function. To be used for adding variables to user a…

…gent.
  • Loading branch information...
1 parent 01cfcff commit fbf3bbced3165bc67364f20d4ff6c1f994beac3b @barrucadu barrucadu committed May 3, 2009
Showing with 25 additions and 0 deletions.
  1. +22 −0 uzbl.c
  2. +3 −0 uzbl.h
View
22 uzbl.c
@@ -132,6 +132,28 @@ itos(int val) {
return g_strdup(tmp);
}
+static char *
+str_replace (const char* search, const char* replace, const char* string) {
+ char newstring[512];
+ char tempstring[512];
+ unsigned int i = 0;
+
+ memset (newstring, 0, sizeof (newstring));
+
+ for (i = 0; i < strlen (string) - strlen (search); i ++) {
+ memset (tempstring, 0, sizeof (tempstring));
+ strncpy (tempstring, string + i, sizeof (search) + 1);
+
+ if (strcmp (tempstring, search) == 0) {
+ strncpy (newstring, string, i);
+ strcat (newstring, replace);
+ strcat (newstring, string + i + sizeof (search) + 1);
+ }
+ }
+
+ return (char *)newstring;
+}
+
/* --- CALLBACKS --- */
static gboolean
View
3 uzbl.h
@@ -122,4 +122,7 @@ search_text (WebKitWebView *page, const char *param);
static void
run_js (WebKitWebView * web_view, const gchar *param);
+static char *
+str_replace (const char* search, const char* replace, const char* string);
+
/* vi: set et ts=4: */

0 comments on commit fbf3bbc

Please sign in to comment.