lib<fancy_string> 0.1.1
A C library for easy and fun string manipulation
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
fancy_string.h File Reference
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  fancy_string_regex_match_info_s
 

Typedefs

typedef struct fancy_string_s fancy_string_t
 
typedef struct fancy_string_array_s fancy_string_array_t
 
typedef struct fancy_string_regex_s fancy_string_regex_t
 
typedef struct fancy_string_regex_match_info_s fancy_string_regex_match_info_t
 
typedef enum fancy_string_memory_usage_mode_e fancy_string_memory_usage_mode_t
 
typedef void(* fancy_string_regex_updater_t) (fancy_string_t *const match, size_t start, size_t end, fancy_string_t const *const string, void *context)
 
typedef void(* fancy_string_for_each_t) (fancy_string_t *const string, size_t index, fancy_string_array_t const *const array, void *context)
 
typedef fancy_string_t *(* fancy_string_mapped_t) (fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context)
 
typedef bool(* fancy_string_sort_t) (fancy_string_t const *const string_1, fancy_string_t const *const string_2, void *context)
 
typedef bool(* fancy_string_filter_t) (fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context)
 
typedef bool(* fancy_string_find_t) (fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context)
 

Enumerations

enum  fancy_string_memory_usage_mode_e { FANCY_STRING_MEMORY_USAGE_MODE_NONE , FANCY_STRING_MEMORY_USAGE_MODE_THREAD_LOCAL , FANCY_STRING_MEMORY_USAGE_MODE_GLOBAL_SYNC }
 

Functions

void fancy_string_library_version (uint16_t *major, uint16_t *minor, uint16_t *revision)
 
void fancy_string_library_version_print (FILE *stream)
 
size_t fancy_string_memory_usage_get (void)
 
void fancy_string_memory_usage_debug (FILE *stream)
 
void fancy_string_memory_usage_init (fancy_string_memory_usage_mode_t mode)
 
fancy_string_memory_usage_mode_t fancy_string_memory_usage_mode (void)
 
fancy_string_tfancy_string_create (char const *const value)
 
fancy_string_tfancy_string_from_copied_memory (void const *const pointer, size_t n)
 
fancy_string_tfancy_string_from_stream (FILE *stream)
 
fancy_string_tfancy_string_from_stream_next_line (FILE *stream)
 
fancy_string_tfancy_string_create_repeat (char const *const value, size_t n_repeat)
 
fancy_string_tfancy_string_create_empty (void)
 
fancy_string_tfancy_string_clone (fancy_string_t const *const self)
 
void fancy_string_destroy (fancy_string_t *const self)
 
void fancy_string_print (fancy_string_t const *const self, FILE *stream, bool debug)
 
size_t fancy_string_size (fancy_string_t const *const self)
 
bool fancy_string_is_empty (fancy_string_t const *const self)
 
void fancy_string_clear (fancy_string_t *const self)
 
void fancy_string_update_value (fancy_string_t *const self, char const *const value)
 
void fancy_string_update (fancy_string_t *const self, fancy_string_t const *const string)
 
charfancy_string_value (fancy_string_t const *const self)
 
void fancy_string_append_value (fancy_string_t *const self, char const *const value)
 
void fancy_string_append (fancy_string_t *const self, fancy_string_t const *const string)
 
void fancy_string_prepend_value (fancy_string_t *const self, char const *const value)
 
void fancy_string_prepend (fancy_string_t *const self, fancy_string_t const *const string)
 
bool fancy_string_equals_value (fancy_string_t const *const self, char const *const value)
 
bool fancy_string_equals (fancy_string_t const *const self, fancy_string_t const *const string)
 
bool fancy_string_starts_with_value (fancy_string_t const *const self, char const *const value)
 
bool fancy_string_starts_with (fancy_string_t const *const self, fancy_string_t const *const string)
 
bool fancy_string_ends_with_value (fancy_string_t const *const self, char const *const value)
 
bool fancy_string_ends_with (fancy_string_t const *const self, fancy_string_t const *const string)
 
ssize_t fancy_string_index_of_value (fancy_string_t const *const self, char const *const value)
 
ssize_t fancy_string_index_of (fancy_string_t const *const self, fancy_string_t const *const string)
 
bool fancy_string_contains_value (fancy_string_t const *const self, char const *const value)
 
bool fancy_string_contains (fancy_string_t const *const self, fancy_string_t const *const string)
 
fancy_string_tfancy_string_substring (fancy_string_t const *const self, ssize_t start, ssize_t end)
 
void fancy_string_trim_left (fancy_string_t *const self)
 
fancy_string_tfancy_string_trimmed_left (fancy_string_t const *const self)
 
void fancy_string_trim_right (fancy_string_t *const self)
 
fancy_string_tfancy_string_trimmed_right (fancy_string_t const *const self)
 
void fancy_string_trim (fancy_string_t *const self)
 
fancy_string_tfancy_string_trimmed (fancy_string_t const *const self)
 
fancy_string_array_tfancy_string_split_by_value (fancy_string_t const *const self, char const *const separator, ssize_t n_max_splits)
 
fancy_string_array_tfancy_string_split (fancy_string_t const *const self, fancy_string_t const *const separator, ssize_t n_max_splits)
 
void fancy_string_pad_start (fancy_string_t *const self, size_t target_size, char value)
 
fancy_string_tfancy_string_padded_start (fancy_string_t const *const self, size_t target_size, char value)
 
void fancy_string_pad_end (fancy_string_t *const self, size_t target_size, char value)
 
fancy_string_tfancy_string_padded_end (fancy_string_t const *const self, size_t target_size, char value)
 
void fancy_string_replace_value (fancy_string_t *const self, char const *const old_value, char const *const new_value, ssize_t replace_n)
 
void fancy_string_replace (fancy_string_t *const self, fancy_string_t const *const old_substring, fancy_string_t const *const new_substring, ssize_t replace_n)
 
fancy_string_tfancy_string_replaced_value (fancy_string_t const *const self, char const *const old_value, char const *const new_value, ssize_t replace_n)
 
fancy_string_tfancy_string_replaced (fancy_string_t const *const self, fancy_string_t const *const old_substring, fancy_string_t const *const new_substring, ssize_t replace_n)
 
void fancy_string_lowercase (fancy_string_t *const self)
 
fancy_string_tfancy_string_lowercased (fancy_string_t const *const self)
 
void fancy_string_uppercase (fancy_string_t *const self)
 
fancy_string_tfancy_string_uppercased (fancy_string_t const *const self)
 
void fancy_string_line_break (fancy_string_t *const self, bool with_carriage_return)
 
fancy_string_regex_tfancy_string_regex_create (fancy_string_t const *const string, fancy_string_t const *const pattern, ssize_t n_max_matches)
 
void fancy_string_regex_destroy (fancy_string_regex_t *const self)
 
void fancy_string_regex_debug (fancy_string_regex_t const *const self, FILE *stream, bool verbose)
 
fancy_string_array_tfancy_string_regex_matches_to_strings (fancy_string_regex_t const *const self)
 
fancy_string_tfancy_string_regex_replaced_matches (fancy_string_regex_t *const self, fancy_string_t *new_string)
 
fancy_string_array_tfancy_string_regex_split_at_matches (fancy_string_regex_t const *const self)
 
size_t fancy_string_regex_match_count (fancy_string_regex_t const *const self)
 
bool fancy_string_regex_has_match (fancy_string_regex_t const *const self)
 
ssize_t fancy_string_regex_max_number_of_matches (fancy_string_regex_t const *const self)
 
bool fancy_string_regex_max_number_of_matches_reached (fancy_string_regex_t const *const self)
 
fancy_string_tfancy_string_regex_string (fancy_string_regex_t const *const self)
 
fancy_string_tfancy_string_regex_pattern (fancy_string_regex_t const *const self)
 
fancy_string_tfancy_string_regex_to_string_with_updated_matches (fancy_string_regex_t const *const self, fancy_string_regex_updater_t fn, void *context)
 
fancy_string_regex_match_info_t fancy_string_regex_match_info_for_index (fancy_string_regex_t const *const self, size_t index)
 
fancy_string_tfancy_string_regex_string_for_match_at_index (fancy_string_regex_t const *const self, size_t index)
 
fancy_string_array_tfancy_string_array_create (void)
 
fancy_string_array_tfancy_string_array_create_with_values (char const *const first_value,...)
 
fancy_string_array_tfancy_string_array_clone (fancy_string_array_t const *const self)
 
void fancy_string_array_append (fancy_string_array_t *const self, fancy_string_array_t const *const array)
 
void fancy_string_array_append_and_destroy (fancy_string_array_t *const self, fancy_string_array_t *array)
 
void fancy_string_array_destroy (fancy_string_array_t *const self)
 
void fancy_string_array_print (fancy_string_array_t const *const self, FILE *stream, bool debug)
 
void fancy_string_array_clear (fancy_string_array_t *const self)
 
size_t fancy_string_array_size (fancy_string_array_t const *const self)
 
bool fancy_string_array_is_empty (fancy_string_array_t const *const self)
 
void fancy_string_array_push_value (fancy_string_array_t *const self, char const *const value)
 
void fancy_string_array_push_values (fancy_string_array_t *const self, char const *const first_value,...)
 
void fancy_string_array_push (fancy_string_array_t *const self, fancy_string_t const *const string)
 
fancy_string_tfancy_string_array_get (fancy_string_array_t const *const self, size_t index)
 
charfancy_string_array_get_value (fancy_string_array_t const *const self, size_t index)
 
fancy_string_tfancy_string_array_remove (fancy_string_array_t *const self, size_t index)
 
void fancy_string_array_remove_and_destroy (fancy_string_array_t *const self, size_t index)
 
fancy_string_tfancy_string_array_pop (fancy_string_array_t *const self)
 
void fancy_string_array_pop_and_destroy (fancy_string_array_t *const self)
 
fancy_string_tfancy_string_array_shift (fancy_string_array_t *const self)
 
void fancy_string_array_shift_and_destroy (fancy_string_array_t *const self)
 
void fancy_string_array_insert_value (fancy_string_array_t *const self, char const *const value, size_t index)
 
void fancy_string_array_insert (fancy_string_array_t *const self, fancy_string_t const *const string, size_t index)
 
fancy_string_tfancy_string_array_first (fancy_string_array_t const *const self)
 
charfancy_string_array_first_value (fancy_string_array_t const *const self)
 
fancy_string_tfancy_string_array_last (fancy_string_array_t const *const self)
 
charfancy_string_array_last_value (fancy_string_array_t const *const self)
 
fancy_string_tfancy_string_array_join_by_value (fancy_string_array_t const *const self, char const *const separator)
 
fancy_string_tfancy_string_array_join (fancy_string_array_t const *const self, fancy_string_t const *const separator)
 
void fancy_string_array_reverse (fancy_string_array_t *const self)
 
fancy_string_array_tfancy_string_array_reversed (fancy_string_array_t const *const self)
 
void fancy_string_array_for_each (fancy_string_array_t *const self, fancy_string_for_each_t fn, void *context)
 
fancy_string_array_tfancy_string_array_mapped (fancy_string_array_t const *const self, fancy_string_mapped_t fn, void *context)
 
void fancy_string_array_sort (fancy_string_array_t *const self, fancy_string_sort_t fn, void *context)
 
fancy_string_array_tfancy_string_array_sorted (fancy_string_array_t const *const self, fancy_string_sort_t fn, void *context)
 
void fancy_string_array_sort_values (fancy_string_array_t *const self)
 
fancy_string_array_tfancy_string_array_sorted_values (fancy_string_array_t const *const self)
 
void fancy_string_array_filter (fancy_string_array_t *const self, fancy_string_filter_t fn, void *context)
 
fancy_string_array_tfancy_string_array_filtered (fancy_string_array_t const *const self, fancy_string_filter_t fn, void *context)
 
fancy_string_array_tfancy_string_array_sliced (fancy_string_array_t const *const self, ssize_t start, ssize_t end)
 
void fancy_string_array_slice_and_destroy (fancy_string_array_t *const self, ssize_t start, ssize_t end)
 
fancy_string_array_tfancy_string_array_splice (fancy_string_array_t *const self, size_t index, ssize_t delete_count, fancy_string_array_t const *const optional_new_strings)
 
void fancy_string_array_splice_and_destroy (fancy_string_array_t *const self, size_t index, ssize_t delete_count, fancy_string_array_t const *const optional_new_strings)
 
fancy_string_array_tfancy_string_array_spliced (fancy_string_array_t const *const self, size_t index, ssize_t delete_count, fancy_string_array_t const *const optional_new_strings)
 
ssize_t fancy_string_array_find_index (fancy_string_array_t const *const self, fancy_string_find_t fn, void *context)
 
fancy_string_tfancy_string_array_find (fancy_string_array_t const *const self, fancy_string_find_t fn, void *context)
 
ssize_t fancy_string_array_find_last_index (fancy_string_array_t const *const self, fancy_string_find_t fn, void *context)
 
fancy_string_tfancy_string_array_find_last (fancy_string_array_t const *const self, fancy_string_find_t fn, void *context)
 
bool fancy_string_array_some (fancy_string_array_t const *const self, fancy_string_find_t fn, void *context)
 
bool fancy_string_array_none (fancy_string_array_t const *const self, fancy_string_find_t fn, void *context)
 
bool fancy_string_array_every (fancy_string_array_t const *const self, fancy_string_find_t fn, void *context)
 
ssize_t fancy_string_array_index_of (fancy_string_array_t const *const self, fancy_string_t const *const string)
 
ssize_t fancy_string_array_index_of_value (fancy_string_array_t const *const self, char const *const value)
 
ssize_t fancy_string_array_last_index_of (fancy_string_array_t const *const self, fancy_string_t const *const string)
 
ssize_t fancy_string_array_last_index_of_value (fancy_string_array_t const *const self, char const *const value)
 
bool fancy_string_array_includes (fancy_string_array_t const *const self, fancy_string_t const *const string)
 
bool fancy_string_array_includes_value (fancy_string_array_t const *const self, char const *const value)
 

Data Structure Documentation

◆ fancy_string_regex_match_info_s

struct fancy_string_regex_match_info_s

A type (i.e., a structure), returned by the fancy_string_regex_match_info_for_index() method, containing information about a particular match.

See also
fancy_string_regex_match_info_for_index
Data Fields
size_t end The 'end' position of the match at position index .
Note
This value has a '1-position offset (to the right)' from the last matched character. For instance, let's say that we had the string 'This is a test.', and that we matched ' is ', then we will get { .start = 4, .end = 8 }.
ssize_t index The index (i.e., the position) of the match inside the fancy_string_regex_t instance.
Note
A value of -1 indicates that the index specified when calling fancy_string_regex_match_info_for_index() was out of bounds. In other words, index should match the value specified when calling fancy_string_regex_match_info_for_index(), provided that that value was not out of bounds.
size_t start The 'start' position of the match at position index .

Typedef Documentation

◆ fancy_string_array_t

typedef struct fancy_string_array_s fancy_string_array_t

An opaque type that serves as a container for a list of fancy_string_t instances and which is passed to the library's "array" methods for state interrogation and manipulation.

Note
Since the fancy_string_array_t type is opaque, the only way to work with it is through a pointer whose memory has been heap-allocated by a factory method such as fancy_string_array_create().
Warning
Once the array object is no longer needed, it is the application's job to call fancy_string_array_destroy() to destroy all of the internally referenced string objects and free the internal pointer list's memory.
See also
fancy_string_array_destroy, fancy_string_array_create

