BSB Developer Docs
Loading...
Searching...
No Matches
slice.h File Reference

Slice types for various containers. More...

#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  StringSlice
 Slice of a character string. More...
 
struct  StringSliceOffset
 Offsets in a string slice. More...
 

Functions

void string_slice_reset (StringSlice *instance)
 Reset the slice so that it represents a valid empty string.
 
void string_slice_to_offset (const StringSlice *instance, StringSliceOffset *offset, const char *source)
 Get the offsets from a string slice.
 
void string_slice_from_offset (StringSlice *instance, const StringSliceOffset *offset, const char *source)
 Build a string slice from the source string and offsets.
 
char * string_slice_to_owned_cstr (const StringSlice *instance)
 Copy the slice to a zero-terminated owned string.
 

Detailed Description

Slice types for various containers.

Function Documentation

◆ string_slice_from_offset()

void string_slice_from_offset ( StringSlice * instance,
const StringSliceOffset * offset,
const char * source )

Build a string slice from the source string and offsets.

Parameters
[out]instancepointer to the slice to be populated
[in]offsetpointer to the offset structure containing the offsets
[in]sourcezero-terminated string that the slice will look into

◆ string_slice_reset()

void string_slice_reset ( StringSlice * instance)

Reset the slice so that it represents a valid empty string.

Parameters
[in,out]instancepointer to the slice to be reset

◆ string_slice_to_offset()

void string_slice_to_offset ( const StringSlice * instance,
StringSliceOffset * offset,
const char * source )

Get the offsets from a string slice.

Parameters
[in]instancepointer to the slice to be converted
[out]offsetpointer to the offset structure to hold the results
[in]sourcezero-terminated string that the slice looks into

◆ string_slice_to_owned_cstr()

char * string_slice_to_owned_cstr ( const StringSlice * instance)

Copy the slice to a zero-terminated owned string.

The caller is responsible to free the return value when it is not needed anymore.

Parameters
[in]instancepointer to the slice to be copied
Returns
pointer to the created string (may be empty, but never NULL)