Macro

X_STRING_VERSION_MAJOR

#define X_STRING_VERSION_MAJOR 1
Macro

X_STRING_VERSION_MINOR

#define X_STRING_VERSION_MINOR 0
Macro

X_STRING_VERSION_PATCH

#define X_STRING_VERSION_PATCH 0
Macro

X_SMALLSTR_MAX_LENGTH

#define X_SMALLSTR_MAX_LENGTH 256
Struct

XSlice

typedef struct{
  const char *ptr;
  size_t length;
}XSlice;
Struct

XWStrview

typedef struct{
  const wchar_t *ptr;
  size_t length;
}XWStrview;
Enum

XUtf8Error

typedef enum XUtf8Error{
  X_UTF8_OK=0,
  X_UTF8_ERR_EOF=-1,
  X_UTF8_ERR_INVALID=-2,
  X_UTF8_ERR_OVERLONG=-3,
  X_UTF8_ERR_RANGE=-4
}XUtf8Error;
Function

x_set_locale

Sets the process locale used by locale-aware string operations.

X_STRING_API void x_set_locale(const char *locale);

Parameters

const char *locale
Parameter.

Returns

No return value.

Function

x_cstr_hash

Computes a 32-bit FNV hash for a null-terminated C-string.

X_STRING_API uint32_t x_cstr_hash(const char *str);

Parameters

const char *str
Input C-string.

Returns

32 bit FNV hash

Function

x_cstr_str

Searches for a substring within a null-terminated C-string.

X_STRING_API char * x_cstr_str(
 const char *haystack,
 const char *needle
);

Parameters

const char *haystack
Input string to search in.
const char *needle
Substring to search for.

Returns

pointer within haystack where needle is found

Function

x_cstr_ends_with

Checks whether the string ends with the specified suffix.

X_STRING_API bool x_cstr_ends_with(
 const char *str,
 const char *suffix
);

Parameters

const char *str
Input C-string.
const char *suffix
Suffix to match.

Returns

true if the condition holds; false otherwise.

Function

x_cstr_starts_with

Checks whether a null-terminated C-string starts with the given prefix.

X_STRING_API bool x_cstr_starts_with(
 const char *str,
 const char *prefix
);

Parameters

const char *str
Input C-string.
const char *prefix
Prefix to match.

Returns

true if the condition holds; false otherwise.

Function

x_cstr_ends_with_ci

Case-insensitive check whether the string ends with the specified suffix.

X_STRING_API bool x_cstr_ends_with_ci(
 const char *str,
 const char *suffix
);

Parameters

const char *str
Input C-string.
const char *suffix
Suffix to match.

Returns

true if the condition holds; false otherwise.

Function

x_cstr_starts_with_ci

Checks whether a null-terminated C-string starts with the given prefix.

X_STRING_API bool x_cstr_starts_with_ci(
 const char *str,
 const char *prefix
);

Parameters

const char *str
Input C-string.
const char *prefix
Prefix to match.

Returns

true if the condition holds; false otherwise.

Function

x_wcstr_starts_with

Checks whether the string starts with the specified prefix.

X_STRING_API bool x_wcstr_starts_with(
 const wchar_t *str,
 const wchar_t *prefix
);

Parameters

const wchar_t *str
Input C-string.
const wchar_t *prefix
Prefix to match.

Returns

true if the condition holds; false otherwise.

Function

x_wcstr_ends_with

Checks whether a null-terminated wide C-string ends with the given suffix.

X_STRING_API bool x_wcstr_ends_with(
 const wchar_t *str,
 const wchar_t *suffix
);

Parameters

const wchar_t *str
Input C-string.
const wchar_t *suffix
Suffix to match.

Returns

true if the condition holds; false otherwise.

Function

x_wcstr_starts_with_ci

Case-insensitive check whether the string starts with the specified prefix.

X_STRING_API bool x_wcstr_starts_with_ci(
 const wchar_t *str,
 const wchar_t *prefix
);

Parameters

const wchar_t *str
Input C-string.
const wchar_t *prefix
Prefix to match.

Returns

true if the condition holds; false otherwise.

Function

x_wcstr_ends_with_ci

Checks whether a null-terminated wide C-string ends with the given suffix.

X_STRING_API bool x_wcstr_ends_with_ci(
 const wchar_t *str,
 const wchar_t *suffix
);

Parameters

const wchar_t *str
Input C-string.
const wchar_t *suffix
Suffix to match.

Returns

true if the condition holds; false otherwise.

Function

x_wcstr_cicmp