◆ fancy_string_filter_t

typedef bool(* fancy_string_filter_t) (fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context)

The signature a callback function needs to implement to be allowed to be passed as argument to the fancy_string_array_filter and fancy_string_array_filtered methods.

Parameters
stringA pointer to the fancy_string_t instance that is subject to being filtered, which instance is found at position index in array .
indexThe position (i.e., index) of string in array .
arrayA pointer to the fancy_string_array_t instance inside of which string exists.
contextAn application-defined context object.
Returns
bool A boolean value that is set to true if string has been retained, or set to false if string has been filtered out.
See also
fancy_string_array_filter, fancy_string_array_filtered

◆ fancy_string_find_t

typedef bool(* fancy_string_find_t) (fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context)

The signature a callback function needs to implement to be allowed to be passed as argument to methods such as fancy_string_array_find_index and fancy_string_array_find .

Parameters
stringA pointer to the fancy_string_t instance found at position index in array .
indexThe position of string in array .
arrayA pointer to the fancy_string_array_t instance inside which string exists.
contextAn application-defined context object.
Returns
bool A boolean value indicating whether or not (true or false) the string object string at position index in the array object array was retained by the implementor of this interface.
See also
fancy_string_array_find_index, fancy_string_array_find, fancy_string_array_find_last_index, fancy_string_array_find_last, fancy_string_array_some, fancy_string_array_none, fancy_string_array_every

◆ fancy_string_for_each_t

typedef void(* fancy_string_for_each_t) (fancy_string_t *const string, size_t index, fancy_string_array_t const *const array, void *context)

The signature a callback function needs to implement to be allowed to be passed as argument to the fancy_string_array_for_each() method.

Parameters
stringA pointer to the fancy_string_t instance on which to operate, which is found at position index in the array object array .
indexThe position (i.e., index) of string in array .
arrayA pointer to the fancy_string_array_t instance inside of which string exists.
contextAn application-defined context object.
See also
fancy_string_array_for_each

◆ fancy_string_mapped_t

typedef fancy_string_t *(* fancy_string_mapped_t) (fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context)

The signature a callback function needs to implement to be allowed to be passed as argument to the fancy_string_array_mapped() method.

Parameters
stringA pointer to the fancy_string_t instance found at position index in the array object array .
indexThe position of string in array .
arrayA pointer to the fancy_string_array_t instance inside which string exists.
contextAn application-defined context object.
Returns
fancy_string_t* A pointer to a string object created and returned by the callback.
See also
fancy_string_array_mapped

◆ fancy_string_memory_usage_mode_t

An enumeration whose members can be used to specify, through the fancy_string_memory_usage_init() static method, the memory usage tracking mode to be used by the library. By default, FANCY_STRING_MEMORY_USAGE_MODE_NONE is used, such that memory tracking is not enabled.

Warning
The memory usage tracking feature is meant to be used during development only, as a tool for aiding in tracking down potential memory leaks linked to erroneous library usage (i.e., not destroying objects before they go out of scope). This feature has not been optimized and will incur substantial overhead when enabled (even if optimized, there would still be incurred overhead).
See also
fancy_string_memory_usage_init

◆ fancy_string_regex_match_info_t

A type (i.e., a structure), returned by the fancy_string_regex_match_info_for_index() method, containing information about a particular match.

See also
fancy_string_regex_match_info_for_index

◆ fancy_string_regex_t

typedef struct fancy_string_regex_s fancy_string_regex_t

An opaque type that serves as a container for regular expression matching results, and which is passed to the library's "regex" methods for state interrogation and manipulation.

Note
Since the fancy_string_regex_t type is opaque, the only way to work with it is through a pointer whose memory has been heap-allocated by a factory method such as fancy_string_regex_create().
Warning
Once the regex object is no longer needed, it is the application's job to call fancy_string_regex_destroy() to destroy all of the internally referenced objects and free the internal pointers' memory.
See also
fancy_string_regex_destroy, fancy_string_regex_create

◆ fancy_string_regex_updater_t

typedef void(* fancy_string_regex_updater_t) (fancy_string_t *const match, size_t start, size_t end, fancy_string_t const *const string, void *context)

The signature a callback function needs to implement to be allowed to be passed as argument to the fancy_string_regex_to_string_with_updated_matches() method.

Parameters
matchA pointer to the fancy_string_t instance on which to operate, which corresponds to the matched string at position start to end (where end is 1 position more than the last character of the match) inside the regular expression object's string object.
startThe start position of the match in the regular expression object's string object.
endThe end position of the match in the regular expression object's string object. Note that this value is "one" position more than the last character of the match.
contextA pointer to the application-defined context object.
See also
fancy_string_regex_to_string_with_updated_matches

◆ fancy_string_sort_t

typedef bool(* fancy_string_sort_t) (fancy_string_t const *const string_1, fancy_string_t const *const string_2, void *context)

The signature a callback function needs to implement to be allowed to be passed as argument to the fancy_string_array_sort and the fancy_string_array_sorted methods.

Parameters
string_1A pointer to a fancy_string_t instance to be compared to string_2 .
string_2A pointer to a fancy_string_t instance to be compared to string_1 .
contextAn application-defined context object.
Returns
bool A boolean value that is set to false if string_1 was determined to be lesser than or equal to string_2 , else, it is set to true.
See also
fancy_string_array_sort, fancy_string_array_sorted

◆ fancy_string_t

typedef struct fancy_string_s fancy_string_t

An opaque type that serves as a container for the string data and which is passed to the library's "string" methods for state interrogation and manipulation.

Note
Since the fancy_string_t type is opaque, the only way to work with it is through a pointer whose memory has been heap-allocated by a factory method such as fancy_string_create().
Warning
Once the string object is no longer needed, it is the application's job to call fancy_string_destroy() to free the memory that is referenced internally.
See also
fancy_string_destroy, fancy_string_create

Enumeration Type Documentation

◆ fancy_string_memory_usage_mode_e

An enumeration whose members can be used to specify, through the fancy_string_memory_usage_init() static method, the memory usage tracking mode to be used by the library. By default, FANCY_STRING_MEMORY_USAGE_MODE_NONE is used, such that memory tracking is not enabled.

Warning
The memory usage tracking feature is meant to be used during development only, as a tool for aiding in tracking down potential memory leaks linked to erroneous library usage (i.e., not destroying objects before they go out of scope). This feature has not been optimized and will incur substantial overhead when enabled (even if optimized, there would still be incurred overhead).
See also
fancy_string_memory_usage_init
Enumerator
FANCY_STRING_MEMORY_USAGE_MODE_NONE 

Disables the library's memory usage tracking feature. This is the default behaviour.

FANCY_STRING_MEMORY_USAGE_MODE_THREAD_LOCAL 

Tracks memory usage and stores the tracking data in a private static variable for each thread using the library.

Note
This mode should be preferred to FANCY_STRING_MEMORY_USAGE_MODE_GLOBAL_SYNC for single threaded applications, since there is less overhead associated with it (the latter uses a mutex each time library memory is allocated, re-allocated, and freed throughout the whole process).
Warning
When this mode is used, the library objects should not be shared between threads, else application crashes will occur.
FANCY_STRING_MEMORY_USAGE_MODE_GLOBAL_SYNC 

Tracks memory usage and stores the tracking data in a private static variable shared by all threads. Internally, synchronization is achieved using pthread_mutex_t.

Note
Of the three (two) modes, this mode is the one that has the most overhead associated with it, because all of the process' memory that is allocated, re-allocated, and freed goes through a mutex lock for the whole process.

Function Documentation

◆ fancy_string_append()

void fancy_string_append ( fancy_string_t *const  self,
fancy_string_t const *const  string 
)

Appends a string object's data (in this case string ) to the current string object's internal state (i.e., to self ).

Parameters
selfA pointer to the fancy_string_t instance to which to append.
stringA pointer to another fancy_string_t instance whose internal data is to be copied and appended to self 's internal data.
See also
fancy_string_append_value

◆ fancy_string_append_value()

void fancy_string_append_value ( fancy_string_t *const  self,
char const *const  value 
)

Appends a (string) value to the current string object's internal state.

Parameters
selfA pointer to the fancy_string_t instance to which to append a copy of value .
valueThe value (i.e., a pointer to a null-terminated string) to be appended to the internal string data.
See also
fancy_string_append

◆ fancy_string_array_append()

void fancy_string_array_append ( fancy_string_array_t *const  self,
fancy_string_array_t const *const  array 
)

Appends the elements of another array object (i.e., array ) into the current array object (i.e., self ).

Parameters
selfA pointer to the fancy_string_array_t instance to which to append copies of the array 's elements.
arrayA pointer to another fancy_string_array_t instance whose fancy_string_t elements are to be copied and appended to self .
See also
fancy_string_array_append_and_destroy

◆ fancy_string_array_append_and_destroy()

void fancy_string_array_append_and_destroy ( fancy_string_array_t *const  self,
fancy_string_array_t array 
)

Appends the elements of another array object (i.e., array) into the current array object (i.e., self), and then internally calls fancy_string_array_destroy() on array.

Parameters
selfA pointer to the fancy_string_array_t instance to which to append a copy of array 's elements.
arrayA pointer to another fancy_string_array_t instance whose fancy_string_t elements are to be copied and appended to self, and which is to subsequently be destroyed.
See also
fancy_string_array_append, fancy_string_array_destroy
Deprecated:
Looking back, this method should not have existed from the beginning, since it is not consistent with other methods whose names are ending with _and_destroy.

◆ fancy_string_array_clear()

void fancy_string_array_clear ( fancy_string_array_t *const  self)

Clears (i.e, empties) the array; i.e., destroys all of the internal fancy_string_t instances and frees the internal memory that was allocated to track those instances.

Parameters
selfA pointer to the fancy_string_array_t instance to be cleared.

◆ fancy_string_array_clone()

fancy_string_array_t * fancy_string_array_clone ( fancy_string_array_t const *const  self)

Clones an array object.

Parameters
selfA pointer to the fancy_string_array_t instance to be cloned.
Returns
fancy_string_array_t* A pointer to the newly created, memory-independent array object that is a clone of self .

◆ fancy_string_array_create()

fancy_string_array_t * fancy_string_array_create ( void  )

Instantiates an empty array object (i.e, a list whose components are string objects).

Returns
fancy_string_array_t* A pointer to the created array object.

◆ fancy_string_array_create_with_values()

fancy_string_array_t * fancy_string_array_create_with_values ( char const *const  first_value,
  ... 
)

Instantiates an array object with a variable list of string values (i.e., pointers to a null-terminated strings).

