Slice99  0.7.7
Memory slices for C99
Data Structures | Macros | Functions
slice99.h File Reference

A slice of some array. More...

Go to the source code of this file.

Data Structures

struct  Slice99
 A slice of some array. More...
 

Macros

#define SLICE99_ASSERT   assert
 Like assert.
 
#define SLICE99_MEMCMP   memcmp
 Like memcmp.
 
#define SLICE99_MEMCPY   memcpy
 Like memcpy.
 
#define SLICE99_MEMMOVE   memmove
 Like memmove.
 
#define SLICE99_STRLEN   strlen
 Like strlen.
 
#define SLICE99_MAJOR   0
 The major version number.
 
#define SLICE99_MINOR   7
 The minor version number.
 
#define SLICE99_PATCH   7
 The patch version number.
 
#define SLICE99_DEF_TYPED(name, T)
 Defines the strongly typed slice name containing items of type T. More...
 
#define SLICE99_TO_TYPED(self)    { .ptr = (self).ptr, .len = (self).len }
 Converts Slice99 to a typed representation. More...
 
#define SLICE99_TO_UNTYPED(self)   Slice99_new((self).ptr, sizeof(*(self).ptr), (self).len)
 Converts the typed slice self to Slice99. More...
 
#define SLICE99_ARRAY_LEN(...)   (sizeof(__VA_ARGS__) / sizeof((__VA_ARGS__)[0]))
 Computes a number of items in an array expression.
 
#define SLICE99_APPEND(buffer, obj)    ((void *)((char *)SLICE99_MEMCPY((buffer), &(obj), sizeof(obj)) + sizeof(obj)))
 Copies obj to buffer, returning the next position of buffer to write to. More...
 
#define SLICE99_APPEND_ARRAY(buffer, ptr, len)
 Copies the array of length len accessible through ptr into buffer, returning the next position of buffer to write to. More...
 
#define SLICE99_TO_OCTETS(obj)   U8Slice99_new((uint8_t *)&(obj), sizeof(obj))
 Constructs U8Slice99 from obj. More...
 
#define Slice99_from_array(...)    Slice99_new((void *)(__VA_ARGS__), sizeof((__VA_ARGS__)[0]), SLICE99_ARRAY_LEN(__VA_ARGS__))
 Constructs a slice from an array expression. More...
 
#define Slice99_typed_from_array(...)    { .ptr = (__VA_ARGS__), .len = SLICE99_ARRAY_LEN(__VA_ARGS__) }
 The same as Slice99_from_array but for typed slices. More...
 
#define Slice99_from_typed_ptr(ptr, len)   Slice99_new(ptr, sizeof(*(ptr)), len)
 Constructs a slice from a pointer of a non-void type and a length. More...
 
#define CharSlice99_alloca_c_str(self)   CharSlice99_c_str((self), alloca((self).len + 1))
 Makes a null-terminated string out of CharSlice99 using alloca. More...
 
#define SLICE99_VSPRINTF   vsprintf
 Like vsprintf. More...
 
#define SLICE99_VSNPRINTF   vsnprintf
 Like vsnprintf. More...
 
#define SLICE99_SNPRINTF   snprintf
 Like snprintf. More...
 
#define CharSlice99_alloca_fmt(fmt, ...)    CharSlice99_fmt(alloca(SLICE99_SNPRINTF(NULL, 0, (fmt), __VA_ARGS__) + 1), (fmt), __VA_ARGS__)
 Printfs a formatted string to a character slice using alloca. More...
 

Functions

static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_new (void *ptr, size_t item_size, size_t len)
 Constructs a slice. More...
 
static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_from_str (char *str)
 Constructs a slice from str. More...
 
static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_from_ptrdiff (void *start, void *end, size_t item_size)
 Constructs a slice residing between start (inclusively) and end (exclusively). More...
 
static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_empty (size_t item_size)
 Constructs an empty slice. More...
 
