XSlice
typedef struct{
const char *ptr;
size_t length;
}XSlice;
typedef struct{
const char *ptr;
size_t length;
}XSlice;
Creates a compile-time string view from a string literal.
#define X_STRVIEW(s) ((XSlice){(s), sizeof(s)-1u})
sXSlice representing the literal contents, excluding the null terminator.
#define x_slice(cstr) (x_slice_init((cstr), strlen(cstr)))
Lexicographically compares two string views.
X_STRING_API int32_t x_slice_cmp(
XSlice a,
XSlice b
);
Negative, zero, or positive according to lexicographic order.
Lexicographically compares two string views case-insensitively.
X_STRING_API int32_t x_slice_cmp_ci(
XSlice a,
XSlice b
);
Function-specific integer result.
Checks whether a string view contains the specified character.
X_STRING_API bool x_slice_contains_char(
XSlice sv,
char c
);
XSlice svchar ctrue if the character is found; false otherwise.
Checks whether a string view contains the specified UTF-8 codepoint.
X_STRING_API bool x_slice_contains_utf8(
XSlice sv,
uint32_t codepoint
);
XSlice svuint32_t codepointtrue if the codepoint is found; false otherwise.
Checks whether a string view ends with the given C-string suffix.
X_STRING_API bool x_slice_ends_with_cstr(
XSlice sv,
const char *prefix
);
XSlice svconst char *prefixtrue if the condition holds; false otherwise.
Compares two string views for equality.
X_STRING_API bool x_slice_eq(
XSlice a,
XSlice b
);
true if the condition holds; false otherwise.
Compares two string views case-insensitively.
X_STRING_API bool x_slice_eq_ci(
XSlice a,
XSlice b
);
true if the condition holds; false otherwise.
Compares a string view with a C-string for equality.
X_STRING_API bool x_slice_eq_cstr(
XSlice a,
const char *b
);
XSlice aconst char *bFunction-specific result.
Finds the first occurrence of a character in a string view.
X_STRING_API int32_t x_slice_find(
XSlice sv,
char c
);
XSlice svchar cIndex on success, or -1 if not found.
Finds the next ASCII whitespace in a string view.
X_STRING_API int32_t x_slice_find_white_space(XSlice sv);
XSlice svIndex on success, or -1 if not found.
Creates a non-owning string view from a null-terminated C-string.
X_STRING_API XSlice x_slice_from_cstr(const char *s);
const char *sXSlice pointing to the provided string, or an empty view if s is NULL.
Creates a non-owning string view from a fixed-capacity small string.
X_STRING_API XSlice x_slice_from_smallstr(const XSmallstr *s);
const XSmallstr *sXSlice referencing the contents of the small string, or an empty view if s is NULL.
Computes a 32-bit FNV hash for a XSlice
X_STRING_API uint32_t x_slice_hash(XSlice slice);
XSlice slice32 bit FNV hash
#define x_slice_init(cstr, len) ((XSlice){.ptr=(cstr), .length=(len)})
Extracts the next token delimited by a character.
X_STRING_API bool x_slice_next_token(
XSlice *input,
char delim,
XSlice *token
);
Function-specific result.
Extracts the next token delimited by ASCII whitespace.
X_STRING_API bool x_slice_next_token_white_space(
XSlice *input,
XSlice *token
);
Function-specific result.
Finds the last occurrence of a character in a string view.
X_STRING_API int32_t x_slice_rfind(
XSlice sv,
char c
);
XSlice svchar cIndex on success, or -1 if not found.
Splits a string view at the first occurrence of a delimiter.
X_STRING_API bool x_slice_split_at(
XSlice sv,
char delim,
XSlice *left,
XSlice *right
);
Function-specific result.
Splits a string view at the first ASCII whitespace.
X_STRING_API bool x_slice_split_at_white_space(
XSlice sv,
XSlice *left,
XSlice *right
);
Function-specific result.
Checks whether a string view starts with the given C-string prefix.
X_STRING_API bool x_slice_starts_with_cstr(
XSlice sv,
const char *prefix
);
XSlice svconst char *prefixtrue if the condition holds; false otherwise.
Creates a sub-view by byte range from a string view.
X_STRING_API XSlice x_slice_substr(
XSlice sv,
size_t start,
size_t len
);
XSlice svsize_t startsize_t lenResulting view after the operation.
Removes leading and trailing ASCII whitespace from a string view.
X_STRING_API XSlice x_slice_trim(XSlice sv);
XSlice svFunction-specific result.
Removes leading ASCII whitespace from a string view.
X_STRING_API XSlice x_slice_trim_left(XSlice sv);
XSlice svFunction-specific result.
Removes trailing ASCII whitespace from a string view.
X_STRING_API XSlice x_slice_trim_right(XSlice sv);
XSlice svResulting view after the operation.