Case-insensitively compares two wide C-strings.

X_STRING_API int32_t x_wcstr_cicmp(
 const wchar_t *a,
 const wchar_t *b
);

Parameters

const wchar_t *a
First input view or string.
const wchar_t *b
Second input view or string.

Returns

Function-specific integer result.

Function

x_cstr_to_wcstr

Utility for null-terminated C-strings.

X_STRING_API size_t x_cstr_to_wcstr(
 const char *src,
 wchar_t *dest,
 size_t max
);

Parameters

const char *src
Source buffer or string.
wchar_t *dest
Destination buffer.
size_t max
Capacity of the destination buffer (in elements).

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_wcstr_to_utf8

Converts between string encodings.

X_STRING_API size_t x_wcstr_to_utf8(
 const wchar_t *wide,
 char *utf8,
 size_t max
);

Parameters

const wchar_t *wide
Destination wide-character buffer.
char *utf8
Source UTF-8 string.
size_t max
Capacity of the destination buffer (in elements).

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_wcstr_to_cstr

Utility for null-terminated wide C-strings.

X_STRING_API size_t x_wcstr_to_cstr(
 const wchar_t *src,
 char *dest,
 size_t max
);

Parameters

const wchar_t *src
Source buffer or string.
char *dest
Destination buffer.
size_t max
Capacity of the destination buffer (in elements).

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_utf8_to_wcstr

Converts between string encodings.

X_STRING_API size_t x_utf8_to_wcstr(
 const char *utf8,
 wchar_t *wide,
 size_t max
);

Parameters

const char *utf8
Source UTF-8 string.
wchar_t *wide
Destination wide-character buffer.
size_t max
Capacity of the destination buffer (in elements).

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_utf8_strlen

Returns the number of UTF-8 codepoints in a null-terminated string.

X_STRING_API size_t x_utf8_strlen(const char *utf8);

Parameters

const char *utf8
Source UTF-8 string.

Returns

Number of UTF-8 codepoints.

Function

x_utf8_strcmp

Compares two null-terminated UTF-8 strings.

X_STRING_API int32_t x_utf8_strcmp(
 const char *a,
 const char *b
);

Parameters

const char *a
First input view or string.
const char *b
Second input view or string.

Returns

Negative, zero, or positive according to lexicographic order.

Function

x_utf8_tolower

Converts ASCII letters to lower case; leaves multibyte UTF-8 unchanged.

X_STRING_API char * x_utf8_tolower(
 char *dest,
 const char *src
);

Parameters

char *dest
Destination buffer.
const char *src
Source buffer or string.

Returns

Function-specific result.

Function

x_utf8_toupper

Converts ASCII letters to upper case; leaves multibyte UTF-8 unchanged.

X_STRING_API char * x_utf8_toupper(
 char *dest,
 const char *src
);

Parameters

char *dest
Destination buffer.
const char *src
Source buffer or string.

Returns

Function-specific result.

Function

x_utf8_is_single_char

Checks whether the string contains exactly one UTF-8 codepoint.

X_STRING_API bool x_utf8_is_single_char(const char *s);

Parameters

const char *s
Destination small string.

Returns

Function-specific result.

Function

x_utf8_decode

Decodes a single UTF-8 codepoint from the specified byte span.

X_STRING_API int32_t x_utf8_decode(
 const char *ptr,
 const char *end,
 size_t *out_len
);

Parameters

const char *ptr
Current read pointer within the byte span.
const char *end
One-past-the-end pointer for the byte span.
size_t *out_len
Output: number of codepoints consumed on success or bytes to skip on error.

Returns

Decoded codepoint on success; negative X_UTF8_ERR_* on failure.

Function

x_utf8_codepoint_length

Returns the expected byte length for a UTF-8 starter byte.

X_STRING_API int32_t x_utf8_codepoint_length(unsigned char first_byte);

Parameters

unsigned char first_byte
Parameter.

Returns

1..4 for a valid starter byte; negative error code if invalid.

Function

x_smallstr_init

Initializes a fixed-capacity small string from a source C-string.

X_STRING_API int32_t x_smallstr_init(
 XSmallstr *s,
 const char *str
);

Parameters

XSmallstr *s
Destination small string.
const char *str
Input C-string.

Returns

Function-specific integer result.

Function

x_smallstr_format

Formats text into a small string; truncates if necessary.

X_STRING_API size_t x_smallstr_format(
 XSmallstr *s,
 const char *fmt,
 ...
);

Parameters