static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_update_len (Slice99 self, size_t new_len)
 Updates self with the new length new_len. More...
 
static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST bool Slice99_is_empty (Slice99 self)
 Checks whether self is empty or not. More...
 
static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST size_t Slice99_size (Slice99 self)
 Computes a total size in bytes. More...
 
static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST void * Slice99_get (Slice99 self, ptrdiff_t i)
 Computes a pointer to the i -indexed item. More...
 
static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST void * Slice99_first (Slice99 self)
 Computes a pointer to the first item. More...
 
static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST void * Slice99_last (Slice99 self)
 Computes a pointer to the last item. More...
 
static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_sub (Slice99 self, ptrdiff_t start_idx, ptrdiff_t end_idx)
 Subslicing self with [start_idx .. end_idx]. More...
 
static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_advance (Slice99 self, ptrdiff_t offset)
 Advances self by offset items. More...
 
static SLICE99_WARN_UNUSED_RESULT bool Slice99_primitive_eq (Slice99 lhs, Slice99 rhs)
 Performs a byte-by-byte comparison of lhs with rhs. More...
 
static SLICE99_WARN_UNUSED_RESULT bool Slice99_eq (Slice99 lhs, Slice99 rhs, int(*cmp)(const void *, const void *))
 Performs a comparison of lhs with rhs with a user-supplied comparator. More...
 
static SLICE99_WARN_UNUSED_RESULT bool Slice99_primitive_starts_with (Slice99 self, Slice99 prefix)
 Checks whether prefix is a prefix of self, byte-by-byte. More...
 
static SLICE99_WARN_UNUSED_RESULT bool Slice99_starts_with (Slice99 self, Slice99 prefix, int(*cmp)(const void *, const void *))
 Checks whether prefix is a prefix of self with a user-supplied comparator. More...
 
static SLICE99_WARN_UNUSED_RESULT bool Slice99_primitive_ends_with (Slice99 self, Slice99 postfix)
 Checks whether postfix is a postfix of self, byte-by-byte. More...
 
static SLICE99_WARN_UNUSED_RESULT bool Slice99_ends_with (Slice99 self, Slice99 postfix, int(*cmp)(const void *, const void *))
 Checks whether postfix is a postfix of self with a user-supplied comparator. More...
 
static void Slice99_copy (Slice99 self, Slice99 other)
 Copies other to the beginning of self, byte-by-byte. More...
 
static void Slice99_copy_non_overlapping (Slice99 self, Slice99 other)
 The same as Slice99_copy except that self and other must be non-overlapping. More...
 
static void Slice99_swap (Slice99 self, ptrdiff_t lhs, ptrdiff_t rhs, void *restrict backup)
 Swaps the lhs -indexed and rhs -indexed items. More...
 
static void Slice99_swap_with_slice (Slice99 self, Slice99 other, void *restrict backup)
 Swaps all the items in self with those in other. More...
 
static void Slice99_reverse (Slice99 self, void *restrict backup)
 Reverses the order of items in self. More...
 
static void Slice99_split_at (Slice99 self, size_t i, Slice99 *restrict lhs, Slice99 *restrict rhs)
 Splits self into two parts. More...
 
