lib<fancy_string> 0.1.1
A C library for easy and fun string manipulation
Loading...
Searching...
No Matches
fancy_string.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023 BB-301 <fw3dg3@gmail.com>
3
4 Permission is hereby granted, free of charge, to any person
5 obtaining a copy of this software and associated documentation
6 files (the “Software”), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge,
8 publish, distribute, sublicense, and/or sell copies of the Software,
9 and to permit persons to whom the Software is furnished to do so,
10 subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22*/
23
28#ifndef __FANCY_STRING_H__
29#define __FANCY_STRING_H__
30
31#include <string.h>
32#include <stdlib.h>
33#include <stdio.h>
34#include <stdbool.h>
35#include <stdint.h>
36#include <stddef.h>
37#include <sys/types.h>
38
39// -----------------------------------------------
40// OPAQUE TYPES
41// -----------------------------------------------
42
54typedef struct fancy_string_s fancy_string_t;
55
68typedef struct fancy_string_array_s fancy_string_array_t;
69
82typedef struct fancy_string_regex_s fancy_string_regex_t;
83
90{
101 size_t start;
108 size_t end;
110
122{
148
149// -----------------------------------------------
150// MISC
151// -----------------------------------------------
152
161
168
183
195
216
224
225// -----------------------------------------------
226// STRING (methods)
227// -----------------------------------------------
228
236fancy_string_t *fancy_string_create(char const *const value);
237
256fancy_string_t *fancy_string_from_copied_memory(void const *const pointer, size_t n);
257
275
295
305fancy_string_t *fancy_string_create_repeat(char const *const value, size_t n_repeat);
306
314
321
331
341void fancy_string_print(fancy_string_t const *const self, FILE *stream, bool debug);
342
348size_t fancy_string_size(fancy_string_t const *const self);
349
355bool fancy_string_is_empty(fancy_string_t const *const self);
356
362
372void fancy_string_update_value(fancy_string_t *const self, char const *const value);
373
380void fancy_string_update(fancy_string_t *const self, fancy_string_t const *const string);
381
391char *fancy_string_value(fancy_string_t const *const self);
392
401void fancy_string_append_value(fancy_string_t *const self, char const *const value);
402
411void fancy_string_append(fancy_string_t *const self, fancy_string_t const *const string);
412
421void fancy_string_prepend_value(fancy_string_t *const self, char const *const value);
422
431void fancy_string_prepend(fancy_string_t *const self, fancy_string_t const *const string);
432
441bool fancy_string_equals_value(fancy_string_t const *const self, char const *const value);
442
450bool fancy_string_equals(fancy_string_t const *const self, fancy_string_t const *const string);
451
461bool fancy_string_starts_with_value(fancy_string_t const *const self, char const *const value);
462
472bool fancy_string_starts_with(fancy_string_t const *const self, fancy_string_t const *const string);
473
483bool fancy_string_ends_with_value(fancy_string_t const *const self, char const *const value);
484
494bool fancy_string_ends_with(fancy_string_t const *const self, fancy_string_t const *const string);
495
506ssize_t fancy_string_index_of_value(fancy_string_t const *const self, char const *const value);
507
518ssize_t fancy_string_index_of(fancy_string_t const *const self, fancy_string_t const *const string);
519
527bool fancy_string_contains_value(fancy_string_t const *const self, char const *const value);
528
538bool fancy_string_contains(fancy_string_t const *const self, fancy_string_t const *const string);
539
557
564
574
581
591
599
609
623fancy_string_array_t *fancy_string_split_by_value(fancy_string_t const *const self, char const *const separator, ssize_t n_max_splits);
624
640fancy_string_array_t *fancy_string_split(fancy_string_t const *const self, fancy_string_t const *const separator, ssize_t n_max_splits);
641
651void fancy_string_pad_start(fancy_string_t *const self, size_t target_size, char value);
652
663fancy_string_t *fancy_string_padded_start(fancy_string_t const *const self, size_t target_size, char value);
664
672void fancy_string_pad_end(fancy_string_t *const self, size_t target_size, char value);
673
684fancy_string_t *fancy_string_padded_end(fancy_string_t const *const self, size_t target_size, char value);
685
698void fancy_string_replace_value(fancy_string_t *const self, char const *const old_value, char const *const new_value, ssize_t replace_n);
699
710void 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);
711
727fancy_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);
728
742fancy_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);
743
755
770
782
797
808void fancy_string_line_break(fancy_string_t *const self, bool with_carriage_return);
809
810// -----------------------------------------------
811// REGEX (methods)
812// -----------------------------------------------
813
837fancy_string_regex_t *fancy_string_regex_create(fancy_string_t const *const string, fancy_string_t const *const pattern, ssize_t n_max_matches);
838
844
852void fancy_string_regex_debug(fancy_string_regex_t const *const self, FILE *stream, bool verbose);
853
863
878
889
898
908
919
932
941
951
964typedef 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);
965
984
1001
1015
1016// -----------------------------------------------
1017// ARRAY (methods)
1018// -----------------------------------------------
1019
1026
1047
1055
1066
1080
1090
1100void fancy_string_array_print(fancy_string_array_t const *const self, FILE *stream, bool debug);
1101
1108
1117
1124
1133void fancy_string_array_push_value(fancy_string_array_t *const self, char const *const value);
1134
1154void fancy_string_array_push_values(fancy_string_array_t *const self, char const *const first_value, ...);
1155
1164void fancy_string_array_push(fancy_string_array_t *const self, fancy_string_t const *const string);
1165
1178
1191char *fancy_string_array_get_value(fancy_string_array_t const *const self, size_t index);
1192
1207
1219
1231
1239
1251
1259
1273void fancy_string_array_insert_value(fancy_string_array_t *const self, char const *const value, size_t index);
1274
1288void fancy_string_array_insert(fancy_string_array_t *const self, fancy_string_t const *const string, size_t index);
1289
1299
1310
1321
1332
1342fancy_string_t *fancy_string_array_join_by_value(fancy_string_array_t const *const self, char const *const separator);
1343
1355
1363
1372
1383typedef void (*fancy_string_for_each_t)(fancy_string_t *const string, size_t index, fancy_string_array_t const *const array, void *context);
1384
1399
1410typedef 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);
1411
1432
1443typedef bool (*fancy_string_sort_t)(fancy_string_t const *const string_1, fancy_string_t const *const string_2, void *context);
1444
1455
1467
1478
1490
1503typedef bool (*fancy_string_filter_t)(fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context);
1504
1518
1532
1549
1565
1587fancy_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);
1588
1606void 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);
1607
1626fancy_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);
1627
1640typedef bool (*fancy_string_find_t)(fancy_string_t const *const string, size_t index, fancy_string_array_t const *const array, void *context);
1641
1656
1672
1688
1704
1720bool fancy_string_array_some(fancy_string_array_t const *const self, fancy_string_find_t fn, void *context);
1721
1738bool fancy_string_array_none(fancy_string_array_t const *const self, fancy_string_find_t fn, void *context);
1739
1754bool fancy_string_array_every(fancy_string_array_t const *const self, fancy_string_find_t fn, void *context);
1755
1770
1783ssize_t fancy_string_array_index_of_value(fancy_string_array_t const *const self, char const *const value);
1784
1799
1812ssize_t fancy_string_array_last_index_of_value(fancy_string_array_t const *const self, char const *const value);
1813
1825bool fancy_string_array_includes(fancy_string_array_t const *const self, fancy_string_t const *const string);
1826
1838bool fancy_string_array_includes_value(fancy_string_array_t const *const self, char const *const value);
1839
1840#endif
void void
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....
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 ...
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.
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....
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.
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.
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 fa...
Definition: fancy_string.h:1503
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...
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....
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...
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 ).
fancy_string_array_t * fancy_string_array_clone(fancy_string_array_t const *const self)
Clones an array object.
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
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...
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_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 repl...
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_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_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...
fancy_string_t * fancy_string_create(char const *const value)
Instantiates a string object with its internal state specified by the value parameter.
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.
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_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 trans...
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....
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....
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 a...
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).
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 .
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.
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...
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 fa...
Definition: fancy_string.h:1443
void fancy_string_library_version(uint16_t *major, uint16_t *minor, uint16_t *revision)
Populates its arguments with the library's version.
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 expre...
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....
void fancy_string_array_reverse(fancy_string_array_t *const self)
Reverses the order of the elements in the array object's internal list.
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 .
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.
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.
bool fancy_string_is_empty(fancy_string_t const *const self)
Checks whether the string is empty.
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...
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....
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.
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.
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 s...
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 interna...
fancy_string_memory_usage_mode_e
An enumeration whose members can be used to specify, through the fancy_string_memory_usage_init() sta...
Definition: fancy_string.h:122
@ FANCY_STRING_MEMORY_USAGE_MODE_NONE
Disables the library's memory usage tracking feature. This is the default behaviour.
Definition: fancy_string.h:127
@ 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
@ FANCY_STRING_MEMORY_USAGE_MODE_THREAD_LOCAL
Tracks memory usage and stores the tracking data in a private static variable for each thread using t...
Definition: fancy_string.h:138
size_t fancy_string_memory_usage_get(void)
A "static method" that retrieves and returns the amount of memory allocated by the library.
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 .
void fancy_string_lowercase(fancy_string_t *const self)
Applies a lowercase transformation to the string object's internal data.
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...
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.
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 free...
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 establ...
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.
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 obj...
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_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 v...
void fancy_string_regex_destroy(fancy_string_regex_t *const self)
Destroys the regular expression object.
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 intern...
fancy_string_array_t * fancy_string_array_create(void)
Instantiates an empty array object (i.e, a list whose components are string objects).
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 fa...
Definition: fancy_string.h:964
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...
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 fa...
Definition: fancy_string.h:1383
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.
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_print(fancy_string_t const *const self, FILE *stream, bool debug)
Prints (i.e., writes) the string object's data to the specified stream .
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...
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.
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_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 ).
fancy_string_t * fancy_string_create_empty(void)
Similarly to fancy_string_create(), instantiates a string object, but with its internal value set to ...
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 .
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 .
enum fancy_string_memory_usage_mode_e fancy_string_memory_usage_mode_t
An enumeration whose members can be used to specify, through the fancy_string_memory_usage_init() sta...
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 fa...
Definition: fancy_string.h:1410
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 ).
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,...
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 me...
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.
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 ...
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 ra...
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 arra...
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....
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...
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.
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 re...
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 .
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...
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 m...
size_t start
The 'start' position of the match at position index .
Definition: fancy_string.h:101
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 va...
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.
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 ....
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...
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 method...
Definition: fancy_string.h:1640
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.
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 re...
size_t end
The 'end' position of the match at position index .
Definition: fancy_string.h:108
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...
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 val...
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.
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.
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 ...
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...
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.
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.
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.
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() ).
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.
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 whit...
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 v...
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...
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...
void fancy_string_clear(fancy_string_t *const self)
Clears the internal string data (i.e., makes self an empty string object).
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...
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.
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 wi...
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....
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...
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.
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 "...
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,...
void fancy_string_library_version_print(FILE *stream)
Prints (i.e., writes) the library's version to the specified stream.
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 whi...
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 (...
void fancy_string_uppercase(fancy_string_t *const self)
Applies an uppercase transformation to the string object's internal data.
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 .
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
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...
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 .
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 sp...
ssize_t index
The index (i.e., the position) of the match inside the fancy_string_regex_t instance.
Definition: fancy_string.h:97
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...
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.
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 ...
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 transf...
struct fancy_string_regex_match_info_s fancy_string_regex_match_info_t
A type (i.e., a structure), returned by the fancy_string_regex_match_info_for_index() method,...
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 .
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...
bool fancy_string_array_is_empty(fancy_string_array_t const *const self)
Checks whether the array is empty.
A type (i.e., a structure), returned by the fancy_string_regex_match_info_for_index() method,...
Definition: fancy_string.h:90
ssize_t ssize_t