Parameters
first_valueA pointer to the first string value (i.e., a null-terminated string) argument to be used to instantiate a memory-independent string object to be added first to the array.
...A variable number of null-terminated string pointers (i.e., char *) to be used, in the order they appear, in the same way as first_value . Important: The last value should be the NULL pointer, unless first_value itself is NULL , in which case all other arguments will be ignored and an empty array will be returned.
Returns
fancy_string_array_t* A pointer to the created array object containing the string objects specified as arguments.
Warning
Internally, this method is based on the macros defined by stdarg.h , which means that a way of knowing where to stop, when reading the variable list of argument, is needed. The adopted approach here is therefore to add the NULL pointer as the last argument. If NULL is omitted, the result will be unpredictable.
See also
fancy_string_array_create, fancy_string_array_push_values
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
"one",
"two",
"three",
"four",
"five",
NULL);
assert(fancy_string_equals_value(s, "one two three four five"));
return 0;
}
fancy_string_t * fancy_string_array_join_by_value(fancy_string_array_t const *const self, char const *const separator)
Creates (and returns a pointer to) a fancy_string_t instance and populates it with copies of the arra...
size_t fancy_string_array_size(fancy_string_array_t const *const self)
Returns the array object's size; i.e., the number of fancy_string_t instances it contains.
bool fancy_string_equals_value(fancy_string_t const *const self, char const *const value)
Checks whether the string object's internal value equals to value .
void fancy_string_print(fancy_string_t const *const self, FILE *stream, bool debug)
Prints (i.e., writes) the string object's data to the specified stream .
struct fancy_string_s fancy_string_t
An opaque type that serves as a container for the string data and which is passed to the library's "s...
Definition: fancy_string.h:54
void fancy_string_array_print(fancy_string_array_t const *const self, FILE *stream, bool debug)
Prints (i.e., writes) the array's string contents to the specified stream .
void fancy_string_array_destroy(fancy_string_array_t *const self)
Destroys the array object; i.e., frees the memory that was allocated for the internal pointers to fan...
fancy_string_array_t * fancy_string_array_create_with_values(char const *const first_value,...)
Instantiates an array object with a variable list of string values (i.e., pointers to a null-terminat...
void fancy_string_destroy(fancy_string_t *const self)
Destroys the string object; i.e., frees the memory that was allocated for the internal string data,...
struct fancy_string_array_s fancy_string_array_t
An opaque type that serves as a container for a list of fancy_string_t instances and which is passed ...
Definition: fancy_string.h:68
NULL NULL
FILE stdout

◆ fancy_string_array_destroy()

void fancy_string_array_destroy ( fancy_string_array_t *const  self)

Destroys the array object; i.e., frees the memory that was allocated for the internal pointers to fancy_string_t instances and destroys those string instances using fancy_string_destroy().

Parameters
selfA reference to the fancy_string_array_t instance to be destroyed.
See also
fancy_string_destroy
Warning
This method should only be called once per object, else a double-free error might incur.

◆ fancy_string_array_every()

bool fancy_string_array_every ( fancy_string_array_t const *const  self,
fancy_string_find_t  fn,
void context 
)

Checks whether fn returns true for all of the elements in the array object's internal list.

Parameters
selfA pointer to the fancy_string_array_t instance to be checked.
fnA pointer to a function conforming to the fancy_string_find_t interface, which function gets called (internally) until a non-match (i.e., false value) is returned, in which case the method will return false, else the function will return true, which will mean that all elements are matching.
contextAn application-defined context object that gets passed to fn on each call.
Returns
bool A boolean value indicating whether or not (i.e., true or false) fn returned true for all of the elements in the array object's internal list.
See also
fancy_string_find_t, fancy_string_array_none, fancy_string_array_some
Note
See the documentation for fancy_string_array_find_index for an example on how to use methods accepting a pointer to a function conforming to fancy_string_find_t for the purpose of identifying elements inside an array object.

◆ fancy_string_array_filter()

void fancy_string_array_filter ( fancy_string_array_t *const  self,
fancy_string_filter_t  fn,
void context 
)

Filters (therefore likely mutates) the array object's internal list's elements based on the rules established by the fn callback.

Parameters
selfA pointer to the fancy_string_array_t instance whose elements are to be filtered.
fnA pointer to the filtering function to be used.
contextAn application-defined context object.
See also
fancy_string_filter_t, fancy_string_array_filtered
Note
Internally, this method will call fancy_string_array_remove_and_destroy on the elements that have been filtered out.
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
#define IGNORE_UNUSED(x) ((void)(x))
struct my_context
{
char *starts_with;
};
static bool callback(fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context)
{
IGNORE_UNUSED(index);
IGNORE_UNUSED(array);
struct my_context *c = (struct my_context *)context;
return fancy_string_starts_with_value(string, c->starts_with);
}
int main(void)
{
char *value = "Julie John Jeff Karina Francis Joe Lucas Eric";
char *filtered = "Julie John Jeff Joe";
struct my_context context = {.starts_with = "J"};
fancy_string_array_filter(a, callback, &context);
assert(fancy_string_equals_value(s_filtered, filtered));
fancy_string_destroy(s_filtered);
return 0;
}
bool fancy_string_starts_with_value(fancy_string_t const *const self, char const *const value)
Checks whether the string object's internal value starts with value.
fancy_string_t * fancy_string_create(char const *const value)
Instantiates a string object with its internal state specified by the value parameter.
void fancy_string_array_filter(fancy_string_array_t *const self, fancy_string_filter_t fn, void *context)
Filters (therefore likely mutates) the array object's internal list's elements based on the rules est...
fancy_string_array_t * fancy_string_split_by_value(fancy_string_t const *const self, char const *const separator, ssize_t n_max_splits)
Splits the string into an array (i.e., a list) of string objects based on the separator .

◆ fancy_string_array_filtered()

fancy_string_array_t * fancy_string_array_filtered ( fancy_string_array_t const *const  self,
fancy_string_filter_t  fn,
void context 
)

Clones the array object (i.e., self ) and performs filtering on that clone, based on the rules established by the fn callback.

Parameters
selfA pointer to the fancy_string_array_t instance to be cloned and whose clone's elements to be filtered.
fnA pointer to the filtering function to be used.
contextAn application-defined context object.
Returns
fancy_string_array_t* A pointer to the created, memory-independent filtered array object.
See also
fancy_string_filter_t, fancy_string_array_filter
Note
See the documentation for the fancy_string_array_filter method for an example that illustrates how a filtering function (to be passed as fn ) can be defined.

◆ fancy_string_array_find()

fancy_string_t * fancy_string_array_find ( fancy_string_array_t const *const  self,
fancy_string_find_t  fn,
void context 
)

Finds the first element in the array object's internal list for which fn returns true and returns a memory-independent copy of that element.

Parameters
selfA pointer to the fancy_string_array_t instance inside of which to look for a matching element.
fnA pointer to a function conforming to the fancy_string_find_t interface, which function gets called (internally) until the first match (i.e., true value) is returned.
contextAn application-defined context object that gets passed to fn on each call.
Returns
fancy_string_t* A pointer to a memory-independent copy of the first string object in self for which fn returned true. The NULL pointer is returned if all fn calls returned false, which indicates that not a single match was found.
See also
fancy_string_find_t, fancy_string_array_find_index
Note
See the documentation for fancy_string_array_find_index for an example on how to use methods accepting a pointer to a function conforming to fancy_string_find_t for the purpose of identifying elements inside an array object.

◆ fancy_string_array_find_index()

ssize_t fancy_string_array_find_index ( fancy_string_array_t const *const  self,
fancy_string_find_t  fn,
void context 
)

Finds the first element in the array object's internal list for which fn returns true and returns that element's position.

Parameters
selfA pointer to the fancy_string_array_t instance inside of which to look for a matching element.
fnA pointer to a function conforming to the fancy_string_find_t interface, which function gets called (internally) until the first match (i.e., true value) is returned.
contextAn application-defined context object that gets passed to fn on each call.
Returns
ssize_t The position (i.e., index) of the first string object in self for which fn returned true. The value -1 is returned if all fn calls returned false, which indicates that not a single match was found.
See also
fancy_string_find_t, fancy_string_array_find
Example:
#include <assert.h>
#include "fancy_string.h"
#define IGNORE_UNUSED(x) ((void)(x))
enum my_context_type
{
MY_CONTEXT_TYPE_STARTS_WITH,
MY_CONTEXT_TYPE_ENDS_WITH
};
struct my_context
{
char *string;
enum my_context_type type;
};
static bool my_callback(fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context)
{
IGNORE_UNUSED(index);
IGNORE_UNUSED(array);
struct my_context *c = (struct my_context *)context;
switch (c->type)
{
case MY_CONTEXT_TYPE_STARTS_WITH:
return fancy_string_starts_with_value(string, c->string);
case MY_CONTEXT_TYPE_ENDS_WITH:
return fancy_string_ends_with_value(string, c->string);
}
}
int main(void)
{
struct my_context context;
context = (struct my_context){.type = MY_CONTEXT_TYPE_STARTS_WITH, .string = "J"};
assert(fancy_string_array_find_index(a, my_callback, &context) == 3);
context = (struct my_context){.type = MY_CONTEXT_TYPE_STARTS_WITH, .string = "A"};
assert(fancy_string_array_find_index(a, my_callback, &context) == 0);
context = (struct my_context){.type = MY_CONTEXT_TYPE_STARTS_WITH, .string = "Z"};
assert(fancy_string_array_find_index(a, my_callback, &context) == -1);
context = (struct my_context){.type = MY_CONTEXT_TYPE_ENDS_WITH, .string = "o"};
assert(fancy_string_array_find_index(a, my_callback, &context) == 0);
context = (struct my_context){.type = MY_CONTEXT_TYPE_ENDS_WITH, .string = "s"};
assert(fancy_string_array_find_index(a, my_callback, &context) == 6);
return 0;
}
void fancy_string_array_push_value(fancy_string_array_t *const self, char const *const value)
Instantiates a string object, with internal state set to value , and appends it at the end of the arr...
bool fancy_string_ends_with_value(fancy_string_t const *const self, char const *const value)
Checks whether the string object's internal value ends with value .
fancy_string_array_t * fancy_string_array_create(void)
Instantiates an empty array object (i.e, a list whose components are string objects).
ssize_t fancy_string_array_find_index(fancy_string_array_t const *const self, fancy_string_find_t fn, void *context)
Finds the first element in the array object's internal list for which fn returns true and returns tha...

◆ fancy_string_array_find_last()

fancy_string_t * fancy_string_array_find_last ( fancy_string_array_t const *const  self,
fancy_string_find_t  fn,
void context 
)

Finds the last element in the array object's internal list for which fn returns true and returns a memory-independent copy of that element.

Parameters
selfA pointer to the fancy_string_array_t instance inside of which to look for a matching element.
fnA pointer to a function conforming to the fancy_string_find_t interface, which function gets called (internally; starting from the last element to the first) until a match (i.e., true value) is returned.
contextAn application-defined context object that gets passed to fn on each call.
Returns
fancy_string_t* A pointer to a memory-independent copy of the first string object in self for which fn returned true. The NULL pointer is returned if all fn calls returned false, which indicates that not a single match was found.
See also
fancy_string_find_t, fancy_string_array_find_last_index
Note
See the documentation for fancy_string_array_find_index for an example on how to use methods accepting a pointer to a function conforming to fancy_string_find_t for the purpose of identifying elements inside an array object.

◆ fancy_string_array_find_last_index()

ssize_t fancy_string_array_find_last_index ( fancy_string_array_t const *const  self,
fancy_string_find_t  fn,
void context 
)

Finds the last element in the array object's internal list for which fn returns true and returns that element's position.

Parameters
selfA pointer to the fancy_string_array_t instance inside of which to look for the last matching element.
fnA pointer to a function conforming to the fancy_string_find_t interface, which function gets called (internally; starting from the last element to the first) until a match (i.e., true value) is returned.
contextAn application-defined context object that gets passed to fn on each call.
Returns
ssize_t The position (i.e., index) of the last string object in self for which fn returned true. The value -1 is returned if all fn calls returned false, which indicates that not a single match was found.
See also
fancy_string_find_t, fancy_string_array_find_last
Note
See the documentation for fancy_string_array_find_index for an example on how to use methods accepting a pointer to a function conforming to fancy_string_find_t for the purpose of identifying elements inside an array object.

◆ fancy_string_array_first()

fancy_string_t * fancy_string_array_first ( fancy_string_array_t const *const  self)

Returns a memory-independent copy of the array object's internal list's first string object.

Parameters
selfA pointer to the fancy_string_array_t instance for which the first element of the internal list is to be copied and returned.
Returns
fancy_string_t* A pointer to a fancy_string_t instance that corresponds to the array object's internal list's first string object (a copy of it). If the array object is empty, the NULL pointer is returned.
See also
fancy_string_array_first_value

◆ fancy_string_array_first_value()

char * fancy_string_array_first_value ( fancy_string_array_t const *const  self)

Returns a memory-independent copy of the array object's internal list's first string object's internal string value (i.e., a pointer to a null-terminated string).

Parameters
selfA pointer to the fancy_string_array_t instance for which the first element of the internal list is to have its internal string value copied and returned as a pointer.
Returns
char* A pointer to null-terminated string data that was copied from the first element of the array object's internal list. If the array object is empty, the NULL pointer is returned.
See also
fancy_string_array_first

◆ fancy_string_array_for_each()

void fancy_string_array_for_each ( fancy_string_array_t *const  self,
fancy_string_for_each_t  fn,
void context 
)

Iterates over the array object's elements and calls the fn callback with each element (i.e., fancy_string_t instance), along with its position and a reference to its parent array object.

Parameters
selfA pointer to the fancy_string_array_t instance whose internal list's elements are to be iterated over with the specified callback fn.
fnA pointer to the function to be called for each element in the array.
contextAn application-defined context object that will be passed to fn , along with each individual fancy_string_t instance contained in the array object's internal list.
See also
fancy_string_for_each_t
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
#define IGNORE_UNUSED(x) ((void)(x))
struct my_context
{
char *prefix;
size_t skip_indexes_above;
};
static void callback(fancy_string_t *const string, size_t index, fancy_string_array_t const *const array, void *context)
{
IGNORE_UNUSED(array);
struct my_context *c = (struct my_context *)context;
if (index > c->skip_indexes_above)
{
return;
}
fancy_string_prepend_value(string, c->prefix);
}
int main(void)
{
struct my_context context = {.prefix = "HEY_", .skip_indexes_above = 2};
fancy_string_array_for_each(a, callback, &context);
assert(fancy_string_equals_value(s, "HEY_anna HEY_nathan HEY_john jules liz"));
return 0;
}
void fancy_string_array_for_each(fancy_string_array_t *const self, fancy_string_for_each_t fn, void *context)
Iterates over the array object's elements and calls the fn callback with each element (i....
void fancy_string_prepend_value(fancy_string_t *const self, char const *const value)
Prepends a (string) value to the current string object's internal state.

◆ fancy_string_array_get()

fancy_string_t * fancy_string_array_get ( fancy_string_array_t const *const  self,
size_t  index 
)

Returns a memory-independent copy of the fancy_string_t instance located at position index inside the array object.

Parameters
selfA pointer to the fancy_string_array_t instance whose index -th element is to be cloned and returned.
indexThe position (in the array object's internal list) of the sought element (i.e., fancy_string_t instance).
Returns
fancy_string_t* A memory-independent copy of the fancy_string_t instance at position index . If index is out of bounds, then the NULL pointer is returned.
See also
fancy_string_array_get_value

◆ fancy_string_array_get_value()

char * fancy_string_array_get_value ( fancy_string_array_t const *const  self,
size_t  index 
)

Returns a memory-independent copy of the fancy_string_t instance's internal state (i.e., string data) located at position index inside the array object.

Parameters
selfA pointer to the fancy_string_array_t instance whose index -th element is to have its internal state cloned and returned.
indexThe position (in the array object's internal list) of the sought element (i.e., fancy_string_t instance's value).
Returns
char* A memory-independent copy (i.e., a pointer to a null-terminated string) of the fancy_string_t instance's internal state at position index . If index is out of bounds, then the NULL pointer is returned.
See also
fancy_string_array_get

◆ fancy_string_array_includes()

bool fancy_string_array_includes ( fancy_string_array_t const *const  self,
fancy_string_t const *const  string 
)

Checks whether a string object's internal value is contained inside the array object's internal list.

Parameters
selfA pointer to the fancy_string_array_t instance to be searched for the presence of at least one matching element.
stringA pointer to the fancy_string_t instance for whose internal value to search.
Returns
bool A boolean value that indicates whether or not (true or false) at least one match was found.
See also
fancy_string_array_includes_value
Example:
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
{
fancy_string_update_value(name, "caesar");
}
return 0;
}
bool fancy_string_array_includes_value(fancy_string_array_t const *const self, char const *const value)
Checks whether the value value is contained inside the array object's internal list.
void fancy_string_update_value(fancy_string_t *const self, char const *const value)
Updates the internal state of the string object with the new string data (i.e., value ).
bool fancy_string_array_includes(fancy_string_array_t const *const self, fancy_string_t const *const string)
Checks whether a string object's internal value is contained inside the array object's internal list.

◆ fancy_string_array_includes_value()

bool fancy_string_array_includes_value ( fancy_string_array_t const *const  self,
char const *const  value 
)

Checks whether the value value is contained inside the array object's internal list.

Parameters
selfA pointer to the fancy_string_array_t instance to be searched for the presence of at least one matching element.
valueA pointer to a null-terminated string value for which to search.
Returns
bool A boolean value that indicates whether or not (true or false) at least one match was found.
See also
fancy_string_array_includes
Note
See the documentation for fancy_string_array_includes for an example on how this method can be used.

◆ fancy_string_array_index_of()

ssize_t fancy_string_array_index_of ( fancy_string_array_t const *const  self,
fancy_string_t const *const  string 
)

Finds the index of the first element in the array object's internal list whose internal value is equal to string 's internal value.

Parameters
selfA pointer to the fancy_string_array_t instance to be searched for the presence of an element (the first one) whose internal value matches string 's internal value.
stringA pointer to the fancy_string_t instance whose internal value is to be looked for in self 's internal list.
Returns
ssize_t The position (i.e., the index) of the first matching element in self . The value -1 is returned if no matching element is found.
See also
fancy_string_array_index_of_value
Example:
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
fancy_string_t *s = fancy_string_create("joe john jimmy joey jeffry joey jeff julie joe jeff julia julian jimmy");
// First index ("joey")
// Last index ("joey")
// First index ("julian")
// Last index ("julian")
// No match
// Using a string object instead of a value...
{
// First index ("joe")
// Last index ("joe")
}
return 0;
}
ssize_t fancy_string_array_last_index_of(fancy_string_array_t const *const self, fancy_string_t const *const string)
Finds the index of the last element in the array object's internal list whose internal value is equal...
ssize_t fancy_string_array_last_index_of_value(fancy_string_array_t const *const self, char const *const value)
Finds the index of the last element in the array object's internal list whose internal value is equal...
ssize_t fancy_string_array_index_of(fancy_string_array_t const *const self, fancy_string_t const *const string)
Finds the index of the first element in the array object's internal list whose internal value is equa...
ssize_t fancy_string_array_index_of_value(fancy_string_array_t const *const self, char const *const value)
Finds the index of the first element in the array object's internal list whose internal value is equa...

◆ fancy_string_array_index_of_value()

ssize_t fancy_string_array_index_of_value ( fancy_string_array_t const *const  self,
char const *const  value 
)

Finds the index of the first element in the array object's internal list whose internal value is equal to value .

Parameters
selfA pointer to the fancy_string_array_t instance to be searched for the presence of an element (the first one) whose internal value matches value .
valueA pointer to a null-terminated string value for which to search in self 's internal list.
Returns
ssize_t The position (i.e., the index) of the first matching element in self . The value -1 is returned if no matching element is found.
See also
fancy_string_array_index_of
Note
See the documentation for fancy_string_array_index_of for an example on how this method can be used.

◆ fancy_string_array_insert()

void fancy_string_array_insert ( fancy_string_array_t *const  self,
fancy_string_t const *const  string,
size_t  index 
)