static char * Slice99_c_str (Slice99 self, char out[restrict])
 Copies self to out and appends '\0' to the end. More...
 
 SLICE99_DEF_TYPED (CharSlice99, char)
 
 SLICE99_DEF_TYPED (SCharSlice99, signed char)
 
 SLICE99_DEF_TYPED (UCharSlice99, unsigned char)
 
 SLICE99_DEF_TYPED (ShortSlice99, short)
 
 SLICE99_DEF_TYPED (UShortSlice99, unsigned short)
 
 SLICE99_DEF_TYPED (IntSlice99, int)
 
 SLICE99_DEF_TYPED (UIntSlice99, unsigned int)
 
 SLICE99_DEF_TYPED (LongSlice99, long)
 
 SLICE99_DEF_TYPED (ULongSlice99, unsigned long)
 
 SLICE99_DEF_TYPED (LongLongSlice99, long long)
 
 SLICE99_DEF_TYPED (ULongLongSlice99, unsigned long long)
 
 SLICE99_DEF_TYPED (FloatSlice99, float)
 
 SLICE99_DEF_TYPED (DoubleSlice99, double)
 
 SLICE99_DEF_TYPED (LongDoubleSlice99, long double)
 
 SLICE99_DEF_TYPED (BoolSlice99, _Bool)
 
 SLICE99_DEF_TYPED (U8Slice99, uint8_t)
 
 SLICE99_DEF_TYPED (U16Slice99, uint16_t)
 
 SLICE99_DEF_TYPED (U32Slice99, uint32_t)
 
 SLICE99_DEF_TYPED (U64Slice99, uint64_t)
 
 SLICE99_DEF_TYPED (I8Slice99, int8_t)
 
 SLICE99_DEF_TYPED (I16Slice99, int16_t)
 
 SLICE99_DEF_TYPED (I32Slice99, int32_t)
 
 SLICE99_DEF_TYPED (I64Slice99, int64_t)
 
static SLICE99_WARN_UNUSED_RESULT CharSlice99 CharSlice99_from_str (char *str)
 The same as Slice99_from_str.
 
static char * CharSlice99_c_str (CharSlice99 self, char out[restrict])
 The same as Slice99_c_str.
 
static SLICE99_WARN_UNUSED_RESULT SLICE99_FORMAT_HINT_2_0 CharSlice99 CharSlice99_vfmt (char out[restrict], const char *restrict fmt, va_list list)
 Prints a formatted string to out and returns the corresponding character slice. More...
 
static SLICE99_WARN_UNUSED_RESULT SLICE99_FORMAT_HINT_2_3 CharSlice99 CharSlice99_fmt (char out[restrict], const char *restrict fmt,...)
 The CharSlice99_vfmt twin. More...
 
static SLICE99_WARN_UNUSED_RESULT SLICE99_FORMAT_HINT_3_0 CharSlice99 CharSlice99_vnfmt (char out[restrict], size_t bufsz, const char *restrict fmt, va_list list)
 The same as CharSlice99_vfmt but writes at most bufsz - 1 characters. More...
 
static SLICE99_WARN_UNUSED_RESULT SLICE99_FORMAT_HINT_3_4 CharSlice99 CharSlice99_nfmt (char out[restrict], size_t bufsz, const char *restrict fmt,...)
 The CharSlice99_vnfmt twin. More...
 

Detailed Description

A slice of some array.

Some macros are automatically defined in case they have not been defined before including this header file; these are: SLICE99_ASSERT, SLICE99_MEMCMP, SLICE99_MEMCPY, SLICE99_MEMMOVE, SLICE99_STRLEN, SLICE99_VSPRINTF, SLICE99_VSNPRINTF, and SLICE99_SNPRINTF. They represent the corresponding standard library's functions, although actual implementations can differ. If you develop software for a freestanding environment, these macros must be defined beforehand. If you do not want to implement string formatting macros from stdio.h, define SLICE99_DISABLE_STDIO and Slice99 will not require them from you.

Macro Definition Documentation

◆ CharSlice99_alloca_c_str

#define CharSlice99_alloca_c_str (   self)    CharSlice99_c_str((self), alloca((self).len + 1))

Makes a null-terminated string out of CharSlice99 using alloca.

The same as CharSlice99_c_str, except that the second parameter is allocated using alloca. Do not use this macro for big strings to avoid stack overflow.

◆ CharSlice99_alloca_fmt

#define CharSlice99_alloca_fmt (   fmt,
  ... 
)     CharSlice99_fmt(alloca(SLICE99_SNPRINTF(NULL, 0, (fmt), __VA_ARGS__) + 1), (fmt), __VA_ARGS__)

