GNOME Bugzilla – Bug 65987
There is no g_strreplace() function in glib.
Last modified: 2014-05-10 20:32:41 UTC
There should be a g_strreplace() function in the glib library. Kudos to Elliot! Those are the types of functions that need to be in a decent string handling library. For instance, I'm developing a database application that needs to replace ' with '' in the query before submitting it to the database. The following should be included in gstrfuncs.c. This may not be the most efficient way to write it, but it works for me and will benefit from any improvements to g_strjoinv or g_strsplit. gchar * g_strreplace (gchar * string, gchar * search, gchar * replace) { return (g_strjoinv (replace, g_strsplit (string, search, -1))); } PS - Keep up the good work! Thanks!
Created attachment 30701 [details] [review] proposed patch Patch implements g_strreplace() as suggested (without the leak and with some parameter checking though). Cheers -Tim
Created attachment 30743 [details] [review] new patch Forgot to put prototype into header file; patch also adds a couple of simple tests now. Cheers -Tim
I'm not convinced this kind of oneline function adds sufficient benefit. I'd rather see a more general regexp api which would include string replacement.
*** Bug 665763 has been marked as a duplicate of this bug. ***