Inserts a memory-independent copy of the string object string at the specified position index inside the array object's internal list.

Parameters
selfA pointer to the fancy_string_array_t instance into which to insert the string object.
stringA pointer to the fancy_string_t instance to be cloned and inserted into the array object's internal list.
indexThe position at which to insert the string object into the array object's internal list.
Note
This method is very permissive. If the insertion position index is out of bounds, the array will be padded with empty string objects up to one less than index , and the string object will be added at index as requested. If an element is present at position index , that element, along with all of the elements to the right of it, will be moved right by one position. @ see fancy_string_array_insert_value

◆ fancy_string_array_insert_value()

void fancy_string_array_insert_value ( fancy_string_array_t *const  self,
char const *const  value,
size_t  index 
)

Instantiates a fancy_string_t object, with its internal state set as value , and inserts it at the specified position index inside the array object's internal list.

Parameters
selfA pointer to the fancy_string_array_t instance into which to insert the new string object.
valueA pointer to a null-terminated string, which corresponds to the internal state of the string object to be created and inserted into the array object's internal list.
indexThe position at which to insert the new string object into the array object's internal list.
Note
This method is very permissive. If the insertion position index is out of bounds, the array will be padded with empty string objects up to one less than index , and the string object will be added at index as requested. If an element is present at position index , that element, along with all of the elements to the right of it, will be moved right by one position. @ see fancy_string_array_insert

◆ fancy_string_array_is_empty()

bool fancy_string_array_is_empty ( fancy_string_array_t const *const  self)

Checks whether the array is empty.

Parameters
selfA pointer to the fancy_string_array_t instance to be checked for "emptiness".
Returns
bool A boolean value that is true if the array is empty (else it is set to false).

◆ fancy_string_array_join()

fancy_string_t * fancy_string_array_join ( fancy_string_array_t const *const  self,
fancy_string_t const *const  separator 
)

Creates (and returns a pointer to) a fancy_string_t instance and populates it with copies of the array object's elements' string data, from first to last, using the separator argument as separator.

Parameters
selfA pointer to the fancy_string_array_t instance to be "joined" into a string object.
separatorA pointer to a fancy_string_t instance whose internal string value is to be used as separator while joining.
Returns
fancy_string_t* A pointer to the memory-independent created string object.
See also
fancy_string_array_join_by_value

◆ fancy_string_array_join_by_value()

fancy_string_t * fancy_string_array_join_by_value ( fancy_string_array_t const *const  self,
char const *const  separator 
)

Creates (and returns a pointer to) a fancy_string_t instance and populates it with copies of the array object's elements' string data, from first to last, using the separator argument as separator.

Parameters
selfA pointer to the fancy_string_array_t instance to be "joined" into a string object.
separatorA pointer to a null-terminated string to be used as separator while joining.
Returns
fancy_string_t* A pointer to the memory-independent created string object.
See also
fancy_string_array_join

◆ fancy_string_array_last()

fancy_string_t * fancy_string_array_last ( fancy_string_array_t const *const  self)

Returns a memory-independent copy of the array object's internal list's last string object.

Parameters
selfA pointer to the fancy_string_array_t instance for which the last element of the internal list is to be copied and returned.
Returns
fancy_string_t* A pointer to a fancy_string_t instance that corresponds to the array object's internal list's last string object (a copy of it). If the array object is empty, the NULL pointer is returned.
See also
fancy_string_array_last_value

◆ fancy_string_array_last_index_of()

ssize_t fancy_string_array_last_index_of ( fancy_string_array_t const *const  self,
fancy_string_t const *const  string 
)

Finds the index of the last element in the array object's internal list whose internal value is equal to string 's internal value.

Parameters
selfA pointer to the fancy_string_array_t instance to be searched for the presence of an element (the last one) whose internal value matches string 's internal value.
stringA pointer to the fancy_string_t instance whose internal value is to be sought in self 's internal list.
Returns
ssize_t The position (i.e., the index) of the last matching element in self . The value -1 is returned if no matching element is found.
See also
fancy_string_array_last_index_of_value
Note
See the documentation for fancy_string_array_index_of for an example on how this method can be used.

◆ fancy_string_array_last_index_of_value()

ssize_t fancy_string_array_last_index_of_value ( fancy_string_array_t const *const  self,
char const *const  value 
)

Finds the index of the last element in the array object's internal list whose internal value is equal to value .

Parameters
selfA pointer to the fancy_string_array_t instance to be searched for the presence of an element (the last one) whose internal value matches value .
valueA pointer to a null-terminated string value for which to search in self 's internal list.
Returns
ssize_t The position (i.e., the index) of the last matching element in self . The value -1 is returned if no matching element is found.
See also
fancy_string_array_last_index_of
Note
See the documentation for fancy_string_array_index_of for an example on how this method can be used.

◆ fancy_string_array_last_value()

char * fancy_string_array_last_value ( fancy_string_array_t const *const  self)

Returns a memory-independent copy of the array object's internal list's last string object's internal string value (i.e., a pointer to a null-terminated string).

Parameters
selfA pointer to the fancy_string_array_t instance for which the last element of the internal list is to have its internal string value copied and returned as a pointer.
Returns
char* A pointer to null-terminated string data that was copied from the last element of the array object's internal list. If the array object is empty, the NULL pointer is returned.
See also
fancy_string_array_last

◆ fancy_string_array_mapped()

fancy_string_array_t * fancy_string_array_mapped ( fancy_string_array_t const *const  self,
fancy_string_mapped_t  fn,
void context 
)

Iterates over the array object's elements and calls the fn callback with each element (i.e, fancy_string_t instance), along with its position and a reference to its parent array object.

Parameters
selfA pointer to the fancy_string_array_t instance whose internal list's elements are to be iterated over with the specified callback.
fnA pointer to the function to be called for each element in the array. A call to this function will return a fancy_string_t instance that should be memory-independent of the one that was passed in.
contextAn application-defined context object.
Returns
fancy_string_array_t* A pointer to a new array object containing the mapped elements in its internal list.
See also
fancy_string_mapped_t
Warning
The function implementing fancy_string_mapped_t should never return a pointer to the fancy_string_t instance that was passed in as an argument. Compiling with the -Wall and -Werror flags, however, should prevent that from happening.
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
#define IGNORE_UNUSED(x) ((void)(x))
struct my_context
{
char *old_value;
char *new_value;
};
static fancy_string_t *callback(fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context)
{
IGNORE_UNUSED(index);
IGNORE_UNUSED(array);
struct my_context *c = (struct my_context *)context;
fancy_string_replace_value(clone, c->old_value, c->new_value, -1);
return clone;
}
int main(void)
{
struct my_context context = {.old_value = "a", .new_value = "A"};
fancy_string_array_t *a_mapped = fancy_string_array_mapped(a, callback, &context);
assert(fancy_string_equals_value(s, "AnnA nAthAn john jules liz"));
return 0;
}
void fancy_string_replace_value(fancy_string_t *const self, char const *const old_value, char const *const new_value, ssize_t replace_n)
Replaces the specified number of occurrences (i.e., replace_n ) of old_value with new_value in the st...
fancy_string_t * fancy_string_clone(fancy_string_t const *const self)
Creates a memory-independent copy of the fancy_string_t instance (i.e., self ).
fancy_string_array_t * fancy_string_array_mapped(fancy_string_array_t const *const self, fancy_string_mapped_t fn, void *context)
Iterates over the array object's elements and calls the fn callback with each element (i....

◆ fancy_string_array_none()

bool fancy_string_array_none ( fancy_string_array_t const *const  self,
fancy_string_find_t  fn,
void context 
)

Checks whether there are no elements in the array object's internal list for which fn returns true.

Parameters
selfA pointer to the fancy_string_array_t instance in which to check for the absence of matching elements.
fnA pointer to a function conforming to the fancy_string_find_t interface, which function gets called (internally) until a match (i.e., true value) is returned. Note that, in this context, a match means that this method will return false.
contextAn application-defined context object that gets passed to fn on each call.
Returns
bool A boolean value indicating whether or not (i.e., true or false) no string objects were found in self for which fn returned true.
See also
fancy_string_find_t, fancy_string_array_some, fancy_string_array_every
Note
See the documentation for fancy_string_array_find_index for an example on how to use methods accepting a pointer to a function conforming to fancy_string_find_t for the purpose of identifying elements inside an array object.

◆ fancy_string_array_pop()

fancy_string_t * fancy_string_array_pop ( fancy_string_array_t *const  self)

Removes the last element from the array object's internal list and returns a pointer to it.

Parameters
selfA pointer to the fancy_string_array_t instance whose internal list's last element is to be removed.
Returns
fancy_string_t* A pointer to the removed element, if any, else the NULL pointer.
See also
fancy_string_array_pop_and_destroy fancy_string_destroy
Warning
Once removed from its original array object, the string object becomes the application's responsibility, and therefore needs to be destroyed using the fancy_string_destroy method once it's no longer needed.

◆ fancy_string_array_pop_and_destroy()

void fancy_string_array_pop_and_destroy ( fancy_string_array_t *const  self)

Removes and destroys the array object's internal list's last element.

Parameters
selfA pointer to the fancy_string_array_t instance whose internal list's last element is to be removed and destroyed.
See also
fancy_string_array_pop

◆ fancy_string_array_print()

void fancy_string_array_print ( fancy_string_array_t const *const  self,
FILE stream,
bool  debug 
)

Prints (i.e., writes) the array's string contents to the specified stream .

Parameters
selfA pointer to the fancy_string_array_t instance to be printed.
streamThe stream to which to write (e.g., stdout ).
debugWhether to use the debug format (true) or not (false). With the debug format, additional information about the object and size is printed, while the standard format simply writes the internal string objects data as is.
See also
fancy_string_print

◆ fancy_string_array_push()

void fancy_string_array_push ( fancy_string_array_t *const  self,
fancy_string_t const *const  string 
)

Appends a memory-independent copy of the string object string at the end of the array object's internal list.

Parameters
selfA pointer to the fancy_string_array_t instance to which to append a copy of string .
stringA pointer to the fancy_string_t instance which is to be copied and that copy appended to the array object's internal list.
See also
fancy_string_array_push_value

◆ fancy_string_array_push_value()

void fancy_string_array_push_value ( fancy_string_array_t *const  self,
char const *const  value 
)

Instantiates a string object, with internal state set to value , and appends it at the end of the array object's internal list.

Parameters
selfA pointer to the fancy_string_array_t instance onto which to push the new string object.
valueThe value (i.e., a pointer to a null-terminated string) with which to populate the new fancy_string_t instance.
See also
fancy_string_array_push

◆ fancy_string_array_push_values()

void fancy_string_array_push_values ( fancy_string_array_t *const  self,
char const *const  first_value,
  ... 
)

Instantiates a variable number of string objects with internal states set to first_value and ... , and appends those in order at the end of the array object's internal list.

Parameters
selfA pointer to the fancy_string_array_t instance at the end of which to insert the new string objects.
first_valueThe value (i.e., a pointer to a null-terminated string) with which to populate the first new fancy_string_t instance.
...A variable number of null-terminated string pointers (i.e., char *) to be used, in the order they appear, in the same way as first_value . Important: The last value should be the NULL pointer, unless first_value itself is NULL, in which case all other arguments will be ignored and an the array object won't be modified.
See also
fancy_string_array_create_with_values, fancy_string_array_push_value, fancy_string_array_push
Warning
Internally, this method is based on the macros defined by stdarg.h , which means that a way of knowing where to stop, when reading the variable list of argument, is needed. The adopted approach here is therefore to add the NULL pointer as the last argument. If NULL is omitted, the result will be unpredictable.
Note
See the documentation for fancy_string_array_create_with_values for an example on how this method can be used to insert multiple string objects at the an of an array object.

◆ fancy_string_array_remove()

fancy_string_t * fancy_string_array_remove ( fancy_string_array_t *const  self,
size_t  index 
)

Removes and returns the pointer to the fancy_string_t instance located at position index inside the array object.