XSmallstr *s
Destination small string.
const char *fmt
printf-style format string.
param
Variadic arguments list.

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_smallstr_from_cstr

Copies a null-terminated C-string into a small string.

X_STRING_API size_t x_smallstr_from_cstr(
 XSmallstr *s,
 const char *cstr
);

Parameters

XSmallstr *s
Destination small string.
const char *cstr
Source null-terminated C-string.

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_smallstr_from_slice

Copies a string view into a small string.

X_STRING_API size_t x_smallstr_from_slice(
 XSlice sv,
 XSmallstr *out
);

Parameters

XSlice sv
String view input.
XSmallstr *out
Parameter.

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_smallstr_to_slice

Creates a non-owning view over a small string's contents.

X_STRING_API XSlice x_smallstr_to_slice(const XSmallstr *s);

Parameters

const XSmallstr *s
Destination small string.

Returns

Resulting view after the operation.

Function

x_smallstr_length

Returns the current byte length of the small string.

X_STRING_API size_t x_smallstr_length(const XSmallstr *s);

Parameters

const XSmallstr *s
Destination small string.

Returns

Number of elements in the string (excluding the final terminator).

Function

x_smallstr_clear

Clears the small string to empty.

X_STRING_API void x_smallstr_clear(XSmallstr *s);

Parameters

XSmallstr *s
Destination small string.

Returns

No return value.

Function

x_smallstr_append_cstr

Appends a null-terminated C-string if space allows.

X_STRING_API size_t x_smallstr_append_cstr(
 XSmallstr *s,
 const char *cstr
);

Parameters

XSmallstr *s
Destination small string.
const char *cstr
Source null-terminated C-string.

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_smallstr_append_char

Appends a single character if space allows.

X_STRING_API size_t x_smallstr_append_char(
 XSmallstr *s,
 char c
);

Parameters

XSmallstr *s
Destination small string.
char c
Character value.

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_smallstr_substring

Copies a byte-range substring into a small string.

X_STRING_API size_t x_smallstr_substring(
 const XSmallstr *s,
 size_t start,
 size_t len,
 XSmallstr *out
);

Parameters

const XSmallstr *s
Destination small string.
size_t start
Starting offset (0-based).
size_t len
Number of units to copy or inspect.
XSmallstr *out
Parameter.

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_smallstr_trim_left

Trims leading ASCII whitespace in a small string.

X_STRING_API void x_smallstr_trim_left(XSmallstr *s);

Parameters

XSmallstr *s
Destination small string.

Returns

Resulting view after the operation.

Function

x_smallstr_trim_right

Trims trailing ASCII whitespace in a small string.

X_STRING_API void x_smallstr_trim_right(XSmallstr *s);

Parameters

XSmallstr *s
Destination small string.

Returns

No return value.

Function

x_smallstr_trim

Trims leading and trailing ASCII whitespace in a small string.

X_STRING_API void x_smallstr_trim(XSmallstr *s);

Parameters

XSmallstr *s
Destination small string.

Returns

Resulting view after the operation.

Function

x_smallstr_cmp_ci

Compares two small strings case-insensitively.

X_STRING_API int32_t x_smallstr_cmp_ci(
 const XSmallstr *a,
 const XSmallstr *b
);

Parameters

const XSmallstr *a
First input view or string.
const XSmallstr *b
Second input view or string.

Returns

Negative, zero, or positive according to lexicographic order.

Function

x_smallstr_replace_all

Replaces all occurrences of a substring in a small string.

X_STRING_API int32_t x_smallstr_replace_all(
 XSmallstr *s,
 const char *find,
 const char *replace
);

Parameters

XSmallstr *s
Destination small string.
const char *find
Substring to be replaced.
const char *replace
Replacement substring.

Returns

Function-specific integer result.

Function

x_smallstr_utf8_len

Counts UTF-8 codepoints in a small string.

X_STRING_API size_t x_smallstr_utf8_len(const XSmallstr *s);

Parameters

const XSmallstr *s
Destination small string.

Returns

Number of units written or measured (excluding the final terminator, if any).

Function

x_smallstr_cmp

Compares two small strings.

X_STRING_API int32_t x_smallstr_cmp(
 const XSmallstr *a,
 const XSmallstr *b
);

Parameters

const XSmallstr *a
First input view or string.
const XSmallstr *b
Second input view or string.

Returns

Negative, zero, or positive according to lexicographic order.

Function

x_smallstr_cmp_cstr

Compares a small string with a null-terminated C-string.

