[gnome-builder/wip/gtk4-port: 1295/1774] libide/core: add strv sort helper




commit 2170a9c94dd6eed3e866305346a9106baeab856a
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 1 16:18:01 2022 -0700

    libide/core: add strv sort helper
    
    We can probably clean up a few places which can re-use this.

 src/libide/core/ide-macros.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
---
diff --git a/src/libide/core/ide-macros.h b/src/libide/core/ide-macros.h
index ae3043ba0..3268066b7 100644
--- a/src/libide/core/ide-macros.h
+++ b/src/libide/core/ide-macros.h
@@ -282,6 +282,25 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeObjectArray, g_ptr_array_unref)
 
 #define IDE_STRV_INIT(...) ((const char * const[]) { __VA_ARGS__, NULL})
 
+static inline int
+ide_strv_qsort_compare_element (const char * const *a,
+                                const char * const *b,
+                                gpointer            sort_data)
+{
+  return strcmp (*a, *b);
+}
+
+static inline void
+ide_strv_sort (char   **strv,
+               gssize   len)
+{
+  if (len < 0)
+    len = g_strv_length (strv);
+  g_qsort_with_data (strv, len, sizeof (char*),
+                     (GCompareDataFunc)ide_strv_qsort_compare_element,
+                     NULL);
+}
+
 G_END_DECLS
 
 #endif /* __GI_SCANNER__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]