CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
C String Utilities

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)
 
int cstrCmpi (const char *s1, const char *s2)
 

Detailed Description

Portable C string helpers for common operations like length, duplication, and comparison. These functions use xalloc for memory allocation and provide optimized implementations.

Function Documentation

◆ cstrCmpi()

int cstrCmpi ( const char *  s1,
const char *  s2 
)

Case-insensitive string comparison.

Compares two strings ignoring case differences.

Parameters
s1First null-terminated string
s2Second null-terminated string
Returns
0 if strings are equal (ignoring case), negative if s1 < s2, positive if s1 > s2

◆ cstrDup()

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().

Parameters
sNull-terminated string to duplicate, or NULL
Returns
Newly allocated copy of the string, or NULL if input was NULL

Referenced by xa_strdup().

◆ cstrDupw()

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().

Parameters
sNull-terminated wide string to duplicate, or NULL
Returns
Newly allocated copy of the wide string, or NULL if input was NULL

◆ cstrLen()

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.

Parameters
sNull-terminated string
Returns
Length of the string in bytes (excluding null terminator)

◆ cstrLenw()

size_t cstrLenw ( const unsigned short *  s)

Compute the length of a null-terminated wide character string.

Parameters
sNull-terminated wide string (unsigned short)
Returns
Length of the string in characters (excluding null terminator)