X_STRING_API int32_t x_smallstr_cmp_cstr(
 const XSmallstr *a,
 const char *b
);

Parameters

const XSmallstr *a
First input view or string.
const char *b
Second input view or string.

Returns

Negative, zero, or positive according to lexicographic order.

Function

x_smallstr_cstr

Returns a pointer to the small string's null-terminated buffer.

X_STRING_API const char * x_smallstr_cstr(const XSmallstr *s);

Parameters

const XSmallstr *s
Destination small string.

Returns

Function-specific result.

Function

x_smallstr_utf8_substring

Copies a UTF-8 codepoint-range substring into a small string.

X_STRING_API int32_t x_smallstr_utf8_substring(
 const XSmallstr *s,
 size_t start_cp,
 size_t len_cp,
 XSmallstr *out
);

Parameters

const XSmallstr *s
Destination small string.
size_t start_cp
Starting UTF-8 codepoint offset (0-based).
size_t len_cp
Number of UTF-8 codepoints to copy or inspect.
XSmallstr *out
Parameter.

Returns

Function-specific integer result.

Function

x_smallstr_utf8_trim_left

Trims leading Unicode whitespace (by UTF-8 codepoints).

X_STRING_API void x_smallstr_utf8_trim_left(XSmallstr *s);

Parameters

XSmallstr *s
Destination small string.

Returns

Resulting view after the operation.

Function

x_smallstr_utf8_trim_right

Trims trailing Unicode whitespace (by UTF-8 codepoints).

X_STRING_API void x_smallstr_utf8_trim_right(XSmallstr *s);

Parameters

XSmallstr *s
Destination small string.

Returns

No return value.

Function

x_smallstr_utf8_trim

Trims leading and trailing Unicode whitespace (by UTF-8 codepoints).

X_STRING_API void x_smallstr_utf8_trim(XSmallstr *s);

Parameters

XSmallstr *s
Destination small string.

Returns

Resulting view after the operation.

Function

x_wsmallstr_init

Initializes a wide-character small string from a wide C-string.

X_STRING_API int32_t x_wsmallstr_init(
 XWSmallstr *s,
 const wchar_t *src
);

Parameters

XWSmallstr *s
Destination small string.
const wchar_t *src
Source buffer or string.

Returns

Function-specific integer result.

Function

x_wsmallstr_cmp

Compares two wide small strings.

X_STRING_API int32_t x_wsmallstr_cmp(
 const XWSmallstr *a,
 const XWSmallstr *b
);

Parameters

const XWSmallstr *a
First input view or string.
const XWSmallstr *b
Second input view or string.

Returns

Negative, zero, or positive according to lexicographic order.

Function

x_wsmallstr_cmp_cstr

Compares a wide small string with a wide C-string.

X_STRING_API int32_t x_wsmallstr_cmp_cstr(
 const XWSmallstr *a,
 const wchar_t *b
);

Parameters

const XWSmallstr *a
First input view or string.
const wchar_t *b
Second input view or string.

Returns

Function-specific integer result.

Function

x_wsmallstr_cmp_ci

Compares two wide small strings case-insensitively.

X_STRING_API int32_t x_wsmallstr_cmp_ci(
 const XWSmallstr *a,
 const XWSmallstr *b
);

Parameters

const XWSmallstr *a
First input view or string.
const XWSmallstr *b
Second input view or string.

Returns

Negative, zero, or positive according to lexicographic order.

Function

x_wsmallstr_length

Returns the current length (in wide characters).

X_STRING_API size_t x_wsmallstr_length(const XWSmallstr *s);

Parameters

const XWSmallstr *s
Destination small string.

Returns

Number of elements in the string (excluding the final terminator).

Function

x_wsmallstr_clear

Clears the wide small string to empty.

X_STRING_API void x_wsmallstr_clear(XWSmallstr *s);

Parameters

XWSmallstr *s
Destination small string.

Returns

No return value.

Function

x_wsmallstr_append

Appends a wide C-string if space allows.

X_STRING_API int32_t x_wsmallstr_append(
 XWSmallstr *s,
 const wchar_t *tail
);

Parameters

XWSmallstr *s
Destination small string.
const wchar_t *tail
Parameter.

Returns

Function-specific integer result.

Function

x_wsmallstr_substring

Copies a wide-character substring into a destination small string.

X_STRING_API int32_t x_wsmallstr_substring(
 const XWSmallstr *s,
 size_t start,
 size_t len,
 XWSmallstr *out
);

Parameters

