Fri, 06 Jun 2025 15:34:53 +0200
2 files changed,
35 insertions(+),
4 deletions(-)
M
common/string.c
→
common/string.c
@@ -121,3 +121,29 @@
dest[i] = 0; return i; } + +/** + * Compares two strings in a case-sensitive manner. + * + * @param str1 String to be compared + * @param str2 String to be compared + * + * @return 0 if both strings are equal, + * <0 if upper(str1) < upper(str2), + * >0 if upper(str1) > upper(str2) + */ +int sstrcmp(const char *str1, const char *str2) { + int i = 0; + + while (1) { + if (TO_UPPER(str1[i]) != TO_UPPER(str2[i])) { + return TO_UPPER(str1[i]) - TO_UPPER(str2[i]); + } + + if (str1[i] == 0) { + return 0; + } + + i++; + } +}
M
common/string.h
→
common/string.h
@@ -9,6 +9,10 @@
#define NULL ((void*)0) #define WHITESPACE(c) ((c) == ' ' || (c) == '\t') +#define IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z') +#define IS_LOWER(c) ((c) >= 'a' && (c) <= 'z') +#define TO_UPPER(c) (IS_LOWER(c) ? (c) - 'a' + 'A' : c) +#define TO_LOWER(c) (IS_UPPER(c) ? (c) - 'A' + 'a' : c) /*! * Unsigned integral type.@@ -34,10 +38,11 @@ * \return \p ptr is returned.
*/ void *memset (void *ptr, int value, size_t num); -unsigned int strlen (const char *str); -char *strcpy(char *destination, const char *source); -int strcmp(const char *str1, const char *str2); -const char * strchr ( const char * str, int character ); +unsigned int strlen(const char *); +char *strcpy(char *, const char *); +int strcmp(const char *, const char *); +int sstrcmp(const char *, const char *); +const char *strchr (const char *, int); size_t strlstrip(char *, const char *, size_t); size_t strrstrip(char *, const char *, size_t);