Printfs a formatted string to a character slice using alloca.

The same as CharSlice99_fmt, except that the first parameter is allocated using alloca. Do not use this macro for big strings to avoid stack overflow.

Defined only if SLICE99_DISABLE_STDIO is not defined.

◆ SLICE99_APPEND

#define SLICE99_APPEND (   buffer,
  obj 
)     ((void *)((char *)SLICE99_MEMCPY((buffer), &(obj), sizeof(obj)) + sizeof(obj)))

Copies obj to buffer, returning the next position of buffer to write to.

This macro is no different from memcpy except for the return value. It is useful when you want to write a sequence of objects to some memory buffer, e.g., to a packet header:

const uint16_t x = 123;
const uint32_t y = 456;
header = SLICE99_APPEND(header, x);
header = SLICE99_APPEND(header, y);
// ...
#define SLICE99_APPEND(buffer, obj)
Copies obj to buffer, returning the next position of buffer to write to.
Definition: slice99.h:384
Parameters
[out]bufferThe memory area to write to.
[in]objThe object (lvalue) that will be copied to buffer, byte-by-byte.
Returns
(void *)((char *)buffer + sizeof(obj))
Precondition
buffer must be capable of holding at least sizeof(obj) bytes.
buffer and obj must be non-overlapping.
See also
SLICE99_APPEND_ARRAY

◆ SLICE99_APPEND_ARRAY

#define SLICE99_APPEND_ARRAY (   buffer,
  ptr,
  len 
)
Value:
((void \
*)((char *)SLICE99_MEMCPY((buffer), (ptr), sizeof((ptr)[0]) * (len)) + sizeof((ptr)[0]) * (len)))
#define SLICE99_MEMCPY
Like memcpy.
Definition: slice99.h:72

Copies the array of length len accessible through ptr into buffer, returning the next position of buffer to write to.

This function has the same requirements and a return value as of SLICE99_APPEND.

◆ SLICE99_DEF_TYPED

#define SLICE99_DEF_TYPED (   name,
 
)

Defines the strongly typed slice name containing items of type T.

This macro defines

typedef struct {
T *ptr;
size_t len;
} name;

Also, it specialises all the functions operating on Slice99. Every function (except for Slice99_from_str and Slice99_c_str) is defined by the following rules:

  • A function named Slice99_* becomes name_*.
  • void * is replaced by T *.
  • Slice99 is replaced by name.
  • size_t item_size parameters are removed (e.g., as in Slice99_new, Slice99_empty, Slice99_from_ptrdiff).
  • All function preconditions, invariants, and postconditions remain the same.

Slice99_from_str and Slice99_c_str are derived only for CharSlice99.

Examples

#include <slice99.h>
typedef struct {
double x, y;
} Point;
SLICE99_DEF_TYPED(MyPoints, Point);
int main(void) {
MyPoints points = (MyPoints)Slice99_typed_from_array(
(Point[]){{1.5, 32.5}, {12.0, 314.01}, {-134.10, -9.3}});
MyPoints first_two = MyPoints_sub(points, 0, 2);
Point *first = MyPoints_first(points);
bool is_empty = MyPoints_is_empty(points);
}
A slice of some array.
#define SLICE99_DEF_TYPED(name, T)
Defines the strongly typed slice name containing items of type T.
Definition: slice99.h:174
#define Slice99_typed_from_array(...)
The same as Slice99_from_array but for typed slices.
Definition: slice99.h:433

◆ Slice99_from_array

#define Slice99_from_array (   ...)     Slice99_new((void *)(__VA_ARGS__), sizeof((__VA_ARGS__)[0]), SLICE99_ARRAY_LEN(__VA_ARGS__))

Constructs a slice from an array expression.

The resulting slice will have Slice99.len equal to the number of items in the array, and Slice99.item_size equal to the size of each item.

◆ Slice99_from_typed_ptr