const XWSmallstr *s
Destination small string.
size_t start
Starting offset (0-based).
size_t len
Number of units to copy or inspect.
XWSmallstr *out
Parameter.

Returns

Function-specific integer result.

Function

x_wsmallstr_trim

Trims leading and trailing whitespace in a wide small string.

X_STRING_API void x_wsmallstr_trim(XWSmallstr *s);

Parameters

XWSmallstr *s
Destination small string.

Returns

No return value.

Function

x_wsmallstr_find

Finds a wide character within a wide small string.

X_STRING_API int32_t x_wsmallstr_find(
 const XWSmallstr *s,
 wchar_t c
);

Parameters

const XWSmallstr *s
Destination small string.
wchar_t c
Character value.

Returns

Index on success, or -1 if not found.

Macro

x_slice_empty

#define x_slice_empty() ((XSlice){.ptr=0, .length=0})
Macro

x_slice_is_empty

#define x_slice_is_empty(sv) ((sv).length==0)
Macro

x_slice_init

#define x_slice_init(cstr, len) ((XSlice){.ptr=(cstr), .length=(len)})
Macro

x_slice

#define x_slice(cstr) (x_slice_init((cstr), strlen(cstr)))
Function

x_slice_eq

Compares two string views for equality.

X_STRING_API bool x_slice_eq(
 XSlice a,
 XSlice b
);

Parameters

XSlice a
First input view or string.
XSlice b
Second input view or string.

Returns

true if the condition holds; false otherwise.

Function

x_slice_eq_cstr

Compares a string view with a C-string for equality.

X_STRING_API bool x_slice_eq_cstr(
 XSlice a,
 const char *b
);

Parameters

XSlice a
First input view or string.
const char *b
Second input view or string.

Returns

Function-specific result.

Function

x_slice_eq_ci

Compares two string views case-insensitively.

X_STRING_API bool x_slice_eq_ci(
 XSlice a,
 XSlice b
);

Parameters

XSlice a
First input view or string.
XSlice b
Second input view or string.

Returns

true if the condition holds; false otherwise.

Function

x_slice_cmp

Lexicographically compares two string views.

X_STRING_API int32_t x_slice_cmp(
 XSlice a,
 XSlice b
);

Parameters

XSlice a
First input view or string.
XSlice b
Second input view or string.

Returns

Negative, zero, or positive according to lexicographic order.

Function

x_slice_cmp_ci

Lexicographically compares two string views case-insensitively.

X_STRING_API int32_t x_slice_cmp_ci(
 XSlice a,
 XSlice b
);

Parameters

XSlice a
First input view or string.
XSlice b
Second input view or string.

Returns

Function-specific integer result.

Function

x_slice_substr

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
);

Parameters

XSlice sv
String view input.
size_t start
Starting offset (0-based).
size_t len
Number of units to copy or inspect.

Returns

Resulting view after the operation.

Function

x_slice_trim_left

Removes leading ASCII whitespace from a string view.

X_STRING_API XSlice x_slice_trim_left(XSlice sv);

Parameters

XSlice sv
String view input.

Returns

Function-specific result.

Function

x_slice_trim_right

Removes trailing ASCII whitespace from a string view.

X_STRING_API XSlice x_slice_trim_right(XSlice sv);

Parameters

XSlice sv
String view input.

Returns

Resulting view after the operation.

Function

x_slice_trim

Removes leading and trailing ASCII whitespace from a string view.

X_STRING_API XSlice x_slice_trim(XSlice sv);

Parameters

XSlice sv
String view input.

Returns

Function-specific result.

Function

x_slice_find

Finds the first occurrence of a character in a string view.

X_STRING_API int32_t x_slice_find(
 XSlice sv,
 char c
);

Parameters

XSlice sv
String view input.
char c
Character value.

Returns

Index on success, or -1 if not found.

Function

x_slice_find_white_space

Finds the next ASCII whitespace in a string view.

X_STRING_API int32_t x_slice_find_white_space(XSlice sv);

Parameters

XSlice sv
String view input.

Returns

Index on success, or -1 if not found.

Function

x_slice_rfind

Finds the last occurrence of a character in a string view.

X_STRING_API int32_t x_slice_rfind(
 XSlice sv,
 char c
);

Parameters

XSlice sv
String view input.
char c
Character value.

Returns

Index on success, or -1 if not found.

Function

x_slice_split_at

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
);

Parameters

XSlice sv
String view input.
char delim
Delimiter character or codepoint.
XSlice *left
Output: left side view.
XSlice *right
Output: right side view.

Returns

Function-specific result.

