[vte] widget: Add introspectable variant of vte_terminal_event_check_regex_simple
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] widget: Add introspectable variant of vte_terminal_event_check_regex_simple
- Date: Tue, 28 Apr 2020 18:53:03 +0000 (UTC)
commit 8ba1ed5c6ece5efae8258723b60bc3b5a24de25f
Author: Christian Persch <chpe src gnome org>
Date: Tue Apr 28 20:52:35 2020 +0200
widget: Add introspectable variant of vte_terminal_event_check_regex_simple
Based on a patch by Phil Clayton <phil clayton veonix com>
Fixes: https://gitlab.gnome.org/GNOME/vte/issues/228
doc/reference/vte-sections.txt | 1 +
src/vte/vteterminal.h | 7 ++++++
src/vtegtk.cc | 49 +++++++++++++++++++++++++++++++++++++++---
3 files changed, 54 insertions(+), 3 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 482b2a98..543d377d 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -89,6 +89,7 @@ vte_terminal_search_get_regex
vte_terminal_search_get_wrap_around
vte_terminal_search_set_regex
vte_terminal_search_set_wrap_around
+vte_terminal_event_check_regex_array
vte_terminal_event_check_regex_simple
<SUBSECTION>
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index 6bb2e0f7..812e4476 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -420,6 +420,13 @@ char *vte_terminal_match_check_event(VteTerminal *terminal,
GdkEvent *event,
int *tag) _VTE_GNUC_NONNULL(1) _VTE_GNUC_NONNULL(2) G_GNUC_MALLOC;
_VTE_PUBLIC
+char **vte_terminal_event_check_regex_array(VteTerminal *terminal,
+ GdkEvent *event,
+ VteRegex **regexes,
+ gsize n_regexes,
+ guint32 match_flags,
+ gsize *n_matches) _VTE_GNUC_NONNULL(1) _VTE_GNUC_NONNULL(2)
G_GNUC_MALLOC;
+_VTE_PUBLIC
gboolean vte_terminal_event_check_regex_simple(VteTerminal *terminal,
GdkEvent *event,
VteRegex **regexes,
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index aba6f590..622b742b 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -2264,18 +2264,61 @@ vte_terminal_hyperlink_check_event(VteTerminal *terminal,
}
/**
- * vte_terminal_event_check_regex_simple:
+ * vte_terminal_event_check_regex_array: (rename-to vte_terminal_event_check_regex_simple)
* @terminal: a #VteTerminal
* @event: a #GdkEvent
* @regexes: (array length=n_regexes): an array of #VteRegex
* @n_regexes: number of items in @regexes
* @match_flags: PCRE2 match flags, or 0
- * @matches: (out caller-allocates) (array length=n_regexes): a location to store the matches
+ * @n_matches: (out) (nullable): number of items in @matches, which is always equal to @n_regexes
+ *
+ * Like vte_terminal_event_check_regex_simple(), but returns an array of strings,
+ * containing the matching text (or %NULL if no match) corresponding to each of the
+ * regexes in @regexes.
+ *
+ * You must free each string and the array; but note that this is *not* a %NULL-terminated
+ * string array, and so you must *not* use g_strfreev() on it.
+ *
+ * Returns: (transfer full) (array length=n_matches): a newly allocated array of strings,
+ * or %NULL if none of the regexes matched
+ *
+ * Since: 0.62
+ */
+char**
+vte_terminal_event_check_regex_array(VteTerminal *terminal,
+ GdkEvent *event,
+ VteRegex **regexes,
+ gsize n_regexes,
+ guint32 match_flags,
+ gsize *n_matches)
+{
+ auto matches = vte::glib::take_free_ptr(g_new0(char*, n_regexes));
+ if (n_matches)
+ *n_matches = n_regexes;
+
+ auto const rv = vte_terminal_event_check_regex_simple(terminal,
+ event,
+ regexes,
+ n_regexes,
+ match_flags,
+ matches.get());
+ return rv ? matches.release() : nullptr;
+}
+
+/**
+ * vte_terminal_event_check_regex_simple: (skip)
+ * @terminal: a #VteTerminal
+ * @event: a #GdkEvent
+ * @regexes: (array length=n_regexes): an array of #VteRegex
+ * @n_regexes: number of items in @regexes
+ * @match_flags: PCRE2 match flags, or 0
+ * @matches: (out caller-allocates) (array length=n_regexes) (transfer full): a location to store the matches
*
* Checks each regex in @regexes if the text in and around the position of
* the event matches the regular expressions. If a match exists, the matched
* text is stored in @matches at the position of the regex in @regexes; otherwise
- * %NULL is stored there.
+ * %NULL is stored there. Each non-%NULL element of @matches should be freed with
+ * g_free().
*
* Note that the regexes in @regexes should have been created using the %PCRE2_MULTILINE flag.
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]