#define Slice99_from_typed_ptr (   ptr,
  len 
)    Slice99_new(ptr, sizeof(*(ptr)), len)

Constructs a slice from a pointer of a non-void type and a length.

It is equivalent to Slice99_new but it automatically computes an item size as sizeof(*ptr).

Parameters
[in]ptrThe pointer of the resulting slice. Must not point to void.
[in]lenThe length of the resulting slice.

◆ SLICE99_SNPRINTF

#define SLICE99_SNPRINTF   snprintf

Like snprintf.

Defined only if it has not been defined previously and SLICE99_DISABLE_STDIO is not defined.

◆ SLICE99_TO_OCTETS

#define SLICE99_TO_OCTETS (   obj)    U8Slice99_new((uint8_t *)&(obj), sizeof(obj))

Constructs U8Slice99 from obj.

Parameters
[in]objThe object (lvalue) to which the resulting slice will point to.
Returns
An octet slice pointing to obj of length sizeof(obj).

◆ SLICE99_TO_TYPED

#define SLICE99_TO_TYPED (   self)     { .ptr = (self).ptr, .len = (self).len }

Converts Slice99 to a typed representation.

Precondition
self must be an expression of type Slice99.

Examples

#include <slice99.h>
int main(void) {
CharSlice99 y = (CharSlice99)SLICE99_TO_TYPED(x);
(void)y;
}
#define SLICE99_TO_TYPED(self)
Converts Slice99 to a typed representation.
Definition: slice99.h:332
static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_from_str(char *str)
Constructs a slice from str.
Definition: slice99.h:496
A slice of some array.
Definition: slice99.h:454

◆ SLICE99_TO_UNTYPED

#define SLICE99_TO_UNTYPED (   self)    Slice99_new((self).ptr, sizeof(*(self).ptr), (self).len)

Converts the typed slice self to Slice99.

Precondition
self must be an expression of type defined by SLICE99_DEF_TYPED.

Examples

#include <slice99.h>
int main(void) {
CharSlice99 x = CharSlice99_from_str("abc");
(void)y;
}
static SLICE99_WARN_UNUSED_RESULT CharSlice99 CharSlice99_from_str(char *str)
The same as Slice99_from_str.
Definition: slice99.h:952
#define SLICE99_TO_UNTYPED(self)
Converts the typed slice self to Slice99.
Definition: slice99.h:352

◆ Slice99_typed_from_array

#define Slice99_typed_from_array (   ...)     { .ptr = (__VA_ARGS__), .len = SLICE99_ARRAY_LEN(__VA_ARGS__) }

The same as Slice99_from_array but for typed slices.

Examples

#include <slice99.h>
int main(void) {
IntSlice99 x = (IntSlice99)Slice99_typed_from_array((int[]){1, 2, 3});
(void)x;
}

◆ SLICE99_VSNPRINTF

#define SLICE99_VSNPRINTF   vsnprintf

Like vsnprintf.

Defined only if it has not been defined previously and SLICE99_DISABLE_STDIO is not defined.

◆ SLICE99_VSPRINTF

#define SLICE99_VSPRINTF   vsprintf

Like vsprintf.

Defined only if it has not been defined previously and SLICE99_DISABLE_STDIO is not defined.

Function Documentation

◆ CharSlice99_fmt()

static SLICE99_WARN_UNUSED_RESULT SLICE99_FORMAT_HINT_2_3 CharSlice99 CharSlice99_fmt ( char  out[restrict],
const char *restrict  fmt,
  ... 
)
inlinestatic

The CharSlice99_vfmt twin.

Defined only if SLICE99_DISABLE_STDIO is not defined.

◆ CharSlice99_nfmt()

static SLICE99_WARN_UNUSED_RESULT SLICE99_FORMAT_HINT_3_4 CharSlice99 CharSlice99_nfmt ( char  out[restrict],
size_t  bufsz,
const char *restrict  fmt,
  ... 
)
inlinestatic

The CharSlice99_vnfmt twin.