Function

x_slice_split_at_white_space

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
);

Parameters

XSlice sv
String view input.
XSlice *left
Output: left side view.
XSlice *right
Output: right side view.

Returns

Function-specific result.

Function

x_slice_next_token_white_space

Extracts the next token delimited by ASCII whitespace.

X_STRING_API bool x_slice_next_token_white_space(
 XSlice *input,
 XSlice *token
);

Parameters

XSlice *input
Parameter.
XSlice *token
Output: extracted token.

Returns

Function-specific result.

Function

x_slice_next_token

Extracts the next token delimited by a character.

X_STRING_API bool x_slice_next_token(
 XSlice *input,
 char delim,
 XSlice *token
);

Parameters

XSlice *input
Parameter.
char delim
Delimiter character or codepoint.
XSlice *token
Output: extracted token.

Returns

Function-specific result.

Function

x_slice_starts_with_cstr

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
);

Parameters

XSlice sv
String view input.
const char *prefix
Prefix to match.

Returns

true if the condition holds; false otherwise.

Function

x_slice_ends_with_cstr

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
);

Parameters

XSlice sv
String view input.
const char *prefix
Prefix to match.

Returns

true if the condition holds; false otherwise.

Function

x_slice_utf8_substr

Creates a sub-view by byte range from a string view.

X_STRING_API XSlice x_slice_utf8_substr(
 XSlice sv,
 size_t char_start,
 size_t char_len
);

Parameters

XSlice sv
String view input.
size_t char_start
Parameter.
size_t char_len
Parameter.

Returns

Function-specific result.

Function

x_slice_utf8_trim_left

Removes leading Unicode whitespace (by UTF-8 codepoints).

X_STRING_API XSlice x_slice_utf8_trim_left(XSlice sv);

Parameters

XSlice sv
String view input.

Returns

Resulting view after the operation.

Function

x_slice_utf8_trim_right

Removes trailing ASCII whitespace from a string view.

X_STRING_API XSlice x_slice_utf8_trim_right(XSlice sv);

Parameters

XSlice sv
String view input.

Returns

Function-specific result.

Function

x_slice_utf8_trim

Removes leading and trailing Unicode whitespace (by UTF-8 codepoints).

X_STRING_API XSlice x_slice_utf8_trim(XSlice sv);

Parameters

XSlice sv
String view input.

Returns

Resulting view after the operation.

Function

x_slice_utf8_find

Finds the first occurrence of a character in a string view.

X_STRING_API int32_t x_slice_utf8_find(
 XSlice sv,
 uint32_t codepoint
);

Parameters

XSlice sv
String view input.
uint32_t codepoint
Unicode codepoint value.

Returns

Index on success, or -1 if not found.

Function

x_slice_utf8_rfind

Finds the last occurrence of a UTF-8 codepoint in a string view.

X_STRING_API int32_t x_slice_utf8_rfind(
 XSlice sv,
 uint32_t codepoint
);

Parameters

XSlice sv
String view input.
uint32_t codepoint
Unicode codepoint value.

Returns

Index on success, or -1 if not found.

Function

x_slice_utf8_split_at

Splits a string view at the first occurrence of a delimiter.

X_STRING_API bool x_slice_utf8_split_at(
 XSlice sv,
 uint32_t delim,
 XSlice *left,
 XSlice *right
);

Parameters

XSlice sv
String view input.
uint32_t delim
Delimiter character or codepoint.
XSlice *left
Output: left side view.
XSlice *right
Output: right side view.

Returns

Function-specific result.

Function

x_slice_utf8_next_token

Extracts the next token delimited by a UTF-8 codepoint.

X_STRING_API bool x_slice_utf8_next_token(
 XSlice *input,
 uint32_t codepoint,
 XSlice *token
);

Parameters

XSlice *input
Parameter.
uint32_t codepoint
Unicode codepoint value.
XSlice *token
Output: extracted token.

Returns

Function-specific result.

Function

x_slice_utf8_starts_with_cstr

Checks whether a string view starts with the given C-string prefix.

X_STRING_API bool x_slice_utf8_starts_with_cstr(
 XSlice sv,
 const char *prefix
);

Parameters

XSlice sv
String view input.
const char *prefix
Prefix to match.

Returns

true if the condition holds; false otherwise.

Function

x_slice_utf8_ends_with_cstr

Checks whether a string view ends with the given C-string suffix.

X_STRING_API bool x_slice_utf8_ends_with_cstr(
 XSlice sv,
 const char *prefix
);