Parameters
selfA pointer to the fancy_string_array_t instance whose index -th element is to be removed and returned.
indexThe position (in the array object's internal list) of the sought element (i.e., the fancy_string_t instance to be removed).
Returns
fancy_string_t A pointer to the removed fancy_string_t instance, if any, else the NULL pointer.
See also
fancy_string_array_remove_and_destroy
Warning
Once removed from its original array object, the string object becomes the application's responsibility, and therefore needs to be destroyed using the fancy_string_destroy method once it's no longer needed.

◆ fancy_string_array_remove_and_destroy()

void fancy_string_array_remove_and_destroy ( fancy_string_array_t *const  self,
size_t  index 
)

Removes and destroys the fancy_string_t instance located at position index inside the array object.

Parameters
selfA pointer to the fancy_string_array_t instance whose index -th element is to be removed and destroyed.
indexThe position (in the array object's internal list) of the element sought for removal and destruction.
See also
fancy_string_array_remove, fancy_string_destroy
Note
If the position index is out of bounds, nothing will happen.

◆ fancy_string_array_reverse()

void fancy_string_array_reverse ( fancy_string_array_t *const  self)

Reverses the order of the elements in the array object's internal list.

Parameters
selfA pointer to the fancy_string_array_t instance whose internal list's elements order is to be reversed.
See also
fancy_string_array_reversed

◆ fancy_string_array_reversed()

fancy_string_array_t * fancy_string_array_reversed ( fancy_string_array_t const *const  self)

Clones the array object and reverses the clone's element before returning it.

Parameters
selfA pointer to the fancy_string_array_t instance which is to be cloned and whose clone is to have its internal list's elements order reversed.
Returns
fancy_string_array_t* A pointer to the created "reversed" array object.
See also
fancy_string_array_reverse

◆ fancy_string_array_shift()

fancy_string_t * fancy_string_array_shift ( fancy_string_array_t *const  self)

Removes the first element from the array object's internal list and returns a pointer to it.

Parameters
selfA pointer to the fancy_string_array_t instance whose internal list's first element is to be removed.
Returns
fancy_string_t* A pointer to the removed element, if any, else the NULL pointer.
See also
fancy_string_array_shift_and_destroy, fancy_string_destroy
Warning
Once removed from its original array object, the string object becomes the application's responsibility, and therefore needs to be destroyed using the fancy_string_destroy method once it's no longer needed.

◆ fancy_string_array_shift_and_destroy()

void fancy_string_array_shift_and_destroy ( fancy_string_array_t *const  self)

Removes and destroys the array object's internal list's first element.

Parameters
selfA pointer to the fancy_string_array_t instance whose internal list's first element is to be removed and destroyed.
See also
fancy_string_array_shift, fancy_string_destroy

◆ fancy_string_array_size()

size_t fancy_string_array_size ( fancy_string_array_t const *const  self)

Returns the array object's size; i.e., the number of fancy_string_t instances it contains.

Parameters
selfA pointer to the fancy_string_array_t instance for which the size is to be returned.
Returns
size_t The number of elements (i.e., fancy_string_t instances) in the array object.

◆ fancy_string_array_slice_and_destroy()

void fancy_string_array_slice_and_destroy ( fancy_string_array_t *const  self,
ssize_t  start,
ssize_t  end 
)

Slices the array object self based on the start and end positions, preserving the elements in that range, while destroying the elements falling outside of it.

Parameters
selfA pointer to the fancy_string_array_t instance to be sliced.
startThe position at which the slice starts. If set to -1, will be interpreted as 0.
endThe position before which the slice ends. If set to -1, will be interpreted as the array object's size (i.e., the total number of elements contained in the array object's internal list).
Note
This method is very permissive with regards to start and end . Setting start to -1 will be interpreted as 0, while setting end to -1 will be interpreted as n (where n is the number of elements in the array object's internal list). Setting start such that it is greater than end will simply result in those two values being swapped with one another. If start is out of bounds, the array object will simply get cleared up (i.e., emptied). If end is out of bounds, the slice will retain every element starting at position start .
See also
fancy_string_array_sliced

◆ fancy_string_array_sliced()

fancy_string_array_t * fancy_string_array_sliced ( fancy_string_array_t const *const  self,
ssize_t  start,
ssize_t  end 
)

Creates a memory-independent slice of the array object.

Parameters
selfA pointer to the fancy_string_array_t instance for which to generate a slice.
startThe position at which the slice starts. If set to -1, will be interpreted as 0.
endThe position before which the slice ends. If set to -1, will be interpreted as the array object's size (i.e., the total number of elements contained in the array object's internal list).
Returns
fancy_string_array_t* A pointer to the created slice.
Note
This method is very permissive with regards to start and end . Setting start to -1 will be interpreted as 0, while setting end to -1 will be interpreted as n (where n is the number of elements in the array object's internal list). Setting start such that it is greater than end will simply result in those two values being swapped with one another. If start is out of bounds, an empty array object will be returned. If self is empty, an empty slice will be returned, regardless of the values of start and end . If end is out of bounds, the slice will contain a copy of every element starting at position start .
See also
fancy_string_array_slice_and_destroy

◆ fancy_string_array_some()

bool fancy_string_array_some ( fancy_string_array_t const *const  self,
fancy_string_find_t  fn,
void context 
)

Checks whether there is at least one element in the array object's internal list for which fn returns true.

Parameters
selfA pointer to the fancy_string_array_t instance in which to check for the presence of at least one matching element.
fnA pointer to a function conforming to the fancy_string_find_t interface, which function gets called (internally) until a match (i.e., true value) is returned.
contextAn application-defined context object that gets passed to fn on each call.
Returns
bool A boolean value indicating whether or not (i.e., true or false) at least one string object was found in self for which fn returned true.
See also
fancy_string_find_t, fancy_string_array_none, fancy_string_array_every
Note
See the documentation for fancy_string_array_find_index for an example on how to use methods accepting a pointer to a function conforming to fancy_string_find_t for the purpose of identifying elements inside an array object.

◆ fancy_string_array_sort()

void fancy_string_array_sort ( fancy_string_array_t *const  self,
fancy_string_sort_t  fn,
void context 
)

Sorts the array object's internal list's elements based on the rules established by the fn callback.

Parameters
selfA pointer to the fancy_string_array_t instance to be sorted.
fnA pointer to the sorting function to be used.
contextAn application-defined context object that gets passed to fn on each call.
See also
fancy_string_sort_t, fancy_string_array_sorted
Example:
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "fancy_string.h"
#define IGNORE_UNUSED(x) ((void)(x))
static bool callback(fancy_string_t const *const string_1, fancy_string_t const *const string_2, void *context)
{
IGNORE_UNUSED(context);
// NOTE: This callback implementation is essentially the same as the one used
// by the `fancy_string_array_sort_values` and `fancy_string_array_sorted_values`
// methods.
size_t n_1 = fancy_string_size(string_1);
size_t n_2 = fancy_string_size(string_2);
char *value_1 = fancy_string_value(string_1);
char *value_2 = fancy_string_value(string_2);
size_t n = n_1 > n_2 ? n_2 : n_1;
for (size_t i = 0; i < n; i++)
{
if (value_1[i] == value_2[i])
{
continue;
}
bool out = value_1[i] < value_2[i];
free(value_1);
free(value_2);
return out;
}
free(value_1);
free(value_2);
if (n_1 == n_2)
{
return true;
}
else if (n_2 < n_1)
{
return false;
}
else
{
return true;
}
}
int main(void)
{
char *value = "John Alberto Eric Nicholas Isaac Henry Paul Ronald Keith Bob Rob Anna";
char *sorted = "Alberto Anna Bob Eric Henry Isaac John Keith Nicholas Paul Rob Ronald";
assert(fancy_string_equals_value(s_sorted, sorted));
return 0;
}
char * fancy_string_value(fancy_string_t const *const self)
Returns a pointer to a heap-allocated copy of the string object's internal state.
void fancy_string_array_sort(fancy_string_array_t *const self, fancy_string_sort_t fn, void *context)
Sorts the array object's internal list's elements based on the rules established by the fn callback.
size_t fancy_string_size(fancy_string_t const *const self)
Returns the size of the object's internal string (conceptually the same as strlen() ).
free free(void *ptr)

◆ fancy_string_array_sort_values()

void fancy_string_array_sort_values ( fancy_string_array_t *const  self)

Sorts the array object's internal list's elements based on their internal values, in the most basic way possible; i.e., from the smallest to greatest, as one would expect, using individual bytes as a basis for comparison.

Parameters
selfA pointer to the fancy_string_array_t instance to be sorted.
See also
fancy_string_array_sorted_values
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
char *value = "John Alberto Eric Nicholas Isaac Henry Paul Ronald Keith Bob Rob Anna";
char *sorted = "Alberto Anna Bob Eric Henry Isaac John Keith Nicholas Paul Rob Ronald";
assert(fancy_string_equals_value(s_sorted, sorted));
return 0;
}
void fancy_string_array_sort_values(fancy_string_array_t *const self)
Sorts the array object's internal list's elements based on their internal values, in the most basic w...

◆ fancy_string_array_sorted()

fancy_string_array_t * fancy_string_array_sorted ( fancy_string_array_t const *const  self,
fancy_string_sort_t  fn,
void context 
)

Creates a sorted copy of self .

Parameters
selfA pointer to the fancy_string_array_t instance to be cloned and then sorted.
fnA pointer to the sorting function to be used.
contextAn application-defined context object that gets passed to fn on each call.
Returns
fancy_string_array_t* A pointer to the memory-independent sorted copy of self .
See also
fancy_string_sort_t, fancy_string_array_sort
Note
See the documentation for fancy_string_array_sort for an example on how to define a sorting function (to be passed to fn ).

◆ fancy_string_array_sorted_values()

fancy_string_array_t * fancy_string_array_sorted_values ( fancy_string_array_t const *const  self)

Clones the array object and then sorts the clone's internal list's elements based on their internal values, in the most basic way possible; i.e., from the smallest to greatest, as one would expect, using individual bytes as a basis for comparison.

Parameters
selfA pointer to the fancy_string_array_t instance to be cloned and whose clone to be sorted.
Returns
fancy_string_array_t* A pointer to the created memory-independent sorted array object.
See also
fancy_string_array_sort_values
Note
See the documentation for fancy_string_array_sort_values for an example on how to use this method.

◆ fancy_string_array_splice()

fancy_string_array_t * fancy_string_array_splice ( fancy_string_array_t *const  self,
size_t  index,
ssize_t  delete_count,
fancy_string_array_t const *const  optional_new_strings 
)

Splices the array object's internal list and returns the removed elements (if any) in a new array object.

Parameters
selfThe array object to be spliced.
indexThe position at which to splice.
delete_countThe number of items to be removed (and returned) from the array object's internal element list. If set to 0, no elements will be removed. If set to -1, everything starting at position index , up to the end, will be removed (and returned).
optional_new_stringsA pointer to an optional fancy_string_array_t instance containing elements to be inserted (in their respective order) at position index . This argument should be set to the NULL pointer if no elements need to be inserted.
Returns
fancy_string_array_t* A pointer to a new array object containing the removed elements. If no elements were removed, an array object will still be returned, but it will be empty.
Note
If optional_new_strings is non-NULL and non-empty and the insertion position index is out of bounds, self will be padded with empty string objects up to one less than index , and the additional string objects will be added starting at position index as requested. If elements are present starting at position index , those elements, assuming that delete_count is set to 0, will be moved right by as many positions as there are elements in the optional_new_strings array object.
See also
fancy_string_array_splice_and_destroy, fancy_string_array_spliced
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
// Here we use the `splice` method, with the arguments enumerated below, to remove all the elements
// starting at position 3:
// self = a; index = 3; delete_count = -1; optional_new_strings = NULL
{
assert(fancy_string_equals_value(s, "one two three"));
}
{
assert(fancy_string_equals_value(s, "four five six seven eight nine"));
}
//  Now, we are going to insert back the removed elements (i.e., copies of those elements)
//  using the `splice` method with the following arguments:
// self = a; index = 3; delete_count = 0; optional_new_strings = removed
fancy_string_array_t *removed_2 = fancy_string_array_splice(a, 3, 0, removed);
{
assert(fancy_string_equals_value(s, "one two three four five six seven eight nine"));
}
fancy_string_array_push_value(new_elements, "twelve");
fancy_string_array_push_value(new_elements, "thirteen");
// Finally, we use the `splice` method to insert `new_elements` starting at
// position 11, which is out of bounds, so we expect to have two empty elements
// at position 9 and 10, followed by `twelve` and `thirteen` at positions 11
// and 12, respectively. Our arguments are:
// self = a; index = 11; delete_count = 0; optional_new_strings = new_elements
fancy_string_array_t *removed_3 = fancy_string_array_splice(a, 11, 0, new_elements);
{
assert(fancy_string_equals_value(s, "one_two_three_four_five_six_seven_eight_nine___twelve_thirteen"));
}
return 0;
}
fancy_string_array_t * fancy_string_array_splice(fancy_string_array_t *const self, size_t index, ssize_t delete_count, fancy_string_array_t const *const optional_new_strings)
Splices the array object's internal list and returns the removed elements (if any) in a new array obj...
bool fancy_string_array_is_empty(fancy_string_array_t const *const self)
Checks whether the array is empty.

◆ fancy_string_array_splice_and_destroy()

void fancy_string_array_splice_and_destroy ( fancy_string_array_t *const  self,
size_t  index,
ssize_t  delete_count,
fancy_string_array_t const *const  optional_new_strings 
)

Splices the array object's internal list and destroys the removed elements (if any).

Parameters
selfThe array object to be spliced.
indexThe position at which to splice.
delete_countThe number of items to be removed (and destroyed) from the array object's internal element list. If set to 0, no elements will be removed. If set to -1, everything starting at position index , up to the end, will be removed (and destroyed).
optional_new_stringsA pointer to an optional fancy_string_array_t instance containing elements to be inserted (in their respective order) at position index . This argument should be set to the NULL pointer if no elements need to be inserted.
Note
If optional_new_strings is non-NULL and non-empty and the insertion position index is out of bounds, self will be padded with empty string objects up to one less than index , and the additional string objects will be added starting at position index as requested. If elements are present starting at position index , those elements, assuming that delete_count is set to 0, will be moved right by as many positions as there are elements in the optional_new_strings array object. See the documentation for fancy_string_array_splice for an example on splicing.
See also
fancy_string_array_splice, fancy_string_array_spliced

◆ fancy_string_array_spliced()

fancy_string_array_t * fancy_string_array_spliced ( fancy_string_array_t const *const  self,
size_t  index,
ssize_t  delete_count,
fancy_string_array_t const *const  optional_new_strings 
)

Clones self and calls fancy_string_array_splice_and_destroy on that clone.

Parameters
selfThe array object to be cloned and whose clone is to be spliced.
indexThe position at which to splice.
delete_countThe number of items to be removed (and destroyed) from the clone. If set to 0, no elements will be removed. If set to -1, everything starting at position index , up to the end, will be removed (and destroyed).
optional_new_stringsA pointer to an optional fancy_string_array_t instance containing elements to be inserted (in their respective order) at position index . This argument should be set to the NULL pointer if no elements need to be inserted.
Returns
fancy_string_array_t* A pointer to the cloned and spliced array object.
Note
If optional_new_strings is non-NULL and non-empty and the insertion position index is out of bounds, the clone of self will be padded with empty string objects up to one less than index , and the additional string objects will be added starting at position index as requested. If elements are present starting at position index , those elements, assuming that delete_count is set to 0, will be moved right by as many positions as there are elements in the optional_new_strings array object. See the documentation for fancy_string_array_splice for an example on splicing.
See also
fancy_string_array_splice_and_destroy, fancy_string_array_splice

◆ fancy_string_clear()

void fancy_string_clear ( fancy_string_t *const  self)

Clears the internal string data (i.e., makes self an empty string object).

Parameters
selfA pointer to the fancy_string_t instance to be cleared (i.e., emptied).

◆ fancy_string_clone()

fancy_string_t * fancy_string_clone ( fancy_string_t const *const  self)

Creates a memory-independent copy of the fancy_string_t instance (i.e., self ).

Parameters
selfA pointer to the fancy_string_t instance to be cloned.
Returns
fancy_string_t* A memory-independent copy of self .

◆ fancy_string_contains()

bool fancy_string_contains ( fancy_string_t const *const  self,
fancy_string_t const *const  string 
)

Checks whether the string object's data contains at least one occurrence of string 's internal value.

Parameters
selfA pointer to the fancy_string_t instance to be checked.
stringA pointer to another fancy_string_t instance whose internal value is searched inside self 's value.
Returns
bool A boolean value indicating whether a match was found (true) or not (false).
See also
fancy_string_contains_value

◆ fancy_string_contains_value()

bool fancy_string_contains_value ( fancy_string_t const *const  self,
char const *const  value 
)

Checks whether the string object's data contains at least one occurrence of value .

Parameters
selfA pointer to the fancy_string_t instance to be checked.
valueThe value (i.e., a pointer to a null-terminated string) for which to check inside self .
Returns
bool A boolean value indicating whether value was found (true) or not (false).
See also
fancy_string_contains

◆ fancy_string_create()

fancy_string_t * fancy_string_create ( char const *const  value)

Instantiates a string object with its internal state specified by the value parameter.

Parameters
valueThe initial state of the string object (i.e., a pointer to a null-terminated string).
Returns
fancy_string_t* A pointer to the created string object.
See also
fancy_string_create_empty, fancy_string_create_repeat, fancy_string_from_stream, fancy_string_from_stream_next_line

◆ fancy_string_create_empty()

fancy_string_t * fancy_string_create_empty ( void  )

Similarly to fancy_string_create(), instantiates a string object, but with its internal value set to be empty.

Returns
fancy_string_t* A pointer to the created string object.
See also
fancy_string_create, fancy_string_create_repeat, fancy_string_from_stream

◆ fancy_string_create_repeat()

fancy_string_t * fancy_string_create_repeat ( char const *const  value,
size_t  n_repeat 
)

Similarly to fancy_string_create(), instantiates a string object, but repeats the initial value the specified number of times (i.e., n_repeat times).

Parameters
valueThe initial state of the string object (i.e., a pointer to a null-terminated string).
n_repeatThe number of times to repeat the string object.
Returns
fancy_string_t* A pointer to the created string object.
See also
fancy_string_create, fancy_string_create_empty, fancy_string_from_stream

◆ fancy_string_destroy()

void fancy_string_destroy ( fancy_string_t *const  self)

Destroys the string object; i.e., frees the memory that was allocated for the internal string data, as well as the memory allocated for the container itself.

Parameters
selfA pointer to the fancy_string_t instance to be destroyed.
Warning
This method should only be called once per object, else a double-free error might incur.

◆ fancy_string_ends_with()

