From: Kevin Day Date: Sun, 22 Nov 2020 03:42:09 +0000 (-0600) Subject: Update: add f_string_maps_t increase and decrease functions and FLL documentation... X-Git-Tag: 0.5.2~61 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=17307d86e60cfbbce858c356a62e82c81738c4a2;p=fll Update: add f_string_maps_t increase and decrease functions and FLL documentation cleanup. Add the appropriate functions. This file will need to be reviewed to have increase and decrease functions for all of the string types. Fix documentation for FSS Basic and FSS Extended, which should state that the parameter is optional. --- diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index 52549fa..2de9c69 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -1432,6 +1432,45 @@ extern "C" { } #endif // _di_fl_string_lengths_increase_ +#ifndef _di_fl_string_maps_decrease_ + f_return_status fl_string_maps_decrease(f_string_maps_t *maps) { + #ifndef _di_level_1_parameter_checking_ + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status_t status = F_none; + + if (maps->size - 1 > 0) { + f_macro_string_maps_t_resize(status, (*maps), maps->size - 1); + } + else { + f_macro_string_maps_t_delete(status, (*maps)); + } + + return status; + } +#endif // _di_fl_string_maps_decrease_ + +#ifndef _di_fl_string_maps_decrease_by_ + f_return_status fl_string_maps_decrease_by(const f_array_length_t amount, f_string_maps_t *maps) { + #ifndef _di_level_1_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status_t status = F_none; + + if (maps->size - amount > 0) { + f_macro_string_maps_t_resize(status, (*maps), maps->size - amount); + } + else { + f_macro_string_maps_t_delete(status, (*maps)); + } + + return status; + } +#endif // _di_fl_string_maps_decrease_by_ + #ifndef _di_fl_string_lengths_increase_by_ f_return_status fl_string_lengths_increase_by(const f_array_length_t amount, f_string_lengths_t *lengths) { #ifndef _di_level_1_parameter_checking_ @@ -1455,6 +1494,51 @@ extern "C" { } #endif // _di_fl_string_lengths_increase_by_ +#ifndef _di_fl_string_maps_increase_ + f_return_status fl_string_maps_increase(f_string_maps_t *maps) { + #ifndef _di_level_1_parameter_checking_ + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status_t status = F_none; + + if (maps->size + f_memory_default_allocation_step > f_array_length_t_size) { + if (maps->size == f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + f_macro_string_maps_t_resize(status, (*maps), f_array_length_t_size); + return F_array_too_large; + } + + f_macro_string_maps_t_resize(status, (*maps), maps->size + f_memory_default_allocation_step); + return status; + } +#endif // _di_fl_string_maps_increase_ + +#ifndef _di_fl_string_maps_increase_by_ + f_return_status fl_string_maps_increase_by(const f_array_length_t amount, f_string_maps_t *maps) { + #ifndef _di_level_1_parameter_checking_ + if (!amount) return F_status_set_error(F_parameter); + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_1_parameter_checking_ + + f_status_t status = F_none; + + if (maps->size + amount > f_array_length_t_size) { + if (maps->size == f_array_length_t_size) { + return F_status_set_error(F_array_too_large); + } + + f_macro_string_maps_t_resize(status, (*maps), f_array_length_t_size); + return F_array_too_large; + } + + f_macro_string_maps_t_resize(status, (*maps), maps->size + amount); + return status; + } +#endif // _di_fl_string_maps_increase_by_ + #ifndef _di_fl_string_mash_ f_return_status fl_string_mash(const f_string_t glue, const f_string_length_t glue_length, const f_string_t source, const f_string_length_t length, f_string_dynamic_t *destination) { #ifndef _di_level_1_parameter_checking_ diff --git a/level_1/fl_string/c/string.h b/level_1/fl_string/c/string.h index 8297320..dfaf727 100644 --- a/level_1/fl_string/c/string.h +++ b/level_1/fl_string/c/string.h @@ -2000,6 +2000,92 @@ extern "C" { #endif // _di_fl_string_lengths_increase_by_ /** + * Resize the string maps array to a smaller size, by 1. + * + * This will shrink the size by size - 1. + * This will not shrink the size to less than 0. + * + * @param maps + * The string maps array to resize. + * + * @return + * F_none on success. + * F_memory_allocation (with error bit) on memory allocation error. + * F_memory_reallocation (with error bit) on memory reallocation error. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fl_string_maps_decrease_ + extern f_return_status fl_string_maps_decrease(f_string_maps_t *maps); +#endif // _di_fl_string_maps_decrease_ + +/** + * Resize the string maps array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param maps + * The string maps array to resize. + * + * @return + * F_none on success. + * F_memory_allocation (with error bit) on memory allocation error. + * F_memory_reallocation (with error bit) on memory reallocation error. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fl_string_maps_decrease_by_ + extern f_return_status fl_string_maps_decrease_by(const f_array_length_t amount, f_string_maps_t *maps); +#endif // _di_fl_string_maps_decrease_by_ + +/** + * Increase the size of the string maps array, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param maps + * The string maps array to resize. + * + * @return + * F_none on success. + * F_array_too_large on success, but the requested length is too large for the buffer. + * F_memory_allocation (with error bit) on memory allocation error. + * F_memory_reallocation (with error bit) on memory reallocation error. + * F_parameter (with error bit) if a parameter is invalid. + * F_array_too_large (with error bit) if the new array length is too large. + */ +#ifndef _di_fl_string_maps_increase_ + extern f_return_status fl_string_maps_increase(f_string_maps_t *maps); +#endif // _di_fl_string_maps_increase_ + +/** + * Resize the string maps array to a larger size. + * + * This will resize making the string larger based on the given length. + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param amount + * A positive number representing how much to increase the size by. + * @param maps + * The string maps array to resize. + * + * @return + * F_none on success. + * F_array_too_large on success, but the requested length is too large for the buffer. + * F_memory_allocation (with error bit) on memory allocation error. + * F_memory_reallocation (with error bit) on memory reallocation error. + * F_parameter (with error bit) if a parameter is invalid. + * F_array_too_large (with error bit) if the new array length is too large. + */ +#ifndef _di_fl_string_maps_increase_by_ + extern f_return_status fl_string_maps_increase_by(const f_array_length_t amount, f_string_maps_t *maps); +#endif // _di_fl_string_maps_increase_by_ + +/** * Append the source string onto the destination with the glue in between. * * If the destination string is empty, then no glue is appended. diff --git a/level_2/fll_fss/c/fss_basic.h b/level_2/fll_fss/c/fss_basic.h index 7297535..8ea06c5 100644 --- a/level_2/fll_fss/c/fss_basic.h +++ b/level_2/fll_fss/c/fss_basic.h @@ -41,7 +41,7 @@ extern "C" { * @param contents * This will be populated with all valid contents found. * @param objects_quoted - * An array mapped to each object in objects representing the quote discovered, if any. + * (optional) An array mapped to each object in objects representing the quote discovered, if any. * Set the pointer address to 0 to disable. * @param objects_delimits * An array of delimits for objects detected during processing. diff --git a/level_2/fll_fss/c/fss_extended.h b/level_2/fll_fss/c/fss_extended.h index 7fd94d3..f250b8d 100644 --- a/level_2/fll_fss/c/fss_extended.h +++ b/level_2/fll_fss/c/fss_extended.h @@ -39,10 +39,10 @@ extern "C" { * @param contents * This will be populated with all valid contents found. * @param objects_quoted - * An array mapped to each object in objects representing the quote discovered, if any. + * (optional) An array mapped to each object in objects representing the quote discovered, if any. * Set the pointer address to 0 to disable. * @param contents_quoted - * An array mapped to each content in contents representing the quote discovered, if any. + * (optional) An array mapped to each content in contents representing the quote discovered, if any. * Set the pointer address to 0 to disable. * @param objects_delimits * An array of delimits for objects detected during processing.