Parameters

XSlice sv
String view input.
const char *prefix
Prefix to match.

Returns

true if the condition holds; false otherwise.

Macro

x_wslice_init

#define x_wslice_init(cstr, len) ((XWStrview){.ptr=(cstr), .length=(len)})
Macro

x_wslice

#define x_wslice(cstr) (x_wslice_init((cstr), wcslen(cstr)))
Function

x_wslice_empty

Checks whether the wide string view is empty.

X_STRING_API bool x_wslice_empty(XWStrview sv);

Parameters

XWStrview sv
String view input.

Returns

Function-specific result.

Function

x_wslice_eq

Compares two wide string views for equality.

X_STRING_API bool x_wslice_eq(
 XWStrview a,
 XWStrview b
);

Parameters

XWStrview a
First input view or string.
XWStrview b
Second input view or string.

Returns

true if the condition holds; false otherwise.

Function

x_wslice_cmp

Lexicographically compares two wide string views.

X_STRING_API int32_t x_wslice_cmp(
 XWStrview a,
 XWStrview b
);

Parameters

XWStrview a
First input view or string.
XWStrview b
Second input view or string.

Returns

Function-specific integer result.

Function

x_wslice_substr

Creates a sub-view by range from a wide string view.

X_STRING_API XWStrview x_wslice_substr(
 XWStrview sv,
 size_t start,
 size_t len
);

Parameters

XWStrview sv
String view input.
size_t start
Starting offset (0-based).
size_t len
Number of units to copy or inspect.

Returns

Resulting view after the operation.

Function

x_wslice_trim_left

Removes leading whitespace from a wide string view.

X_STRING_API XWStrview x_wslice_trim_left(XWStrview sv);

Parameters

XWStrview sv
String view input.

Returns

Function-specific result.

Function

x_wslice_trim_right

Removes trailing whitespace from a wide string view.

X_STRING_API XWStrview x_wslice_trim_right(XWStrview sv);

Parameters

XWStrview sv
String view input.

Returns

Resulting view after the operation.

Function

x_wslice_trim

Removes leading and trailing whitespace from a wide string view.

X_STRING_API XWStrview x_wslice_trim(XWStrview sv);

Parameters

XWStrview sv
String view input.

Returns

Function-specific result.

Function

x_wslice_split_at

Splits a wide string view at the first occurrence of a delimiter.

X_STRING_API bool x_wslice_split_at(
 XWStrview sv,
 uint32_t delim,
 XWStrview *left,
 XWStrview *right
);

Parameters

XWStrview sv
String view input.
uint32_t delim
Delimiter character or codepoint.
XWStrview *left
Output: left side view.
XWStrview *right
Output: right side view.

Returns

Function-specific result.

Function

x_wslice_next_token

Extracts the next token from a string view using the given delimiter.

X_STRING_API bool x_wslice_next_token(
 XWStrview *input,
 wchar_t delim,
 XWStrview *token
);

Parameters

XWStrview *input
Parameter.
wchar_t delim
Parameter.
XWStrview *token
Output: extracted token.

Returns

Function-specific result.

Function

x_slice_from_cstr

Creates a non-owning string view from a null-terminated C-string.

X_STRING_API XSlice x_slice_from_cstr(const char *s);

Parameters

const char *s
Source null-terminated C-string (may be NULL).

Returns

XSlice pointing to the provided string, or an empty view if s is NULL.

Function

x_slice_from_smallstr

Creates a non-owning string view from a fixed-capacity small string.

X_STRING_API XSlice x_slice_from_smallstr(const XSmallstr *s);

Parameters

const XSmallstr *s
Source small string (may be NULL).

Returns

XSlice referencing the contents of the small string, or an empty view if s is NULL.

Function

x_smallstr_append_slice

Appends the contents of a string view to a small string.

X_STRING_API size_t x_smallstr_append_slice(
 XSmallstr *s,
 XSlice sv
);

Parameters

XSmallstr *s
Destination small string.
XSlice sv
Source string view to append.

Returns

New length of the small string in bytes after the operation (null-terminated).

Function

x_smallstr_append_n

Appends a fixed-length portion of a C-string to a small string.

X_STRING_API size_t x_smallstr_append_n(
 XSmallstr *s,
 const char *cstr,
 size_t n
);

Parameters

XSmallstr *s
Destination small string.
const char *cstr
Source C-string (may be NULL).
size_t n
Number of bytes to append from cstr.

Returns

New length of the small string in bytes after the operation.

Function

x_smallstr_vappendf

