2.1.3 String View¶
-
ZIX_STATIC_STRING(s)¶
Initialize a string view from a string literal.
-
struct ZixStringView¶
An immutable slice of a string.
This type is used for many string parameters, to allow referring to slices of strings in-place and to avoid redundant string measurement.
-
const char *data¶
Pointer to the first character.
-
size_t length¶
Length of string in bytes.
-
const char *data¶
-
ZixStringView zix_empty_string(void)¶
Return a view of an empty string.
-
ZixStringView zix_string(const char *const str)¶
Return a view of an entire string by measuring it.
This makes a view of the given string by measuring it with
strlen
.- Parameters:
str – Pointer to the start of a null-terminated C string, or null.
-
char *zix_string_view_copy(ZixAllocator *allocator, ZixStringView view)¶
Copy a string view into a newly allocated null-terminated string.
-
bool zix_string_view_equals(ZixStringView lhs, ZixStringView rhs)¶
Return true if both string views refer to equal strings.
This may be significantly faster than a full string comparison, because it has fast paths for when the operands have different lengths, or point to the same string data.
-
ZixStringView zix_substring(const char *const str, const size_t len)¶
Return a view of a substring, or a premeasured string.
This makes either a view of a slice of a string (which may not be null terminated), or a view of a string that has already been measured. This is faster than zix_string() for dynamic strings since it does not call
strlen
, so should be used when the length of the string is already known.- Parameters:
str – Pointer to the start of the substring.
len – Length of the substring in bytes, not including the trailing null terminator if present.