Defined only if SLICE99_DISABLE_STDIO is not defined.

◆ CharSlice99_vfmt()

static SLICE99_WARN_UNUSED_RESULT SLICE99_FORMAT_HINT_2_0 CharSlice99 CharSlice99_vfmt ( char  out[restrict],
const char *restrict  fmt,
va_list  list 
)
inlinestatic

Prints a formatted string to out and returns the corresponding character slice.

Defined only if SLICE99_DISABLE_STDIO is not defined.

Parameters
[out]outThe buffer that must be capable of holding all characters that will be written by SLICE99_VSPRINTF.
[in]fmtThe printf-like format string.
[in]listThe variadic function arguments reified into va_list.
Returns
A character slice constructed from out.
Precondition
out != NULL
fmt != NULL

◆ CharSlice99_vnfmt()

static SLICE99_WARN_UNUSED_RESULT SLICE99_FORMAT_HINT_3_0 CharSlice99 CharSlice99_vnfmt ( char  out[restrict],
size_t  bufsz,
const char *restrict  fmt,
va_list  list 
)
inlinestatic

The same as CharSlice99_vfmt but writes at most bufsz - 1 characters.

Defined only if SLICE99_DISABLE_STDIO is not defined.

◆ Slice99_advance()

static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_advance ( Slice99  self,
ptrdiff_t  offset 
)
inlinestatic

Advances self by offset items.

Parameters
[in]selfThe original slice.
[in]offsetThe number of items to advance. Can be negative.
Returns
A slice advanced by offset items.
Precondition
offset <= (self).len
self.len must be representable as ptrdiff_t.

◆ Slice99_c_str()

static char* Slice99_c_str ( Slice99  self,
char  out[restrict] 
)
inlinestatic

Copies self to out and appends '\0' to the end.

Parameters
[in]selfThe slice that will be copied.
[in]outThe memory area to which self and the null character will be copied.
Returns
The pointer out.
Precondition
out must be capable of writing Slice99_size(self) + 1 bytes.
out must not overlap with self.

◆ Slice99_copy()

static void Slice99_copy ( Slice99  self,
Slice99  other 
)
inlinestatic

Copies other to the beginning of self, byte-by-byte.

Parameters
[out]selfThe location to which the whole other will be copied.
[in]otherThe slice to be copied to self.

◆ Slice99_copy_non_overlapping()

static void Slice99_copy_non_overlapping ( Slice99  self,
Slice99  other 
)
inlinestatic

The same as Slice99_copy except that self and other must be non-overlapping.

Precondition
self and other must be non-overlapping.

◆ Slice99_empty()

static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_empty ( size_t  item_size)
inlinestatic

Constructs an empty slice.

Parameters
[in]item_sizeThe value of Slice99::item_size.
Precondition
item_size > 0

◆ Slice99_ends_with()

static SLICE99_WARN_UNUSED_RESULT bool Slice99_ends_with ( Slice99  self,
Slice99  postfix,
int(*)(const void *, const void *)  cmp 
)
inlinestatic

Checks whether postfix is a postfix of self with a user-supplied comparator.

Parameters
[in]selfThe slice to be checked for postfix.
[in]postfixThe slice to be checked whether it is a postfix of self.
[in]cmpThe function deciding whether two items are equal ot not (0 if equal, any other value otherwise).
Returns
true if postfix is a postfix of self, otherwise false.
Precondition
self.item_size == postfix.item_size
cmp != NULL
self.len and postfix.len must be representable as ptrdiff_t.

◆ Slice99_eq()

static SLICE99_WARN_UNUSED_RESULT bool Slice99_eq ( Slice99  lhs,
Slice99  rhs,
int(*)(const void *, const void *)  cmp 
)
inlinestatic

Performs a comparison of lhs with rhs with a user-supplied comparator.