bool fancy_string_ends_with ( fancy_string_t const *const  self,
fancy_string_t const *const  string 
)

Checks whether the string object's internal value ends with string 's internal value.

Parameters
selfA pointer to the fancy_string_t instance to be checked.
stringA Pointer to another fancy_string_t instance against whose internal value to check for "trailing equality".
Returns
bool A boolean value indicating whether the object's data ends with string 's internal value (true) or not (false).
See also
fancy_string_ends_with_value

◆ fancy_string_ends_with_value()

bool fancy_string_ends_with_value ( fancy_string_t const *const  self,
char const *const  value 
)

Checks whether the string object's internal value ends with value .

Parameters
selfA pointer to the fancy_string_t instance to be checked.
valueA value (i.e., a pointer to a null-terminated string) against which to check for "trailing equality".
Returns
bool A boolean value indicating whether the object's data ends with value (true) or not (false).
See also
fancy_string_ends_with

◆ fancy_string_equals()

bool fancy_string_equals ( fancy_string_t const *const  self,
fancy_string_t const *const  string 
)

Checks whether the string object's internal value equals to string 's internal value.

Parameters
selfA pointer to the fancy_string_t instance for which to check for equality.
stringA pointer to another fancy_string_t instance against which to check for equality.
Returns
bool A boolean value indicating whether equality was found (true) or not (false).
See also
fancy_string_equals_value

◆ fancy_string_equals_value()

bool fancy_string_equals_value ( fancy_string_t const *const  self,
char const *const  value 
)

Checks whether the string object's internal value equals to value .

Parameters
selfA pointer to the fancy_string_t instance for which to check for equality.
valueThe value (i.e., a pointer to a null-terminated string) against which to check for equality.
Returns
bool A value indicating whether equality was found (true) or not (false).
See also
fancy_string_equals

◆ fancy_string_from_copied_memory()

fancy_string_t * fancy_string_from_copied_memory ( void const *const  pointer,
size_t  n 
)

Instantiates a string object with initial internal state obtained by copying n bytes from pointer .

Parameters
pointerA pointer to the memory to be copied (i.e., n bytes of it) and used as internal state for the new string object.
nThe number of bytes to be copied from the memory pointed to by pointer .
Returns
fancy_string_t* A pointer to the created string object.
See also
fancy_string_create, fancy_string_create_empty
Note
Internally, this method temporarily allocates sizeof(char*) * (n + 1) bytes and uses them to make a copy of pointer 's first n bytes using memcpy , and then adds the null character \0 to it, and passes that temporary null-terminated string to fancy_string_create to create the string object. Obviously, this method should only be used when a null-terminated string is not already available to be passed to fancy_string_create directly, or when only a specific segment of a string is needed.
Example:
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
char *message = "I only want this part; not this one.";
{
assert(fancy_string_equals_value(s, "I only want this part"));
}
{
}
{
char tmp[5] = {'h', 'e', 'l', 'l', 'o'};
{
}
}
{
char tmp[6] = {'h', 'e', 'l', 'l', 'o', '\0'};
{
// NOTE: Beyond tmp[5], The size `n` does not matter, because we have a null character.
}
}
return 0;
}
fancy_string_t * fancy_string_from_copied_memory(void const *const pointer, size_t n)
Instantiates a string object with initial internal state obtained by copying n bytes from pointer .

◆ fancy_string_from_stream()

fancy_string_t * fancy_string_from_stream ( FILE stream)

Instantiates a string object and fills its internal state with the string data read from stream .

Parameters
streamA pointer to readable stream (e.g., a file pointer that has been opened for reading).
Returns
fancy_string_t* A pointer to the created string object.
Note
Internally, this method calls fgetc() repeatedly until EOF is reached, after which it calls fclose() to close the stream. This method assumes that value has been opened for reading.
See also
fancy_string_from_stream_next_line, fancy_string_create
Warning
- Trying to read from stream if the latter has not been opened with read permission will crash the application.
- Internally, this method makes calls to getc_unlocked() until EOF is returned, but the method does not bother setting nor checking (and resetting) errno before and after calling getc_unlocked().

◆ fancy_string_from_stream_next_line()

fancy_string_t * fancy_string_from_stream_next_line ( FILE stream)

Reads the next line from the stream and instantiates a string object with internal state set as the "line" that was read.

Parameters
streamA pointer to a readable stream from which to get the next line (e.g., a file pointer that has been opened for reading).
Returns
fancy_string_t* A pointer to the created string object which contains a copy of the value read on stream , or the NULL pointer if the passed stream argument was NULL or if getline(), which is used internally to read the next line, returned -1.
See also
fancy_string_from_stream, fancy_string_create
Note
Unlike fancy_string_from_stream(), this method will not close the stream before returning.
Warning
Trying to read from stream if the latter has not been opened with read permission will crash the application.
Example:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fancy_string.h"
int main(void)
{
// This first example illustrates how to use `fancy_string_from_stream_next_line`
// to read a fake stream (generated using "fmemopen") line by line.
{
char *data = "This is a title\n\nThis is the first line.\nThis is another line.\n\nBye bye line.";
FILE *stream = fmemopen(data, strlen(data), "r");
while (true)
{
if (line == NULL)
{
break;
}
fancy_string_print(line, stdout, true);
}
fclose(stream);
}
// This second example illustrates how to use `fancy_string_from_stream_next_line`
// to read a file stream line by line.
{
FILE *file_pointer = fopen("./test/assets/multi-line-file.txt", "r");
while (true)
{
if (line == NULL)
{
break;
}
fancy_string_print(line, stdout, true);
}
fclose(file_pointer);
}
// This third example illustrates how to use `fancy_string_from_stream_next_line`
// to read from `stdin`. Each new line will be echoed back, and the loop will
// break if the "exit" command is entered.
// NOTE: The example is disabled by default: to use it, change `false` to `true`.
if (false)
{
printf("\n\nPlease write something and press enter. You can write 'exit' to terminate.\n");
while (true)
{
if (fancy_string_equals_value(line, "exit"))
{
break;
}
fancy_string_print(line, stdout, true);
}
}
return 0;
}
fancy_string_t * fancy_string_from_stream_next_line(FILE *stream)
Reads the next line from the stream and instantiates a string object with internal state set as the "...
fclose fclose(FILE *stream)
fmemopen fmemopen(void buf[.size], size_t size, const char *mode)
fopen fopen(const char *restrict pathname, const char *restrict mode)
printf printf(const char *restrict format,...)
strlen strlen(const char *s)

◆ fancy_string_index_of()

ssize_t fancy_string_index_of ( fancy_string_t const *const  self,
fancy_string_t const *const  string 
)

Finds and returns the index of the first occurrence of string 's internal value in self 's internal value, if any.

Parameters
selfA pointer to the fancy_string_t instance for which to find the first matching index for string 's internal value.
stringA pointer to another fancy_string_t instance for whose internal value is being sought inside self 's internal data.
Returns
ssize_t The index of the first match, if any. If none, -1 will be returned.
See also
fancy_string_index_of_value

◆ fancy_string_index_of_value()

ssize_t fancy_string_index_of_value ( fancy_string_t const *const  self,
char const *const  value 
)

Finds and returns the index of the first occurrence of value in the string object's internal value, if any.

Parameters
selfA pointer to the fancy_string_t instance for which to find the first matching index for value .
valueThe value (i.e., a pointer to a null-terminated string) whose first occurrence is being sought inside the string object's data.
Returns
ssize_t The index of the first match, if any. If none, -1 will be returned.
See also
fancy_string_index_of

◆ fancy_string_is_empty()

bool fancy_string_is_empty ( fancy_string_t const *const  self)

Checks whether the string is empty.

Parameters
selfA pointer to the fancy_string_t instance to be checked for emptiness.
Returns
bool A value that is true if the string is empty (else it is false).

◆ fancy_string_library_version()

void fancy_string_library_version ( uint16_t major,
uint16_t minor,
uint16_t revision 
)

Populates its arguments with the library's version.

Parameters
majorA pointer used to store the library's major version number.
minorA pointer used to store the library's minor version number.
revisionA pointer used to store the library's revision number.
See also
fancy_string_library_version_print

◆ fancy_string_library_version_print()

void fancy_string_library_version_print ( FILE stream)

Prints (i.e., writes) the library's version to the specified stream.

Parameters
streamThe stream to which to write the library version (e.g. stdout ).
See also
fancy_string_library_version

◆ fancy_string_line_break()

void fancy_string_line_break ( fancy_string_t *const  self,
bool  with_carriage_return 
)

Appends a line break character (i.e., \\n) at the end of the object's internal string data.

Parameters
selfA pointer to the fancy_string_t instance at the end of which to add a line break character.
with_carriage_returnA boolean value indicating whether, in addition to the line break character \\n, a carriage return character (i.e., \\r) should also be added. If true, the two characters will be appended in the following order: \\r\\n. If false, only \\n will be appended.

◆ fancy_string_lowercase()

void fancy_string_lowercase ( fancy_string_t *const  self)

Applies a lowercase transformation to the string object's internal data.

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be lowercased.
Note
Internally, this method uses the tolower() function defined in the C Standard Library ctype.h header file. This means, among other things, that lowercasing of accented characters may not behave as expected. For instance, depending on the implementation, a character such as À will likely not be transformed to à.
See also
fancy_string_lowercased

◆ fancy_string_lowercased()

fancy_string_t * fancy_string_lowercased ( fancy_string_t const *const  self)

Creates a new string object whose internal data corresponds to a copy of self with a lowercase transformation performed on it.

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be copied and then lowercased.
Returns
fancy_string_t* A pointer to a newly created, memory-independent string object that contains a lowercased version of self 's internal data.
Note
Internally, this method uses the tolower() function defined in the C Standard Library ctype.h header file. This means, among other things, that lowercasing of accented characters may not behave as expected. For instance, depending on the implementation, a character such as À will likely not be transformed to à.
See also
fancy_string_lowercase

◆ fancy_string_memory_usage_debug()

void fancy_string_memory_usage_debug ( FILE stream)

A "static method" that can be used to "print" a summary of the library's memory usage.

Note
- If fancy_string_memory_usage_mode_t was set to FANCY_STRING_MEMORY_USAGE_MODE_NONE , no summary will be printed (only a warning message).
- If fancy_string_memory_usage_mode_t was set to FANCY_STRING_MEMORY_USAGE_MODE_THREAD_LOCAL , a summary of the memory used for the "calling thread" will be printed.
- If fancy_string_memory_usage_mode_t was set to FANCY_STRING_MEMORY_USAGE_MODE_GLOBAL_SYNC , a summary of the memory used for the whole process (regardless of the "calling thread") will be printed.
Parameters
streamA pointer to a valid readable stream to which the summary will be printed (i.e., written).

◆ fancy_string_memory_usage_get()

size_t fancy_string_memory_usage_get ( void  )

A "static method" that retrieves and returns the amount of memory allocated by the library.

Note
- If fancy_string_memory_usage_mode_t was set to FANCY_STRING_MEMORY_USAGE_MODE_NONE , the returned value will always be 0.
- If fancy_string_memory_usage_mode_t was set to FANCY_STRING_MEMORY_USAGE_MODE_THREAD_LOCAL , the returned value will be the total memory used for the "calling thread".
- If fancy_string_memory_usage_mode_t was set to FANCY_STRING_MEMORY_USAGE_MODE_GLOBAL_SYNC , the returned value will be the total memory used for the whole process, regardless of who is the "calling thread".
Returns
size_t The total amount of memory (in bytes) currently in use by the library (not including the memory used by the memory tracking mechanism, however; only for the string, array, and regular expression objects).

◆ fancy_string_memory_usage_init()

void fancy_string_memory_usage_init ( fancy_string_memory_usage_mode_t  mode)

If called, specifies the memory usage tracking mode to be used by the library.

Note
- This method does not need to be called if tracking is not required. By default, the library uses FANCY_STRING_MEMORY_USAGE_MODE_NONE , so calling the method with the latter value is equivalent to doing nothing.
- If tracking is required, this method should be called (only once) as soon as possible, before any library objects are created. The two tracking options are FANCY_STRING_MEMORY_USAGE_MODE_THREAD_LOCAL and FANCY_STRING_MEMORY_USAGE_MODE_GLOBAL_SYNC . See fancy_string_memory_usage_mode_t for more information on what these modes do.
Parameters
modeA variable of type fancy_string_memory_usage_mode_t , which specifies the tracking mode to be used.
See also
fancy_string_memory_usage_mode_t
Warning
This method should be called at most once per process, else the application will likely crash. In fact, calling the method any number of times with FANCY_STRING_MEMORY_USAGE_MODE_NONE will do nothing, but once either FANCY_STRING_MEMORY_USAGE_MODE_THREAD_LOCAL or FANCY_STRING_MEMORY_USAGE_MODE_GLOBAL_SYNC have been set, the method will crash if called again.
Example:
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include <errno.h>
#include <stdbool.h>
#include <unistd.h>
#include "fancy_string.h"
static void *thread_callback(void *context);
typedef enum my_thread_type_e
{
MY_THREAD_TYPE_WATCHER,
MY_THREAD_TYPE_WRITER,
} my_thread_type_t;
typedef struct my_context_s
{
my_thread_type_t thread_type;
} my_context_t;
int main(void)
{
// NOTE: Use `FANCY_STRING_MEMORY_USAGE_MODE_THREAD_LOCAL` instead of
// `FANCY_STRING_MEMORY_USAGE_MODE_GLOBAL_SYNC` to see what happens with
// "thread local" memory tracking mode.
pthread_t thread_1;
my_context_t thread_1_context = {.thread_type = MY_THREAD_TYPE_WRITER};
if (pthread_create(&thread_1, NULL, &thread_callback, &thread_1_context) != 0)
{
perror("Failed to create thread #1 (i.e., writer thread)");
exit(EXIT_FAILURE);
}
pthread_t thread_2;
my_context_t thread_2_context = {.thread_type = MY_THREAD_TYPE_WATCHER};
if (pthread_create(&thread_2, NULL, &thread_callback, &thread_2_context) != 0)
{
perror("Failed to create thread #2 (i.e., watcher thread)");
exit(EXIT_FAILURE);
}
if (pthread_join(thread_1, NULL) != 0)
{
perror("Failed to join thread #1 (i.e., writer thread)");
exit(EXIT_FAILURE);
}
if (pthread_join(thread_2, NULL) != 0)
{
perror("Failed to join thread #2 (i.e., watcher thread)");
exit(EXIT_FAILURE);
}
}
static void *thread_callback(void *context)
{
my_context_t *c = (my_context_t *)context;
size_t iteration_counter = 0;
if (c->thread_type == MY_THREAD_TYPE_WATCHER)
{
bool started = false;
size_t usage = 0;
while (!started || usage > 0)
{
iteration_counter += 1;
if (iteration_counter >= 20)
{
break;
}
if (!started && usage != 0)
{
started = true;
}
fprintf(stdout, "[watcher:%zu]\ttotal memory usage: %zu bytes\n", iteration_counter, usage);
sleep(1);
}
fprintf(stdout, "[watcher:%zu]\texiting thread\n", iteration_counter);
}
else if (c->thread_type == MY_THREAD_TYPE_WRITER)
{
while (true)
{
iteration_counter += 1;
fprintf(stdout, "[writer:%zu]\ttotal memory usage: %zu bytes\n", iteration_counter, usage);
if (usage > 300)
{
break;
}
sleep(2);
}
fprintf(stdout, "[writer:%zu]\texiting thread\n", iteration_counter);
}
else
{
fprintf(stderr, "This is not possible!\n");
exit(EXIT_FAILURE);
}
return NULL;
}
@ FANCY_STRING_MEMORY_USAGE_MODE_GLOBAL_SYNC
Tracks memory usage and stores the tracking data in a private static variable shared by all threads....
Definition: fancy_string.h:146
size_t fancy_string_memory_usage_get(void)
A "static method" that retrieves and returns the amount of memory allocated by the library.
void fancy_string_memory_usage_init(fancy_string_memory_usage_mode_t mode)
If called, specifies the memory usage tracking mode to be used by the library.
void fancy_string_append_value(fancy_string_t *const self, char const *const value)
Appends a (string) value to the current string object's internal state.
void fancy_string_append(fancy_string_t *const self, fancy_string_t const *const string)
Appends a string object's data (in this case string ) to the current string object's internal state (...

◆ fancy_string_memory_usage_mode()

fancy_string_memory_usage_mode_t fancy_string_memory_usage_mode ( void  )

Retrieves and returns the current memory usage mode used by the library, for the current process.

Returns
fancy_string_memory_usage_mode_t A value that corresponds to the memory tracking mode used by the library for the current process.

◆ fancy_string_pad_end()

void fancy_string_pad_end ( fancy_string_t *const  self,
size_t  target_size,
char  value 
)

Pads the right-hand side of the string with the specified character (i.e., value ).

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be right-padded.
target_sizeThe target size of the string after the padding.
valueThe character to be used for the padding.
See also
fancy_string_padded_end

◆ fancy_string_pad_start()

void fancy_string_pad_start ( fancy_string_t *const  self,
size_t  target_size,
char  value 
)

Pads the left-hand side of the string with the specified character (i.e., value ).

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be left-padded.
target_sizeThe target size of the string after the padding.
valueThe character to be used for the padding.
See also
fancy_string_padded_start
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
return 0;
}
void fancy_string_pad_start(fancy_string_t *const self, size_t target_size, char value)
Pads the left-hand side of the string with the specified character (i.e., value ).

