summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <matthiasc@src.gnome.org>2009-01-03 05:10:33 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2009-01-03 05:10:33 +0000
commit889152e4c63e5c4586e2dac40716d2d9d03dcec6 (patch)
tree0ddc04da01abb965cfc80c49d41526b103c1b984
parent34928d8d057ab0ec93649e708071547ea084fa6a (diff)
Add docs
svn path=/trunk/; revision=7762
-rw-r--r--ChangeLog4
-rw-r--r--glib/gregex.c39
2 files changed, 43 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 71522dc5b..97b712c48 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2009-01-02 Matthias Clasen <mclasen@redhat.com>
+ * glib/gregex.c: Add an example to the g_regex_replace_eval() docs.
+
+2009-01-02 Matthias Clasen <mclasen@redhat.com>
+
* glib/gstrfuncs.c: Move docs inline, adding references to g_free()
where appropriate.
diff --git a/glib/gregex.c b/glib/gregex.c
index 31d0323f1..94440efc5 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -2530,6 +2530,45 @@ g_regex_replace_literal (const GRegex *regex,
* string and setting #G_REGEX_MATCH_NOTBOL in the case of a pattern
* that begins with any kind of lookbehind assertion, such as "\b".
*
+ * The following example uses g_regex_replace_eval() to replace multiple
+ * strings at once:
+ * |[
+ * static gboolean
+ * eval_cb (const GMatchInfo *info,
+ * GString *res,
+ * gpointer data)
+ * {
+ * gchar *match;
+ * gchar *r;
+ *
+ * match = g_match_info_fetch (info, 0);
+ * r = g_hash_table_lookup ((GHashTable *)data, match);
+ * g_string_append (res, r);
+ * g_free (match);
+ *
+ * return FALSE;
+ * }
+ *
+ * /&ast; ... &ast;/
+ *
+ * GRegex *reg;
+ * GHashTable *h;
+ * gchar *res;
+ *
+ * h = g_hash_table_new (g_str_hash, g_str_equal);
+ *
+ * g_hash_table_insert (h, "1", "ONE");
+ * g_hash_table_insert (h, "2", "TWO");
+ * g_hash_table_insert (h, "3", "THREE");
+ * g_hash_table_insert (h, "4", "FOUR");
+ *
+ * reg = g_regex_new ("1|2|3|4", 0, 0, NULL);
+ * res = g_regex_replace_eval (reg, text, -1, 0, 0, eval_cb, h, NULL);
+ * g_hash_table_destroy (h);
+ *
+ * /&ast; ... &ast;/
+ * ]|
+ *
* Returns: a newly allocated string containing the replacements
*
* Since: 2.14