Parameters
[in]lhsThe first slice to be compared.
[in]rhsThe second slice to be compared.
[in]cmpThe function deciding whether two items are equal ot not (0 if equal, any other value otherwise).
Returns
true if lhs and rhs are equal, false otherwise.
Precondition
lhs.item_size == rhs.item_size
cmp != NULL
lhs.len and rhs.len must be representable as ptrdiff_t.

◆ Slice99_first()

static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST void* Slice99_first ( Slice99  self)
inlinestatic

Computes a pointer to the first item.

Parameters
[in]selfThe slice upon which the pointer will be computed.

◆ Slice99_from_ptrdiff()

static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_from_ptrdiff ( void *  start,
void *  end,
size_t  item_size 
)
inlinestatic

Constructs a slice residing between start (inclusively) and end (exclusively).

Parameters
[in]startThe start position of a returned slice, inclusively.
[in]endThe end position of a returned slice, exlusively.
[in]item_sizeThe value of Slice99::item_size.
Precondition
start != NULL
end != NULL
((char *)end - (char *)start) >= 0
(((char *)end - (char *)start)) % item_size == 0

◆ Slice99_from_str()

static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_from_str ( char *  str)
inlinestatic

Constructs a slice from str.

Parameters
[in]strAny null-terminated string.
Precondition
str != NULL

◆ Slice99_get()

static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST void* Slice99_get ( Slice99  self,
ptrdiff_t  i 
)
inlinestatic

Computes a pointer to the i -indexed item.

Parameters
[in]selfThe slice upon which the pointer will be computed.
[in]iThe index of a desired item. Can be negative.
Precondition
self.item_size must be representable as ptrdiff_t.

◆ Slice99_is_empty()

static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST bool Slice99_is_empty ( Slice99  self)
inlinestatic

Checks whether self is empty or not.

Parameters
[in]selfThe checked slice.
Returns
true if self is empty, otherwise false.

◆ Slice99_last()

static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST void* Slice99_last ( Slice99  self)
inlinestatic

Computes a pointer to the last item.

Parameters
[in]selfThe slice upon which the pointer will be computed.
Precondition
self.len must be representable as ptrdiff_t.

◆ Slice99_new()

static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_new ( void *  ptr,
size_t  item_size,
size_t  len 
)
inlinestatic

Constructs a slice.

Parameters
[in]ptrThe value of Slice99::ptr.
[in]item_sizeThe value of Slice99::item_size.
[in]lenThe value of Slice99::len.
Precondition
ptr != NULL
item_size > 0

◆ Slice99_primitive_ends_with()

static SLICE99_WARN_UNUSED_RESULT bool Slice99_primitive_ends_with ( Slice99  self,
Slice99  postfix 
)
inlinestatic

Checks whether postfix is a postfix of self, byte-by-byte.

Parameters
[in]selfThe slice to be checked for postfix.
[in]postfixThe slice to be checked whether it is a postfix of self.
Returns
true if postfix is a postfix of self, otherwise false.
Precondition
self.len and postfix.len must be representable as ptrdiff_t.

◆ Slice99_primitive_eq()

static SLICE99_WARN_UNUSED_RESULT bool Slice99_primitive_eq ( Slice99  lhs,
Slice99  rhs 
)
inlinestatic

Performs a byte-by-byte comparison of lhs with rhs.

Parameters
[in]lhsThe first slice to be compared.
[in]rhsThe second slice to be compared.
Returns
true if lhs and rhs are equal, false otherwise.

◆ Slice99_primitive_starts_with()

static SLICE99_WARN_UNUSED_RESULT bool Slice99_primitive_starts_with ( Slice99  self,
Slice99  prefix 
)
inlinestatic

Checks whether prefix is a prefix of self, byte-by-byte.

Parameters
[in]selfThe slice to be checked for prefix.
[in]prefixThe slice to be checked whether it is a prefix of self.
Returns
true if prefix is a prefix of self, otherwise false.
Precondition
prefix.len must be representable as ptrdiff_t.

