Skip to content

Commit

Permalink
Document rz_str_cmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Oct 23, 2024
1 parent 2e0d056 commit 8dbba03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion librz/include/rz_util/rz_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ RZ_API RZ_OWN char *rz_sub_str_ptr(RZ_NONNULL const char *str, RZ_NONNULL const
RZ_API char *rz_str_ichr(char *str, char chr);
RZ_API bool rz_str_ccmp(const char *dst, const char *orig, int ch);
RZ_API bool rz_str_cmp_list(const char *list, const char *item, char sep);
RZ_API int rz_str_cmp(const char *dst, const char *orig, int len);
RZ_API int rz_str_cmp(RZ_NULLABLE const char *dst, RZ_NULLABLE const char *orig, int len);
RZ_API int rz_str_casecmp(const char *dst, const char *orig);
RZ_API int rz_str_ncasecmp(const char *dst, const char *orig, size_t n);
RZ_API int rz_str_ccpy(char *dst, char *orig, int ch);
Expand Down
14 changes: 12 additions & 2 deletions librz/util/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,18 @@ RZ_API bool rz_str_cmp_list(const char *list, const char *item, char sep) {
return true;
}

// like strncmp, but checking for null pointers
RZ_API int rz_str_cmp(const char *a, const char *b, int len) {
/**
* \brief Like strncmp, but checking for null pointers.
*
* \param a String a.
* \param b String b.
* \param len The number of characters to compare. If -1 it compares until the end.
*
* \return Negative value, if a < b
* \return 0, if a == b.
* \return Positive value, if a > b
*/
RZ_API int rz_str_cmp(RZ_NULLABLE const char *a, RZ_NULLABLE const char *b, int len) {
if ((a == b) || (!a && !b)) {
return 0;
}
Expand Down

0 comments on commit 8dbba03

Please sign in to comment.