add CxListComparator compatible string compare functions

Mon, 20 Feb 2023 19:55:42 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 20 Feb 2023 19:55:42 +0100
changeset 657
3eeadf666d6b
parent 656
2ccb9f881420
child 658
56c62780582e

add CxListComparator compatible string compare functions

src/cx/string.h file | annotate | diff | comparison | revisions
src/string.c file | annotate | diff | comparison | revisions
--- a/src/cx/string.h	Mon Feb 20 19:14:42 2023 +0100
+++ b/src/cx/string.h	Mon Feb 20 19:55:42 2023 +0100
@@ -657,6 +657,38 @@
         cxstring s2
 );
 
+/**
+ * Compares two strings.
+ *
+ * This function has a compatible signature for the use as a CxListComparator.
+ *
+ * @param s1 the first string
+ * @param s2 the second string
+ * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger
+ * than \p s2, zero if both strings equal
+ */
+__attribute__((__warn_unused_result__, __nonnull__))
+int cx_strcmp_p(
+        void const *s1,
+        void const *s2
+);
+
+/**
+ * Compares two strings ignoring case.
+ *
+ * This function has a compatible signature for the use as a CxListComparator.
+ *
+ * @param s1 the first string
+ * @param s2 the second string
+ * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger
+ * than \p s2, zero if both strings equal ignoring case
+ */
+__attribute__((__warn_unused_result__, __nonnull__))
+int cx_strcasecmp_p(
+        void const *s1,
+        void const *s2
+);
+
 
 /**
  * Creates a duplicate of the specified string.
--- a/src/string.c	Mon Feb 20 19:14:42 2023 +0100
+++ b/src/string.c	Mon Feb 20 19:55:42 2023 +0100
@@ -451,6 +451,24 @@
     }
 }
 
+int cx_strcmp_p(
+        void const *s1,
+        void const *s2
+) {
+    cxstring const *left = s1;
+    cxstring const *right = s2;
+    return cx_strcmp(*left, *right);
+}
+
+int cx_strcasecmp_p(
+        void const *s1,
+        void const *s2
+) {
+    cxstring const *left = s1;
+    cxstring const *right = s2;
+    return cx_strcasecmp(*left, *right);
+}
+
 cxmutstr cx_strdup_a(
         CxAllocator *allocator,
         cxstring string

mercurial