◆ fancy_string_padded_end()

fancy_string_t * fancy_string_padded_end ( fancy_string_t const *const  self,
size_t  target_size,
char  value 
)

Creates a string object whose right-hand side has been padded with the specified character (i.e., value).

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be copied and then right-padded.
target_sizeThe target size of the padded string object.
valueThe character to be used for the padding.
Returns
fancy_string_t* A pointer to a newly created, memory-independent, right-padded string object.
See also
fancy_string_pad_end

◆ fancy_string_padded_start()

fancy_string_t * fancy_string_padded_start ( fancy_string_t const *const  self,
size_t  target_size,
char  value 
)

Creates a string object whose left-hand side has been padded with the specified character (i.e., value ).

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be copied and then left-padded.
target_sizeThe target size of the padded string object.
valueThe character to be used for the padding.
Returns
fancy_string_t* A pointer to a newly created, memory-independent, left-padded string object.
See also
fancy_string_pad_start

◆ fancy_string_prepend()

void fancy_string_prepend ( fancy_string_t *const  self,
fancy_string_t const *const  string 
)

Prepends a string object's data (in this case string ) to the current string object's internal state (i.e., to self ).

Parameters
selfA pointer to the fancy_string_t instance to which to prepend.
stringA pointer to another fancy_string_t instance whose internal data is to be copied and prepended to self .
See also
fancy_string_prepend_value

◆ fancy_string_prepend_value()

void fancy_string_prepend_value ( fancy_string_t *const  self,
char const *const  value 
)

Prepends a (string) value to the current string object's internal state.

Parameters
selfA pointer to the fancy_string_t instance to which to prepend a copy of value .
valueThe value (i.e., a pointer to a null-terminated string) to be prepended to the internal string data.
See also
fancy_string_prepend

◆ fancy_string_print()

void fancy_string_print ( fancy_string_t const *const  self,
FILE stream,
bool  debug 
)

Prints (i.e., writes) the string object's data to the specified stream .

Parameters
selfA pointer to the fancy_string_t instance to be printed.
streamThe stream to which to write (e.g., stdout ).
debugWhether to use the debug format (true) or not (false). With the debug format, in addition to printing the data itself, information the container and the data size is also printed, while the standard format simply writes the string data as is.
See also
fancy_string_array_print

◆ fancy_string_regex_create()

fancy_string_regex_t * fancy_string_regex_create ( fancy_string_t const *const  string,
fancy_string_t const *const  pattern,
ssize_t  n_max_matches 
)

Instantiates a regular expression object and returns a pointer to it. That object can then be interrogated using the various fancy_string_regex-prefixed methods exposed by this library.

Parameters
stringA pointer to a fancy_string_t instance containing the string data to be searched.
patternA pointer to a fancy_string_t instance containing the string data corresponding to the regular expression pattern for which to match.
n_max_matchesA value that can be used to specify a maximum number of matches allowed during the search. If set -1, the search will go on, from left to right, until no more matches are found.
Returns
fancy_string_regex_t* A pointer to the created regular expression object. Note that if either of string or pattern is empty, this method will return the NULL pointer. The NULL pointer will also be returned if an error occurs while (internally) calling regcomp() or regexec().
Remarks
As mention in the description for the "returned type", the NULL pointer will be returned if any error is encountered while internally calling regcomp() or regexec(). This method currently does not provide information about such errors.
Note
- The string 's data is searched for pattern from left to right, until either n_max_matches is reached or no more matches are found.
- Internally, this method relies on the regcomp() and regexec() POSIX functions. regcomp() is called using the REG_EXTENDED flag, which means that the POSIX-Extended Regular Expressions syntax is used. Read more: POSIX Regular Expression
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
fancy_string_t *s = fancy_string_create("lib<fancy_string> is a C library for easy and fun string manipulation.");
fancy_string_t *pattern = fancy_string_create("fancy[_a-z]*|string|lib[a-z]*");
assert(re != NULL);
assert(fancy_string_array_size(matched_words) == 4);
assert(fancy_string_array_includes_value(matched_words, "library"));
assert(fancy_string_array_includes_value(matched_words, "fancy_string"));
return 0;
}
fancy_string_regex_t * fancy_string_regex_create(fancy_string_t const *const string, fancy_string_t const *const pattern, ssize_t n_max_matches)
Instantiates a regular expression object and returns a pointer to it. That object can then be interro...
void fancy_string_regex_debug(fancy_string_regex_t const *const self, FILE *stream, bool verbose)
Prints a summary of the self regular expression object to the specified stream (i....
struct fancy_string_regex_s fancy_string_regex_t
An opaque type that serves as a container for regular expression matching results,...
Definition: fancy_string.h:82
void fancy_string_regex_destroy(fancy_string_regex_t *const self)
Destroys the regular expression object.
fancy_string_array_t * fancy_string_regex_matches_to_strings(fancy_string_regex_t const *const self)
Creates and returns an array object whose internal components correspond to the regular expression ob...
size_t fancy_string_regex_match_count(fancy_string_regex_t const *const self)
Returns the number of matches obtained for the regular expression object pointed to by self .

◆ fancy_string_regex_debug()

void fancy_string_regex_debug ( fancy_string_regex_t const *const  self,
FILE stream,
bool  verbose 
)

Prints a summary of the self regular expression object to the specified stream (i.e., stream ).

Parameters
selfA pointer to the fancy_string_regex_t instance to be printed.
streamA pointer to a valid "writable" stream (e.g., stdout ).
verboseA boolean value indicating whether (true) or not (false) to print extra information. That extra information, if present, will be prefixed with the word "verbose" in the "printout".

◆ fancy_string_regex_destroy()

void fancy_string_regex_destroy ( fancy_string_regex_t *const  self)

Destroys the regular expression object.

Parameters
selfA pointer to the fancy_string_regex_t instance to be destroyed.

◆ fancy_string_regex_has_match()

bool fancy_string_regex_has_match ( fancy_string_regex_t const *const  self)

Checks whether there was at least one match in the regular expression object pointed to by self .

Parameters
selfA pointer to the fancy_string_regex_t instance for which to check whether at least one match was found.
Returns
bool A boolean value indicating whether (true) or not (false) at least one match was found for the current regular expression object.

◆ fancy_string_regex_match_count()

size_t fancy_string_regex_match_count ( fancy_string_regex_t const *const  self)

Returns the number of matches obtained for the regular expression object pointed to by self .

Parameters
selfA pointer to the fancy_string_regex_t instance for which to retrieve the number of matches found.
Returns
size_t The number of matches that were found for the regular expression object self .

◆ fancy_string_regex_match_info_for_index()

fancy_string_regex_match_info_t fancy_string_regex_match_info_for_index ( fancy_string_regex_t const *const  self,
size_t  index 
)

Retrieves and returns the match information in a fancy_string_regex_t instance for the specified position (i.e., index ).

Parameters
selfA pointer to the fancy_string_regex_t instance for which the match info (i.e., fancy_string_regex_match_info_t) is requested.
indexThe position (i.e., the index) of the match to be returned
Returns
fancy_string_regex_match_info_t A structure containing the requested match information. If .index = -1, that means that the specified position (i.e, index ) was out of bounds, such that both .start and .end will be set to zero. If the index argument was valid, it will be returned in .index, and the .start and .end values will correspond to the location of the index -th match in the target string object (for which string object a copy can be requested using the fancy_string_regex_string method on self ).
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
fancy_string_t *s = fancy_string_create("jules julie julius jean jeffrey joey john joe");
// We match character sequences that start with "j" and end with "e " or "e" at the end of a line,
// with anything in the middle corresponding to ASCII lowercase letters (i.e. a to z). In this case, that
// means that "julie " and "joe" will be matched.
fancy_string_t *p = fancy_string_create("j[a-z]*e($|[ ]{1})");
{
assert(info.index == 0);
}
{
assert(info.index == 1);
}
{
assert(info.index == -1);
}
return 0;
}
fancy_string_t * fancy_string_substring(fancy_string_t const *const self, ssize_t start, ssize_t end)
Creates a substring of a string object.
fancy_string_regex_match_info_t fancy_string_regex_match_info_for_index(fancy_string_regex_t const *const self, size_t index)
Retrieves and returns the match information in a fancy_string_regex_t instance for the specified posi...
size_t start
The 'start' position of the match at position index .
Definition: fancy_string.h:101
void fancy_string_trim(fancy_string_t *const self)
Trims (i.e., remove all the white spaces from) both the right and left-hand sides of the string objec...
size_t end
The 'end' position of the match at position index .
Definition: fancy_string.h:108
ssize_t index
The index (i.e., the position) of the match inside the fancy_string_regex_t instance.
Definition: fancy_string.h:97
A type (i.e., a structure), returned by the fancy_string_regex_match_info_for_index() method,...
Definition: fancy_string.h:90

◆ fancy_string_regex_matches_to_strings()

fancy_string_array_t * fancy_string_regex_matches_to_strings ( fancy_string_regex_t const *const  self)

Creates and returns an array object whose internal components correspond to the regular expression object's matches.

Parameters
selfA pointer to the fancy_string_regex_t instance whose matches are to be extracted and returned as an array object.
Returns
fancy_string_array_t* A pointer to an array object containing the string representations of the regular expression object's matches.

◆ fancy_string_regex_max_number_of_matches()

ssize_t fancy_string_regex_max_number_of_matches ( fancy_string_regex_t const *const  self)

Retrieves and returns the n_max_matches value (i.e., the maximum number of matches allowed for the regular expression instance) that was used when instantiating the fancy_string_regex_t object (i.e., the object pointed to by self ).

Parameters
selfA pointer to the fancy_string_regex_t instance for which to check the specified n_max_matches.
Returns
ssize_t The maximum number of matches that were allowed for the regular expression object. A value of -1 means that there was no limit.

◆ fancy_string_regex_max_number_of_matches_reached()

bool fancy_string_regex_max_number_of_matches_reached ( fancy_string_regex_t const *const  self)

Checks, for self , whether a maximum number of matches was set and, if so, whether that number was reached.

Parameters
selfA pointer to a fancy_string_regex_t instance for which to check whether the maximum number of matches was reached (if specified).
Returns
bool A boolean value indicating whether (true) or not (false) the maximum number of matches (if specified) was reached.
Note
When calling fancy_string_regex_create(), if n_max_matches is set to -1, no limit will be set, and this will alway return false for the corresponding instance.

◆ fancy_string_regex_pattern()

fancy_string_t * fancy_string_regex_pattern ( fancy_string_regex_t const *const  self)

Retrieves and returns the regular expression object's pattern as a memory-independent string object.

Parameters
selfA pointer to a fancy_string_regex_t instance for which to retrieve the "regular expression" pattern.
Returns
fancy_string_t* A pointer to a memory-independent string object containing a copy of the regular expression object's internal pattern.

◆ fancy_string_regex_replaced_matches()

fancy_string_t * fancy_string_regex_replaced_matches ( fancy_string_regex_t *const  self,
fancy_string_t new_string 
)

Creates and returns a new string object whose internal string data is equivalent to the regular expression object's string object, except that the matches (if any) have been replaced with new_string .

Parameters
selfA pointer to a fancy_string_regex_t instance whose matches' values are replaced with new_string to create a new string object based on the original one.
new_stringA pointer to the fancy_string_t instance whose internal string data is to be used as replacement for that matches.
Returns
fancy_string_t* A pointer to a newly created string object that contains the same data as the regular expression object's string object, except that the matched positions have been replaced with new_string .
See also
fancy_string_replace, fancy_string_replace_value, fancy_string_replaced, fancy_string_replaced_value

◆ fancy_string_regex_split_at_matches()

fancy_string_array_t * fancy_string_regex_split_at_matches ( fancy_string_regex_t const *const  self)

Uses the matches as separators for splitting the regular expression object's string into an array object.

Parameters
selfA pointer to a fancy_string_regex_t instance whose internal string object is to be split into an array object.
Returns
fancy_string_array_t* A pointer to an array object created by splitting the regular expression object's internal string object using the matches as separators.
See also
fancy_string_split, fancy_string_split_by_value

◆ fancy_string_regex_string()

fancy_string_t * fancy_string_regex_string ( fancy_string_regex_t const *const  self)

Retrieves and returns the regular expression object's content string (i.e., the string to be searched for matches) as a memory-independent string object.

Parameters
selfA pointer to a fancy_string_regex_t instance for which to retrieve the "content string".
Returns
fancy_string_t* A pointer to a memory-independent string object containing a copy of the regular expression object's internal "content string".

◆ fancy_string_regex_string_for_match_at_index()

fancy_string_t * fancy_string_regex_string_for_match_at_index ( fancy_string_regex_t const *const  self,
size_t  index 
)

Retrieves the index -th matched character sequence (if any), and returns it as a memory-independent string object.

Parameters
selfA pointer to the fancy_string_regex_t instance for which to retrieve a substring of the original string object for the match at position index .
indexThe position of the match inside self , for which a substring is to be created and returned.
Returns
fancy_string_t* A pointer to a fancy_string_t instance containing the index -th matched character sequence. If index is out of bounds, the NULL pointer will be returned.
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
fancy_string_t *s = fancy_string_create("Hello, lib<fancy_string>! My name is Francis. Can I call you lib<fancy-string> instead?");
fancy_string_t *pattern = fancy_string_create("[a-z]*<[-_a-z]*>");
assert(re != NULL);
{
assert(re != NULL);
assert(fancy_string_equals_value(lib_name, "lib<fancy_string>"));
fancy_string_print(lib_name, stdout, true);
}
{
assert(re != NULL);
assert(fancy_string_equals_value(lib_name, "lib<fancy-string>"));
fancy_string_print(lib_name, stdout, true);
}
return 0;
}
fancy_string_t * fancy_string_regex_string_for_match_at_index(fancy_string_regex_t const *const self, size_t index)
Retrieves the index -th matched character sequence (if any), and returns it as a memory-independent s...

