Mon, 20 Feb 2023 19:55:42 +0100
add CxListComparator compatible string compare functions
src/cx/string.h | file | annotate | diff | comparison | revisions | |
src/string.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/cx/string.h Mon Feb 20 19:14:42 2023 +0100 1.2 +++ b/src/cx/string.h Mon Feb 20 19:55:42 2023 +0100 1.3 @@ -657,6 +657,38 @@ 1.4 cxstring s2 1.5 ); 1.6 1.7 +/** 1.8 + * Compares two strings. 1.9 + * 1.10 + * This function has a compatible signature for the use as a CxListComparator. 1.11 + * 1.12 + * @param s1 the first string 1.13 + * @param s2 the second string 1.14 + * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 1.15 + * than \p s2, zero if both strings equal 1.16 + */ 1.17 +__attribute__((__warn_unused_result__, __nonnull__)) 1.18 +int cx_strcmp_p( 1.19 + void const *s1, 1.20 + void const *s2 1.21 +); 1.22 + 1.23 +/** 1.24 + * Compares two strings ignoring case. 1.25 + * 1.26 + * This function has a compatible signature for the use as a CxListComparator. 1.27 + * 1.28 + * @param s1 the first string 1.29 + * @param s2 the second string 1.30 + * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 1.31 + * than \p s2, zero if both strings equal ignoring case 1.32 + */ 1.33 +__attribute__((__warn_unused_result__, __nonnull__)) 1.34 +int cx_strcasecmp_p( 1.35 + void const *s1, 1.36 + void const *s2 1.37 +); 1.38 + 1.39 1.40 /** 1.41 * Creates a duplicate of the specified string.
2.1 --- a/src/string.c Mon Feb 20 19:14:42 2023 +0100 2.2 +++ b/src/string.c Mon Feb 20 19:55:42 2023 +0100 2.3 @@ -451,6 +451,24 @@ 2.4 } 2.5 } 2.6 2.7 +int cx_strcmp_p( 2.8 + void const *s1, 2.9 + void const *s2 2.10 +) { 2.11 + cxstring const *left = s1; 2.12 + cxstring const *right = s2; 2.13 + return cx_strcmp(*left, *right); 2.14 +} 2.15 + 2.16 +int cx_strcasecmp_p( 2.17 + void const *s1, 2.18 + void const *s2 2.19 +) { 2.20 + cxstring const *left = s1; 2.21 + cxstring const *right = s2; 2.22 + return cx_strcasecmp(*left, *right); 2.23 +} 2.24 + 2.25 cxmutstr cx_strdup_a( 2.26 CxAllocator *allocator, 2.27 cxstring string