◆ Slice99_reverse()

static void Slice99_reverse ( Slice99  self,
void *restrict  backup 
)
inlinestatic

Reverses the order of items in self.

Parameters
[out]selfThe slice to be reversed.
[out]backupThe memory area of self.item_size bytes accessible for reading and writing.
Precondition
backup != NULL
self.len must be representable as ptrdiff_t.

◆ Slice99_size()

static SLICE99_WARN_UNUSED_RESULT SLICE99_CONST size_t Slice99_size ( Slice99  self)
inlinestatic

Computes a total size in bytes.

Parameters
[in]selfThe slice whose size is to be computed.

◆ Slice99_split_at()

static void Slice99_split_at ( Slice99  self,
size_t  i,
Slice99 *restrict  lhs,
Slice99 *restrict  rhs 
)
inlinestatic

Splits self into two parts.

Parameters
[in]selfThe slice to be splitted into lhs and rhs.
[in]iThe index at which self will be splitted.
[out]lhsThe first part of self indexed as [0; i).
[out]rhsThe second part of self indexed as [i; self.len).
Precondition
i <= self.len
lhs != NULL
rhs != NULL
self.len and i must be representable as ptrdiff_t.

◆ Slice99_starts_with()

static SLICE99_WARN_UNUSED_RESULT bool Slice99_starts_with ( Slice99  self,
Slice99  prefix,
int(*)(const void *, const void *)  cmp 
)
inlinestatic

Checks whether prefix is a prefix of self with a user-supplied comparator.

Parameters
[in]selfThe slice to be checked for prefix.
[in]prefixThe slice to be checked whether it is a prefix of self.
[in]cmpThe function deciding whether two items are equal ot not (0 if equal, any other value otherwise).
Returns
true if prefix is a prefix of self, otherwise false.
Precondition
self.item_size == prefix.item_size
cmp != NULL
prefix.len must be representable as ptrdiff_t.

◆ Slice99_sub()

static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_sub ( Slice99  self,
ptrdiff_t  start_idx,
ptrdiff_t  end_idx 
)
inlinestatic

Subslicing self with [start_idx .. end_idx].

Parameters
[in]selfThe original slice.
[in]start_idxThe index at which a new slice will reside, inclusively.
[in]end_idxThe index at which a new slice will end, exclusively.
Returns
A slice with the aforementioned properties.
Precondition
start_idx <= end_idx

◆ Slice99_swap()

static void Slice99_swap ( Slice99  self,
ptrdiff_t  lhs,
ptrdiff_t  rhs,
void *restrict  backup 
)
inlinestatic

Swaps the lhs -indexed and rhs -indexed items.

Parameters
[out]selfThe slice in which lhs and rhs will be swapped.
[in]lhsThe index of the first item.
[in]rhsThe index of the second item.
[out]backupThe memory area of self.item_size bytes accessible for reading and writing.
Precondition
backup != NULL
backup must not overlap with Slice99_get(self, lhs) and Slice99_get(self, rhs).
Slice99_get(self, lhs) and Slice99_get(self, rhs) must not overlap.

◆ Slice99_swap_with_slice()

static void Slice99_swap_with_slice ( Slice99  self,
Slice99  other,
void *restrict  backup 
)
inlinestatic

Swaps all the items in self with those in other.

Parameters
[out]selfThe first slice to be swapped.
[out]otherThe second slice to be swapped.
[out]backupThe memory area of self.item_size bytes accessible for reading and writing.
Precondition
self.len == other.len
self.item_size == other.item_size
backup must not overlap with self and other.
self and other must not overlap.
self.len must be representable as ptrdiff_t.

◆ Slice99_update_len()

static SLICE99_WARN_UNUSED_RESULT Slice99 Slice99_update_len ( Slice99  self,
size_t  new_len 
)
inlinestatic

Updates self with the new length new_len.

Parameters
[in]selfThe slice whose length will be updated.
[in]new_lenThe new length.