# HG changeset patch # User Mike Becker # Date 1676919342 -3600 # Node ID 3eeadf666d6b1c0a206463c831b824bfa46170c6 # Parent 2ccb9f88142046549278dcca8932b0b6c1ef5e4c add CxListComparator compatible string compare functions diff -r 2ccb9f881420 -r 3eeadf666d6b src/cx/string.h --- 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. diff -r 2ccb9f881420 -r 3eeadf666d6b src/string.c --- 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