Appends formatted text to a small string using a va_list.

X_STRING_API size_t x_smallstr_vappendf(
 XSmallstr *s,
 const char *fmt,
 va_list args
);

Parameters

XSmallstr *s
Destination small string.
const char *fmt
printf-style format string.
va_list args
va_list argument list.

Returns

New length of the small string in bytes after the operation.

Function

x_smallstr_appendf

Appends formatted text to a small string.

X_STRING_API size_t x_smallstr_appendf(
 XSmallstr *s,
 const char *fmt,
 ...
);

Parameters

XSmallstr *s
Destination small string.
const char *fmt
printf-style format string.
...
Additional arguments for formatting.

Returns

New length of the small string in bytes after the operation.

Function

x_slice_contains_char

Checks whether a string view contains the specified character.

X_STRING_API bool x_slice_contains_char(
 XSlice sv,
 char c
);

Parameters

XSlice sv
Input string view.
char c
Character to search for.

Returns

true if the character is found; false otherwise.

Function

x_slice_contains_utf8

Checks whether a string view contains the specified UTF-8 codepoint.

X_STRING_API bool x_slice_contains_utf8(
 XSlice sv,
 uint32_t codepoint
);

Parameters

XSlice sv
Input string view.
uint32_t codepoint
Unicode codepoint to search for.

Returns

true if the codepoint is found; false otherwise.

Function

x_smallstr_contains_char

Checks whether a small string contains the specified character.

X_STRING_API bool x_smallstr_contains_char(
 const XSmallstr *s,
 char c
);

Parameters

const XSmallstr *s
Input small string.
char c
Character to search for.

Returns

true if the character is found; false otherwise.

Function

x_smallstr_join

Concatenates multiple string views into a small string, inserting a separator between them.

X_STRING_API size_t x_smallstr_join(
 XSmallstr *dst,
 const XSlice *parts,
 size_t count,
 XSlice sep
);

Parameters

XSmallstr *dst
Destination small string.
const XSlice *parts
Array of string views to join.
size_t count
Number of elements in the parts array.
XSlice sep
Separator view inserted between joined elements.

Returns

New length of the small string after concatenation.

Function

x_smallstr_capacity

Returns the maximum number of bytes (excluding terminator) a small string can hold.

X_STRING_API size_t x_smallstr_capacity(void);

Returns

The compile-time capacity constant X_SMALLSTR_MAX_LENGTH.

Function

x_smallstr_is_empty

Tests whether a small string is empty.

X_STRING_API bool x_smallstr_is_empty(const XSmallstr *s);

Parameters

const XSmallstr *s
Input small string.

Returns

true if the small string has zero length or is NULL; false otherwise.

Function

x_smallstr_try_append_cstr

Attempts to append a C-string to a small string up to its capacity.

X_STRING_API bool x_smallstr_try_append_cstr(
 XSmallstr *s,
 const char *cstr,
 size_t *out_appended
);

Parameters

XSmallstr *s
Destination small string.
const char *cstr
Source null-terminated C-string.
size_t *out_appended
Optional pointer to receive bytes actually appended.

Returns

true if any bytes were appended; false if none or on error.

Macro

X_STRVIEW

Creates a compile-time string view from a string literal.

#define X_STRVIEW(s) ((XSlice){(s), sizeof(s)-1u})

Parameters

s
String literal.

Returns

XSlice representing the literal contents, excluding the null terminator.

Macro

strncasecmp

#define strncasecmp _strnicmp
Macro

strnicmp

#define strnicmp _strnicmp
Function

x_wide_to_utf8

X_STRING_API size_t x_wide_to_utf8(
 const wchar_t *wide,
 char *utf8,
 size_t max
);
Function

x_smallstr_find

X_STRING_API int32_t x_smallstr_find(
 const XSmallstr *s,
 char c
);
Function

x_smallstr_rfind

X_STRING_API int32_t x_smallstr_rfind(
 const XSmallstr *s,
 char c
);
Function

x_smallstr_split_at

X_STRING_API int32_t x_smallstr_split_at(
 const XSmallstr *s,
 char delim,
 XSmallstr *left,
 XSmallstr *right
);
Function

x_wsmallstr_from_wcstr

X_STRING_API int32_t x_wsmallstr_from_wcstr(
 XWSmallstr *s,
 const wchar_t *src
);
Function

x_wsmallstr_next_token

X_STRING_API int32_t x_wsmallstr_next_token(
 XWSmallstr *input,
 wchar_t delim,
 XWSmallstr *token
);