◆ fancy_string_regex_to_string_with_updated_matches()

fancy_string_t * fancy_string_regex_to_string_with_updated_matches ( fancy_string_regex_t const *const  self,
fancy_string_regex_updater_t  fn,
void context 
)

Similar to, but more flexible than fancy_string_regex_replaced_matches(), this method can be used to generate a string object whose internal data is a copy of the regular expression object's original string, but with (potentially) modified substring values where matches were founds. The reason why this method is more flexible than fancy_string_regex_replaced_matches() is because it allows applying custom modification rules on a per-match basis (see the example).

Parameters
selfA pointer to the fancy_string_regex_t instance to be used to generate the new string object.
fnA pointer to a function that conforms to the fancy_string_regex_updater_t signature, which will be called internally for each match in the regular expression object self .
contextA pointer to an application-defined context object, which gets passed to fn on each call.
Returns
fancy_string_t* A pointer to the created string object.
See also
fancy_string_regex_updater_t, fancy_string_regex_replaced_matches
Note
This method is used internally by the fancy_string_regex_debug() method, when its verbose argument is set to true, to generate the .verbose_string[calculated] debug output.
Example:
#include <stdio.h>
#include <assert.h>
#include "fancy_string.h"
#define IGNORE_UNUSED(x) ((void)(x))
static void updater_callback(fancy_string_t *const match, size_t start, size_t end, fancy_string_t const *const string, void *context);
struct updater_callback_context
{
char *uppercase_if_equals_to;
};
int main(void)
{
fancy_string_t *s = fancy_string_create("My name is Francis and I wrote this library for fun!");
fancy_string_t *pattern = fancy_string_create("[A-Z][a-z]*");
assert(re != NULL);
struct updater_callback_context context = {.uppercase_if_equals_to = "Francis"};
fancy_string_t *updated_string = fancy_string_regex_to_string_with_updated_matches(re, updater_callback, &context);
assert(fancy_string_equals_value(updated_string, "[[My]] name is [[FRANCIS]] and [[I]] wrote this library for fun!"));
fancy_string_print(updated_string, stdout, true);
fancy_string_destroy(updated_string);
return 0;
}
static void updater_callback(fancy_string_t *const match, size_t start, size_t end, fancy_string_t const *const string, void *context)
{
IGNORE_UNUSED(start);
IGNORE_UNUSED(end);
IGNORE_UNUSED(string);
struct updater_callback_context *c = (struct updater_callback_context *)context;
if (fancy_string_equals_value(match, c->uppercase_if_equals_to))
{
}
}
fancy_string_t * fancy_string_regex_to_string_with_updated_matches(fancy_string_regex_t const *const self, fancy_string_regex_updater_t fn, void *context)
Similar to, but more flexible than fancy_string_regex_replaced_matches(), this method can be used to ...
void fancy_string_uppercase(fancy_string_t *const self)
Applies an uppercase transformation to the string object's internal data.

◆ fancy_string_replace()

void fancy_string_replace ( fancy_string_t *const  self,
fancy_string_t const *const  old_substring,
fancy_string_t const *const  new_substring,
ssize_t  replace_n 
)

Replaces the specified number of occurrences (i.e., replace_n ) of old_substring 's internal value with new_substring 's internal value in the string object's internal data.

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be modified.
old_substringA pointer to another fancy_string_t instance containing the pattern to be found and replaced with new_substring 's value.
new_substringA pointer to another fancy_string_t instance containing the value with which to replace occurrences of old_substring 's value.
replace_nThe maximum number of times, starting from the beginning of the string, to replace old_substring 's value. Specifying replace_n = -1 will result in all occurrences being replaced.
See also
fancy_string_replace_value, fancy_string_replaced_value, fancy_string_replaced

◆ fancy_string_replace_value()

void fancy_string_replace_value ( fancy_string_t *const  self,
char const *const  old_value,
char const *const  new_value,
ssize_t  replace_n 
)

Replaces the specified number of occurrences (i.e., replace_n ) of old_value with new_value in the string object's internal data.

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be modified.
old_valueA pointer to the pattern (i.e., a pointer to a null-terminated string) to be found and replaced with new_value .
new_valueA pointer to the value (i.e., a pointer to a null-terminated string) with which to replace occurrences of old_value .
replace_nThe maximum number of times, starting from the beginning of the string, to replace old_value . Specifying replace_n = -1 will result in all occurrences being replaced.
See also
fancy_string_replace, fancy_string_replaced_value, fancy_string_replaced

◆ fancy_string_replaced()

fancy_string_t * fancy_string_replaced ( fancy_string_t const *const  self,
fancy_string_t const *const  old_substring,
fancy_string_t const *const  new_substring,
ssize_t  replace_n 
)

Creates a string object with the specified number of occurrences (i.e., replace_n ) of old_substring 's internal value replaced with new_substring 's internal value.

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be copied and then modified.
old_substringA pointer to the pattern to be found and replaced with new_substring .
new_substringA pointer to the value with which to replace occurrences of old_substring .
replace_nThe maximum number of times, starting from the beginning of the string, to replace old_substring . Specifying replace_n = -1 will result in all occurrences being replaced.
Returns
fancy_string_t* A pointer to a newly created, memory-independent string object where replace_n 's occurrences of new_substring have been replaced with old_substring .
See also
fancy_string_replace_value, fancy_string_replace, fancy_string_replaced_value

◆ fancy_string_replaced_value()

fancy_string_t * fancy_string_replaced_value ( fancy_string_t const *const  self,
char const *const  old_value,
char const *const  new_value,
ssize_t  replace_n 
)

Creates a string object with the specified number of occurrences (i.e., replace_n ) of old_value replaced with new_value.

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be copied and then modified.
old_valueA pointer to the pattern (i.e., a pointer to a null-terminated string) to be found and replaced with new_value .
new_valueA pointer to the value (i.e., a pointer to a null-terminated string) with which to replace occurrences of old_value .
replace_nThe maximum number of times, starting from the beginning of the string, to replace old_value . Specifying replace_n = -1 will result in all occurrences being replaced.
Returns
fancy_string_t* A pointer to a newly created, memory-independent string object where replace_n 's occurrences of new_value have been replaced with old_value.
See also
fancy_string_replace_value, fancy_string_replace, fancy_string_replaced

◆ fancy_string_size()

size_t fancy_string_size ( fancy_string_t const *const  self)

Returns the size of the object's internal string (conceptually the same as strlen() ).

Parameters
selfA pointer to the fancy_string_t instance for which the size is to be returned.
Returns
size_t A value corresponding to the size of the internal string data.

◆ fancy_string_split()

fancy_string_array_t * fancy_string_split ( fancy_string_t const *const  self,
fancy_string_t const *const  separator,
ssize_t  n_max_splits 
)

Splits the string into an array (i.e., a list) of string objects based on the separator string object's internal value.

Parameters
selfA pointer to the fancy_string_t instance whose internal string is to be split.
separatorA pointer to the fancy_string_t instance whose internal data is to be used as the splitting pattern.
n_max_splitsThe maximum number of times to split (i.e., the maximum number of matches to act upon). If this value set to -1, there will be as many splits as there are matches found. If set to 0, the method will simply return an array object with a single element containing a copy of the original string object.
Returns
fancy_string_array_t* A pointer to a newly created, memory-independent array object containing the "splitted" string components.
See also
fancy_string_split_by_value

◆ fancy_string_split_by_value()

fancy_string_array_t * fancy_string_split_by_value ( fancy_string_t const *const  self,
char const *const  separator,
ssize_t  n_max_splits 
)

Splits the string into an array (i.e., a list) of string objects based on the separator .

Parameters
selfA pointer to the fancy_string_t instance whose internal string is to be split.
separatorA value (i.e., a pointer to a null-terminated string) that contains the pattern to be used for splitting.
n_max_splitsThe maximum number of times to split (i.e., the maximum number of matches to act upon). If this value is set -1, there will be as many splits as there are matches found. If set to 0, the method will simply return an array object with a single element containing a copy of the original string object.
Returns
fancy_string_array_t* A pointer to a newly created, memory-independent array object containing the "splitted" string components.
See also
fancy_string_split

◆ fancy_string_starts_with()

bool fancy_string_starts_with ( fancy_string_t const *const  self,
fancy_string_t const *const  string 
)

Checks whether the string object's internal value starts with string 's internal value.

Parameters
selfA pointer to the fancy_string_t instance to be checked.
stringA Pointer to another fancy_string_t instance against whose internal value to check for "leading equality".
Returns
bool A boolean value indicating whether the object's data starts with string 's internal value (true) or not (false).
See also
fancy_string_starts_with_value

◆ fancy_string_starts_with_value()

bool fancy_string_starts_with_value ( fancy_string_t const *const  self,
char const *const  value 
)

Checks whether the string object's internal value starts with value.

Parameters
selfA pointer to the fancy_string_t instance to be checked.
valueA value (i.e., a pointer to a null-terminated string) against which to check for "leading equality".
Returns
bool A value indicating whether the object's data starts with value (true) or not (false).
See also
fancy_string_starts_with

◆ fancy_string_substring()

fancy_string_t * fancy_string_substring ( fancy_string_t const *const  self,
ssize_t  start,
ssize_t  end 
)

Creates a substring of a string object.

Parameters
selfA pointer to the fancy_string_t instance for which to create a substring.
startThe start index of the substring. If this value is set to -1, the start index will be 0.
endThe end index of the substring. If this value is set to -1, the end index will be n, which corresponds to self 's size. It should be noted that end is not included in the range. For instance, start = 0 and end = 5 will return of substring for the 0..4, not 0..5.
Returns
fancy_string_t* A pointer to a memory-independent string object containing the specified substring.
Note
This method is very permissive with its start and end index values. For instance, if start is greater than end, the two values will be swapped with one another. Also, if end is out of bounds, the substring's upper bound will be set as n - 1. Lastly, if the specified range is completely out of bounds, an empty string object will be returned.
Example:
#include <assert.h>
#include "fancy_string.h"
int main(void)
{
fancy_string_t *s = fancy_string_create("this is a test");
// end = 6 to get 0..5 range
assert(fancy_string_equals_value(s_sub, "this i"));
return 0;
}

◆ fancy_string_trim()

void fancy_string_trim ( fancy_string_t *const  self)

Trims (i.e., remove all the white spaces from) both the right and left-hand sides of the string object's internal values.

Parameters
selfA pointer to the fancy_string_t instance to be trimmed.
See also
fancy_string_trimmed

◆ fancy_string_trim_left()

void fancy_string_trim_left ( fancy_string_t *const  self)

Trims (i.e., remove all the white spaces from) the left-hand side of the string object's internal value.

Parameters
selfA pointer to the fancy_string_t instance to be trimmed left.
See also
fancy_string_trimmed_left

◆ fancy_string_trim_right()

void fancy_string_trim_right ( fancy_string_t *const  self)

Trims (i.e., remove all the white spaces from) the right-hand side of the string object's internal value.

Parameters
selfA pointer to the fancy_string_t instance to be trimmed right.
See also
fancy_string_trimmed_right

◆ fancy_string_trimmed()

fancy_string_t * fancy_string_trimmed ( fancy_string_t const *const  self)

Creates a trimmed version of the string object (i.e., a version with all the leading and trailing white spaces removed).

Parameters
selfA pointer to the fancy_string_t instance for which to create a trimmed copy.
Returns
fancy_string_t* A pointer to a new, memory-independent string object that is the same as self , except that it has been trimmed at both the right and the left.
See also
fancy_string_trim.

◆ fancy_string_trimmed_left()

fancy_string_t * fancy_string_trimmed_left ( fancy_string_t const *const  self)

Creates a left-hand-trimmed version of the string object (i.e., a version with all the leading white spaces removed).

Parameters
selfA pointer to the fancy_string_t instance for which to create a left-trimmed copy.
Returns
fancy_string_t* A pointer to a new, memory-independent string object that is the same as self , except that it has been trimmed at the left.
See also
fancy_string_trim_left

◆ fancy_string_trimmed_right()

fancy_string_t * fancy_string_trimmed_right ( fancy_string_t const *const  self)

Creates a right-hand-trimmed version of the string object (i.e., a version with all the trailing white spaces removed).

Parameters
selfA pointer to the fancy_string_t instance for which to create a right-trimmed copy.
Returns
fancy_string_t* A pointer to a new, memory-independent string object that is the same as self , except that it has been trimmed at the right.
See also
fancy_string_trim_right.

◆ fancy_string_update()

void fancy_string_update ( fancy_string_t *const  self,
fancy_string_t const *const  string 
)

Updates the internal state of the string object using that of another string object (i.e., string ).

Parameters
selfA pointer to the fancy_string_t instance whose value needs updating.
stringA pointer to another fancy_string_t instance whose internal state is to be copied inside self .
See also
fancy_string_update_value

◆ fancy_string_update_value()

void fancy_string_update_value ( fancy_string_t *const  self,
char const *const  value 
)

Updates the internal state of the string object with the new string data (i.e., value ).

Parameters
selfA pointer to the fancy_string_t instance whose value needs updating.
valueThe value (i.e., a pointer to a null-terminated string) with which to replace the string object's internal state.
Note
The method makes a copy of the value , so if that value has been heap-allocated by the application, the application is responsible for freeing its memory when no longer needed.
See also
fancy_string_update

◆ fancy_string_uppercase()

void fancy_string_uppercase ( fancy_string_t *const  self)

Applies an uppercase transformation to the string object's internal data.

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be uppercased.
Note
Internally, this method uses the toupper() function defined in the C Standard Library ctype.h header file. This means, among other things, that uppercasing of accented characters may not behave as expected. For instance, depending on the implementation, a character such as à will likely not be transformed to À.
See also
fancy_string_uppercased

◆ fancy_string_uppercased()

fancy_string_t * fancy_string_uppercased ( fancy_string_t const *const  self)

Creates a new string object whose internal data corresponds to a copy of self with an uppercase transformation performed on it.

Parameters
selfA pointer to the fancy_string_t instance whose internal data is to be copied and then uppercased.
Returns
fancy_string_t* A pointer to a newly created, memory-independent string object that contains an uppercased version of self 's internal data.
Note
Internally, this method uses the toupper() function defined in the C Standard Library ctype.h header file. This means, among other things, that uppercasing of accented characters may not behave as expected. For instance, depending on the implementation, a character such as à will likely not be transformed to À.
See also
fancy_string_uppercase

◆ fancy_string_value()

char * fancy_string_value ( fancy_string_t const *const  self)

Returns a pointer to a heap-allocated copy of the string object's internal state.

Parameters
selfA pointer to the fancy_string_t instance for which a copy of the internal state is requested.
Returns
char* A pointer to a heap-allocated copy of the string object's internal state (i.e., a pointer to a null-terminated string).
Warning
Calling this method creates an heap-alloacted copy of the string object's internal state, such that it becomes the application's responsibility to free that memory (using the standard library's free() function) once it is no longer needed.