summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2021-04-25 02:33:24 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2021-04-27 16:25:09 +0200
commitfbb198f968eb5542a270039c17773164a6621a6a (patch)
treedec1425a33d252f1f88e68f752b1ecc72c547725
parentb8a9f4b43637eb60ab149693c5b09744be4da60f (diff)
downloadglib-fbb198f968eb5542a270039c17773164a6621a6a.tar.gz
gpattern: Move match and match_string functions into GPatternSpec
This allows introspection to properly handle them as GPatternSpec methods, as per this deprecate g_pattern_match() and g_pattern_match_string() functions.
-rw-r--r--docs/reference/glib/glib-sections.txt2
-rw-r--r--glib/gpattern.c81
-rw-r--r--glib/gpattern.h12
-rw-r--r--glib/tests/pattern.c6
4 files changed, 89 insertions, 12 deletions
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 3a96ba789..482b01b51 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1426,6 +1426,8 @@ g_pattern_spec_new
g_pattern_spec_free
g_pattern_spec_equal
g_pattern_spec_copy
+g_pattern_spec_match
+g_pattern_spec_match_string
g_pattern_match
g_pattern_match_string
g_pattern_match_simple
diff --git a/glib/gpattern.c b/glib/gpattern.c
index 24001002a..138cebd93 100644
--- a/glib/gpattern.c
+++ b/glib/gpattern.c
@@ -158,7 +158,7 @@ g_pattern_ph_match (const gchar *match_pattern,
}
/**
- * g_pattern_match:
+ * g_pattern_spec_match:
* @pspec: a #GPatternSpec
* @string_length: the length of @string (in bytes, i.e. strlen(),
* not g_utf8_strlen())
@@ -184,12 +184,14 @@ g_pattern_ph_match (const gchar *match_pattern,
* g_utf8_strreverse() function to reverse UTF-8 encoded strings.
*
* Returns: %TRUE if @string matches @pspec
+ *
+ * Since: 2.70
**/
gboolean
-g_pattern_match (GPatternSpec *pspec,
- guint string_length,
- const gchar *string,
- const gchar *string_reversed)
+g_pattern_spec_match (GPatternSpec *pspec,
+ gsize string_length,
+ const gchar *string,
+ const gchar *string_reversed)
{
g_return_val_if_fail (pspec != NULL, FALSE);
g_return_val_if_fail (string != NULL, FALSE);
@@ -239,6 +241,44 @@ g_pattern_match (GPatternSpec *pspec,
}
/**
+ * g_pattern_match: (skip)
+ * @pspec: a #GPatternSpec
+ * @string_length: the length of @string (in bytes, i.e. strlen(),
+ * not g_utf8_strlen())
+ * @string: the UTF-8 encoded string to match
+ * @string_reversed: (nullable): the reverse of @string or %NULL
+ *
+ * Matches a string against a compiled pattern. Passing the correct
+ * length of the string given is mandatory. The reversed string can be
+ * omitted by passing %NULL, this is more efficient if the reversed
+ * version of the string to be matched is not at hand, as
+ * g_pattern_match() will only construct it if the compiled pattern
+ * requires reverse matches.
+ *
+ * Note that, if the user code will (possibly) match a string against a
+ * multitude of patterns containing wildcards, chances are high that
+ * some patterns will require a reversed string. In this case, it's
+ * more efficient to provide the reversed string to avoid multiple
+ * constructions thereof in the various calls to g_pattern_match().
+ *
+ * Note also that the reverse of a UTF-8 encoded string can in general
+ * not be obtained by g_strreverse(). This works only if the string
+ * does not contain any multibyte characters. GLib offers the
+ * g_utf8_strreverse() function to reverse UTF-8 encoded strings.
+ *
+ * Returns: %TRUE if @string matches @pspec
+ * Deprecated: 2.70: Use g_pattern_spec_match() instead
+ **/
+gboolean
+g_pattern_match (GPatternSpec *pspec,
+ guint string_length,
+ const gchar *string,
+ const gchar *string_reversed)
+{
+ return g_pattern_spec_match (pspec, string_length, string, string_reversed);
+}
+
+/**
* g_pattern_spec_new:
* @pattern: a zero-terminated UTF-8 encoded string
*
@@ -416,7 +456,7 @@ g_pattern_spec_equal (GPatternSpec *pspec1,
}
/**
- * g_pattern_match_string:
+ * g_pattern_spec_match_string:
* @pspec: a #GPatternSpec
* @string: the UTF-8 encoded string to match
*
@@ -425,15 +465,36 @@ g_pattern_spec_equal (GPatternSpec *pspec1,
* g_pattern_match() instead while supplying the reversed string.
*
* Returns: %TRUE if @string matches @pspec
+ *
+ * Since: 2.70
**/
gboolean
-g_pattern_match_string (GPatternSpec *pspec,
- const gchar *string)
+g_pattern_spec_match_string (GPatternSpec *pspec,
+ const gchar *string)
{
g_return_val_if_fail (pspec != NULL, FALSE);
g_return_val_if_fail (string != NULL, FALSE);
- return g_pattern_match (pspec, strlen (string), string, NULL);
+ return g_pattern_spec_match (pspec, strlen (string), string, NULL);
+}
+
+/**
+ * g_pattern_match_string: (skip)
+ * @pspec: a #GPatternSpec
+ * @string: the UTF-8 encoded string to match
+ *
+ * Matches a string against a compiled pattern. If the string is to be
+ * matched against more than one pattern, consider using
+ * g_pattern_match() instead while supplying the reversed string.
+ *
+ * Returns: %TRUE if @string matches @pspec
+ * Deprecated: 2.70: Use g_pattern_spec_match_string() instead
+ **/
+gboolean
+g_pattern_match_string (GPatternSpec *pspec,
+ const gchar *string)
+{
+ return g_pattern_spec_match_string (pspec, string);
}
/**
@@ -459,7 +520,7 @@ g_pattern_match_simple (const gchar *pattern,
g_return_val_if_fail (string != NULL, FALSE);
pspec = g_pattern_spec_new (pattern);
- ergo = g_pattern_match (pspec, strlen (string), string, NULL);
+ ergo = g_pattern_spec_match (pspec, strlen (string), string, NULL);
g_pattern_spec_free (pspec);
return ergo;
diff --git a/glib/gpattern.h b/glib/gpattern.h
index d69799cdd..2d7f83077 100644
--- a/glib/gpattern.h
+++ b/glib/gpattern.h
@@ -38,12 +38,20 @@ GPatternSpec *g_pattern_spec_copy (GPatternSpec *pspec);
GLIB_AVAILABLE_IN_ALL
gboolean g_pattern_spec_equal (GPatternSpec *pspec1,
GPatternSpec *pspec2);
-GLIB_AVAILABLE_IN_ALL
+GLIB_AVAILABLE_IN_2_70
+gboolean g_pattern_spec_match (GPatternSpec *pspec,
+ gsize string_length,
+ const gchar *string,
+ const gchar *string_reversed);
+GLIB_AVAILABLE_IN_2_70
+gboolean g_pattern_spec_match_string (GPatternSpec *pspec,
+ const gchar *string);
+GLIB_DEPRECATED_IN_2_70_FOR (g_pattern_spec_match)
gboolean g_pattern_match (GPatternSpec *pspec,
guint string_length,
const gchar *string,
const gchar *string_reversed);
-GLIB_AVAILABLE_IN_ALL
+GLIB_DEPRECATED_IN_2_70_FOR (g_pattern_spec_match_string)
gboolean g_pattern_match_string (GPatternSpec *pspec,
const gchar *string);
GLIB_AVAILABLE_IN_ALL
diff --git a/glib/tests/pattern.c b/glib/tests/pattern.c
index ef807fbde..0ff915681 100644
--- a/glib/tests/pattern.c
+++ b/glib/tests/pattern.c
@@ -176,10 +176,16 @@ test_match (gconstpointer d)
g_assert_cmpint (g_pattern_match_simple (test->pattern, test->string), ==, test->match);
p = g_pattern_spec_new (test->pattern);
+ g_assert_cmpint (g_pattern_spec_match_string (p, test->string), ==, test->match);
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_cmpint (g_pattern_match_string (p, test->string), ==, test->match);
+ G_GNUC_END_IGNORE_DEPRECATIONS
r = g_utf8_strreverse (test->string, -1);
+ g_assert_cmpint (g_pattern_spec_match (p, strlen (test->string), test->string, r), ==, test->match);
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_cmpint (g_pattern_match (p, strlen (test->string), test->string, r), ==, test->match);
+ G_GNUC_END_IGNORE_DEPRECATIONS
g_free (r);
g_pattern_spec_free (p);