str.h
Exposes functions to hendle the string data-type.
- Author: Edward Jones
- Date: 2021-09-17
arr_to_str
Create a string from an array of characters.
- Param
str
: Pointer to the string to create - Param
arr
: Pointer to the array to read
void arr_to_str(Str* str, Array* arr);
copy_into_str
Copy the value of a string into another string starting at a given index. Only mutates if the entire string.
- Param
cont
: The container string to write into - Param
ins
: The insertion string to read from - Param
startIdx
: The index to start writing from
Returns: true
iff startIdx
is low enough to allow all of ins
to fit in cont
otherwise false
bool copy_into_str(Str* cont, Str* ins, size_t startIdx);
dest_free_sig
Destroy and free a string.
- Param
str
: String to destroy
dest_free_sig(str, Str);
dest_str
Destroy a string and free its memory if required.
- Param
str
: Pointer to the string to destroy
void dest_str(Str* str);
get_strc
Get the character at a specified index.
- Param
ret
: Pointer to the return value, creates a Maybe object of constructor JUST iff the index was valid. In this - Param
str
: Pointer to the string to search - Param
idx
: Index to get if valid
void get_strc(Maybe* ret, Str* str, size_t idx);
make_str
Make an empty string.
- Param
str
: Pointer to the String object to initialise
void make_str(Str* str);
make_strc
Make a string by copying another.
- Param
str
: Pointer to the string to make - Param
raw
: Pointer to the raw characters to copy
void make_strc(Str* str, char* raw);
make_strl
Make a string of specified length.
- Param
str
: Pointer to the string to initialise - Param
len
: Length of the string to create
Returns: True iff memory was successfully allocated
bool make_strl(Str* str, size_t len);
make_strr
Make a string by reference to a raw value, freeing the raw value when destroyed.
- Param
str
: Pointer to the string to make - Param
raw
: Pointer to the raw characters
void make_strr(Str* str, char* raw);
make_strv
Make a string by reference to a raw value.
- Param
str
: Pointer to the string to make - Param
raw
: Pointer to the raw characters
void make_strv(Str* str, char* raw);
set_strc
Set the value of a character in a string at a specified index.
- Param
str
: Pointer to the string to mutate - Param
idx
: Index of the mutation - Param
val
: Value to write
Returns: true
if idx
was valid else false
bool set_strc(Str* str, size_t idx, char val);
str_to_arr
Create an array (of character values) from a string.
- Param
arr
: Pointer to the array to make - Param
str
: Pointer to the string whose data will be copied
void str_to_arr(Array* arr, Str* str);