diff --git a/subprojects/gstreamer/gst/gstutils.c b/subprojects/gstreamer/gst/gstutils.c index 7770cf03c8..f4417cf46d 100644 --- a/subprojects/gstreamer/gst/gstutils.c +++ b/subprojects/gstreamer/gst/gstutils.c @@ -4801,3 +4801,39 @@ gst_type_is_plugin_api (GType type, GstPluginAPIFlags * flags) return ret; } + +/** + * gst_util_filename_compare: + * @a: a filename to compare with @b + * @b: a filename to compare with @a + * + * Compares the given filenames using natural ordering. + * + * Since: 1.24 + */ +gint +gst_util_filename_compare (const gchar * a, const gchar * b) +{ + gchar *a_utf8, *b_utf8; + gchar *a1, *b1; + gint ret; + + /* Filenames in GLib are only guaranteed to be UTF-8 on Windows */ + a_utf8 = g_filename_to_utf8 ((gchar *) a, -1, NULL, NULL, NULL); + b_utf8 = g_filename_to_utf8 ((gchar *) b, -1, NULL, NULL, NULL); + + if (a_utf8 == NULL || b_utf8 == NULL) { + return strcmp (a, b); + } + + a1 = g_utf8_collate_key_for_filename (a_utf8, -1); + b1 = g_utf8_collate_key_for_filename (b_utf8, -1); + ret = strcmp (a1, b1); + g_free (a1); + g_free (b1); + + g_free (a_utf8); + g_free (b_utf8); + + return ret; +} diff --git a/subprojects/gstreamer/gst/gstutils.h b/subprojects/gstreamer/gst/gstutils.h index 7b4ec2e3b4..f42dab843a 100644 --- a/subprojects/gstreamer/gst/gstutils.h +++ b/subprojects/gstreamer/gst/gstutils.h @@ -1243,6 +1243,9 @@ gboolean gst_type_is_plugin_api (GType type, GstPluginAPIFlags * GST_API guint gst_util_ceil_log2 (guint32 v); +GST_API +gint gst_util_filename_compare (const gchar *a, const gchar *b); + G_END_DECLS #endif /* __GST_UTILS_H__ */