XSmallstr
typedef struct{
char buf[X_SMALLSTR_MAX_LENGTH+1];
size_t length;
}XSmallstr;
typedef struct{
char buf[X_SMALLSTR_MAX_LENGTH+1];
size_t length;
}XSmallstr;
Appends a single character if space allows.
X_STRING_API size_t x_smallstr_append_char(
XSmallstr *s,
char c
);
XSmallstr *schar cNumber of units written or measured (excluding the final terminator, if any).
Appends a null-terminated C-string if space allows.
X_STRING_API size_t x_smallstr_append_cstr(
XSmallstr *s,
const char *cstr
);
XSmallstr *sconst char *cstrNumber of units written or measured (excluding the final terminator, if any).
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
);
XSmallstr *sconst char *cstrsize_t nNew length of the small string in bytes after the operation.
Appends the contents of a string view to a small string.
X_STRING_API size_t x_smallstr_append_slice(
XSmallstr *s,
XSlice sv
);
New length of the small string in bytes after the operation (null-terminated).
Appends formatted text to a small string.
X_STRING_API size_t x_smallstr_appendf(
XSmallstr *s,
const char *fmt,
...
);
XSmallstr *sconst char *fmt...New length of the small string in bytes after the operation.
Returns the maximum number of bytes (excluding terminator) a small string can hold.
X_STRING_API size_t x_smallstr_capacity(void);
The compile-time capacity constant X_SMALLSTR_MAX_LENGTH.
Clears the small string to empty.
X_STRING_API void x_smallstr_clear(XSmallstr *s);
XSmallstr *sNo return value.
Compares two small strings.
X_STRING_API int32_t x_smallstr_cmp(
const XSmallstr *a,
const XSmallstr *b
);
Negative, zero, or positive according to lexicographic order.
Compares two small strings case-insensitively.
X_STRING_API int32_t x_smallstr_cmp_ci(
const XSmallstr *a,
const XSmallstr *b
);
Negative, zero, or positive according to lexicographic order.
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
);
const XSmallstr *aconst char *bNegative, zero, or positive according to lexicographic order.
Checks whether a small string contains the specified character.
X_STRING_API bool x_smallstr_contains_char(
const XSmallstr *s,
char c
);
const XSmallstr *schar ctrue if the character is found; false otherwise.
Returns a pointer to the small string's null-terminated buffer.
X_STRING_API const char * x_smallstr_cstr(const XSmallstr *s);
const XSmallstr *sFunction-specific result.
Formats text into a small string; truncates if necessary.
X_STRING_API size_t x_smallstr_format(
XSmallstr *s,
const char *fmt,
...
);
XSmallstr *sconst char *fmtparamNumber of units written or measured (excluding the final terminator, if any).
Copies a null-terminated C-string into a small string.
X_STRING_API size_t x_smallstr_from_cstr(
XSmallstr *s,
const char *cstr
);
XSmallstr *sconst char *cstrNumber of units written or measured (excluding the final terminator, if any).
Copies a string view into a small string.
X_STRING_API size_t x_smallstr_from_slice(
XSlice sv,
XSmallstr *out
);
Number of units written or measured (excluding the final terminator, if any).
Initializes a fixed-capacity small string from a source C-string.
X_STRING_API int32_t x_smallstr_init(
XSmallstr *s,
const char *str
);
XSmallstr *sconst char *strFunction-specific integer result.
Tests whether a small string is empty.
X_STRING_API bool x_smallstr_is_empty(const XSmallstr *s);
const XSmallstr *strue if the small string has zero length or is NULL; false otherwise.
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
);
New length of the small string after concatenation.
Returns the current byte length of the small string.
X_STRING_API size_t x_smallstr_length(const XSmallstr *s);
const XSmallstr *sNumber of elements in the string (excluding the final terminator).
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
);
XSmallstr *sconst char *findconst char *replaceFunction-specific integer result.
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
);
Number of units written or measured (excluding the final terminator, if any).
Creates a non-owning view over a small string's contents.
X_STRING_API XSlice x_smallstr_to_slice(const XSmallstr *s);
const XSmallstr *sResulting view after the operation.
Trims leading and trailing ASCII whitespace in a small string.
X_STRING_API void x_smallstr_trim(XSmallstr *s);
XSmallstr *sResulting view after the operation.
Trims leading ASCII whitespace in a small string.
X_STRING_API void x_smallstr_trim_left(XSmallstr *s);
XSmallstr *sResulting view after the operation.
Trims trailing ASCII whitespace in a small string.
X_STRING_API void x_smallstr_trim_right(XSmallstr *s);
XSmallstr *sNo return value.
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
);
XSmallstr *sconst char *cstrsize_t *out_appendedtrue if any bytes were appended; false if none or on error.
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
);
XSmallstr *sconst char *fmtva_list argsNew length of the small string in bytes after the operation.