|
CX Framework
Cross-platform C utility framework
|
Functions | |
| size_t | cstrLen (const char *s) |
| char * | cstrDup (const char *s) |
| size_t | cstrLenw (const unsigned short *s) |
| unsigned short * | cstrDupw (const unsigned short *s) |
| bool | cstrEq (const char *s1, const char *s2) |
| int | cstrCmp (const char *s1, const char *s2) |
| int | cstrCmpi (const char *s1, const char *s2) |
Portable C string helpers for common operations like length, duplication, and comparison. These functions use xalloc for memory allocation and provide optimized implementations.
| int cstrCmp | ( | const char * | s1, |
| const char * | s2 | ||
| ) |
Compares two null-terminated strings.
Bytes are compared as unsigned, consistent with memcmp() and cstrCmpi(). Either string may be NULL, which sorts before any non-NULL string.
| s1 | First null-terminated string, or NULL |
| s2 | Second null-terminated string, or NULL |
Example:
| int cstrCmpi | ( | const char * | s1, |
| const char * | s2 | ||
| ) |
Case-insensitive string comparison.
Compares two strings ignoring case differences.
| s1 | First null-terminated string |
| s2 | Second null-terminated string |
| char * cstrDup | ( | const char * | s | ) |
Duplicate a null-terminated C string.
Allocates memory using xaAlloc and copies the string. The returned string must be freed with xaFree() or xaDestroy().
| s | Null-terminated string to duplicate, or NULL |
Referenced by xa_strdup().
| unsigned short * cstrDupw | ( | const unsigned short * | s | ) |
Duplicate a null-terminated wide character string.
Allocates memory using xaAlloc and copies the wide string. The returned string must be freed with xaFree() or xaDestroy().
| s | Null-terminated wide string to duplicate, or NULL |
| bool cstrEq | ( | const char * | s1, |
| const char * | s2 | ||
| ) |
Tests two null-terminated strings for equality.
Either string may be NULL, which compares equal only to another NULL.
| s1 | First null-terminated string, or NULL |
| s2 | Second null-terminated string, or NULL |
Example:
| size_t cstrLen | ( | const char * | s | ) |
Efficiently compute the length of a null-terminated C string.
This uses an optimized word-aligned algorithm for better performance than standard strlen on most architectures.
| s | Null-terminated string |
| size_t cstrLenw | ( | const unsigned short * | s | ) |
Compute the length of a null-terminated wide character string.
| s | Null-terminated wide string (unsigned short) |