From: Kevin Day Date: Fri, 11 Nov 2022 03:25:05 +0000 (-0600) Subject: Cleanup: Improve organization in f_string, using addtional files. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=541fecc282751ed96ada64c336796c998431f820;p=fll Cleanup: Improve organization in f_string, using addtional files. Create more files to better organize structures and their accompanying functions. Structures like f_string_dynamic_t, f_string_dynamics_t, and f_string_dynamicss_t now each have their own files. --- diff --git a/build/level_0/settings b/build/level_0/settings index 681a341..d83c156 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -40,7 +40,8 @@ build_sources_library serialize.c private-serialize.c serialize/common.c build_sources_library signal.c build_sources_library socket.c build_sources_library status_string.c -build_sources_library string.c private-string.c string/common.c string/dynamic.c string/map.c string/map_multi.c string/private-dynamic.c string/private-map.c string/private-map_multi.c string/private-quantity.c string/private-range.c string/private-triple.c string/quantity.c string/range.c string/static.c string/triple.c +build_sources_library string.c private-string.c string/common.c string/private-dynamic.c string/private-dynamics.c string/private-dynamicss.c string/private-maps.c string/private-mapss.c string/private-map_multis.c string/private-map_multiss.c string/private-quantitys.c string/private-quantityss.c string/private-ranges.c string/private-rangess.c string/private-triples.c string/private-tripless.c +build_sources_library string/dynamic.c string/dynamics.c string/dynamicss.c string/map.c string/maps.c string/mapss.c string/map_multi.c string/map_multis.c string/map_multiss.c string/quantity.c string/quantitys.c string/quantityss.c string/range.c string/ranges.c string/rangess.c string/static.c string/statics.c string/staticss.c string/triple.c string/triples.c string/tripless.c build_sources_library type_array/array_length.c type_array/cell.c type_array/fll_id.c type_array/int8.c type_array/int16.c type_array/int32.c type_array/int64.c type_array/int128.c type_array/state.c type_array/status.c type_array/uint8.c type_array/uint16.c type_array/uint32.c type_array/uint64.c type_array/uint128.c build_sources_library type_array/private-array_length.c type_array/private-cell.c type_array/private-fll_id.c type_array/private-int8.c type_array/private-int16.c type_array/private-int32.c type_array/private-int64.c type_array/private-int128.c type_array/private-state.c type_array/private-status.c type_array/private-uint8.c type_array/private-uint16.c type_array/private-uint32.c type_array/private-uint64.c type_array/private-uint128.c build_sources_library utf.c private-utf.c private-utf_alphabetic.c private-utf_combining.c private-utf_control.c private-utf_digit.c private-utf_emoji.c private-utf_numeric.c private-utf_phonetic.c private-utf_private.c private-utf_punctuation.c private-utf_subscript.c private-utf_superscript.c private-utf_symbol.c private-utf_unassigned.c private-utf_valid.c private-utf_whitespace.c private-utf_wide.c private-utf_word.c private-utf_zero_width.c @@ -70,7 +71,7 @@ build_sources_headers signal.h signal/common.h build_sources_headers socket.h socket/common.h build_sources_headers status.h build_sources_headers status_string.h -build_sources_headers string.h string/common.h string/dynamic.h string/map.h string/map_multi.h string/quantity.h string/range.h string/static.h string/triple.h +build_sources_headers string.h string/common.h string/dynamic.h string/dynamics.h string/dynamicss.h string/map.h string/maps.h string/mapss.h string/map_multi.h string/map_multis.h string/map_multiss.h string/quantity.h string/quantitys.h string/quantityss.h string/range.h string/ranges.h string/rangess.h string/static.h string/statics.h string/staticss.h string/triple.h string/triples.h string/tripless.h build_sources_headers type.h type_file.h build_sources_headers type_array.h type_array/common.h build_sources_headers type_array/array_length.h type_array/cell.h type_array/fll_id.h type_array/int8.h type_array/int16.h type_array/int32.h type_array/int64.h type_array/int128.h type_array/state.h type_array/status.h type_array/uint8.h type_array/uint16.h type_array/uint32.h type_array/uint64.h type_array/uint128.h diff --git a/build/monolithic/settings b/build/monolithic/settings index 4aa4f10..e8bfd15 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -40,7 +40,8 @@ build_sources_library level_0/serialize.c level_0/private-serialize.c level_0/se build_sources_library level_0/signal.c build_sources_library level_0/socket.c build_sources_library level_0/status_string.c -build_sources_library level_0/string.c level_0/private-string.c level_0/string/common.c level_0/string/dynamic.c level_0/string/map.c level_0/string/map_multi.c level_0/string/private-dynamic.c level_0/string/private-map.c level_0/string/private-map_multi.c level_0/string/private-quantity.c level_0/string/private-range.c level_0/string/private-triple.c level_0/string/quantity.c level_0/string/range.c level_0/string/static.c level_0/string/triple.c +build_sources_library level_0/string.c level_0/private-string.c level_0/string/common.c level_0/string/private-dynamic.c level_0/string/private-dynamics.c level_0/string/private-dynamicss.c level_0/string/private-maps.c level_0/string/private-mapss.c level_0/string/private-map_multis.c level_0/string/private-map_multiss.c level_0/string/private-quantitys.c level_0/string/private-quantityss.c level_0/string/private-ranges.c level_0/string/private-rangess.c level_0/string/private-triples.c level_0/string/private-tripless.c +build_sources_library level_0/string/dynamic.c level_0/string/dynamics.c level_0/string/dynamicss.c level_0/string/map.c level_0/string/maps.c level_0/string/mapss.c level_0/string/map_multi.c level_0/string/map_multis.c level_0/string/map_multiss.c level_0/string/quantity.c level_0/string/quantitys.c level_0/string/quantityss.c level_0/string/range.c level_0/string/ranges.c level_0/string/rangess.c level_0/string/static.c level_0/string/statics.c level_0/string/staticss.c level_0/string/triple.c level_0/string/triples.c level_0/string/tripless.c build_sources_library level_0/type_array/array_length.c level_0/type_array/cell.c level_0/type_array/fll_id.c level_0/type_array/int8.c level_0/type_array/int16.c level_0/type_array/int32.c level_0/type_array/int64.c level_0/type_array/int128.c level_0/type_array/state.c level_0/type_array/status.c level_0/type_array/uint8.c level_0/type_array/uint16.c level_0/type_array/uint32.c level_0/type_array/uint64.c level_0/type_array/uint128.c build_sources_library level_0/type_array/private-array_length.c level_0/type_array/private-cell.c level_0/type_array/private-fll_id.c level_0/type_array/private-int8.c level_0/type_array/private-int16.c level_0/type_array/private-int32.c level_0/type_array/private-int64.c level_0/type_array/private-int128.c level_0/type_array/private-state.c level_0/type_array/private-status.c level_0/type_array/private-uint8.c level_0/type_array/private-uint16.c level_0/type_array/private-uint32.c level_0/type_array/private-uint64.c level_0/type_array/private-uint128.c build_sources_library level_0/utf.c level_0/private-utf.c level_0/private-utf_alphabetic.c level_0/private-utf_combining.c level_0/private-utf_control.c level_0/private-utf_digit.c level_0/private-utf_emoji.c level_0/private-utf_numeric.c level_0/private-utf_phonetic.c level_0/private-utf_private.c level_0/private-utf_punctuation.c level_0/private-utf_subscript.c level_0/private-utf_superscript.c level_0/private-utf_symbol.c level_0/private-utf_unassigned.c level_0/private-utf_valid.c level_0/private-utf_whitespace.c level_0/private-utf_wide.c level_0/private-utf_word.c level_0/private-utf_zero_width.c @@ -94,7 +95,7 @@ build_sources_headers level_0/signal.h level_0/signal/common.h build_sources_headers level_0/socket.h level_0/socket/common.h build_sources_headers level_0/status.h build_sources_headers level_0/status_string.h -build_sources_headers level_0/string.h level_0/string/common.h level_0/string/dynamic.h level_0/string/map.h level_0/string/map_multi.h level_0/string/quantity.h level_0/string/range.h level_0/string/static.h level_0/string/triple.h +build_sources_headers level_0/string.h level_0/string/common.h level_0/string/dynamic.h level_0/string/dynamics.h level_0/string/dynamicss.h level_0/string/map.h level_0/string/maps.h level_0/string/mapss.h level_0/string/map_multi.h level_0/string/map_multis.h level_0/string/map_multiss.h level_0/string/quantity.h level_0/string/quantitys.h level_0/string/quantityss.h level_0/string/range.h level_0/string/ranges.h level_0/string/rangess.h level_0/string/static.h level_0/string/statics.h level_0/string/staticss.h level_0/string/triple.h level_0/string/triples.h level_0/string/tripless.h build_sources_headers level_0/type.h level_0/type_file.h build_sources_headers level_0/type_array.h level_0/type_array/common.h build_sources_headers level_0/type_array/array_length.h level_0/type_array/cell.h level_0/type_array/fll_id.h level_0/type_array/int8.h level_0/type_array/int16.h level_0/type_array/int32.h level_0/type_array/int64.h level_0/type_array/int128.h level_0/type_array/state.h level_0/type_array/status.h level_0/type_array/uint8.h level_0/type_array/uint16.h level_0/type_array/uint32.h level_0/type_array/uint64.h level_0/type_array/uint128.h diff --git a/level_0/f_string/c/private-string.c b/level_0/f_string/c/private-string.c index 3c4ca5a..66ff931 100644 --- a/level_0/f_string/c/private-string.c +++ b/level_0/f_string/c/private-string.c @@ -6,7 +6,7 @@ extern "C" { #endif -#if !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(f_string_dynamic_partial_append) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) +#if !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(_di_f_string_dynamic_partial_append_) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamic_partial_mash_nulless_) || !defined(_di_f_string_dynamic_partial_mish_) || !defined(_di_f_string_dynamic_partial_mish_nulless_) || !defined(_di_f_string_dynamic_partial_prepend_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) f_status_t private_f_string_append(const f_string_t source, const f_array_length_t length, f_string_dynamic_t * const destination) { if (destination->used + length + 1 > destination->size) { @@ -20,7 +20,7 @@ extern "C" { return F_none; } -#endif // !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(f_string_dynamic_partial_append) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) +#endif // !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(_di_f_string_dynamic_partial_append_) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamic_partial_mash_nulless_) || !defined(_di_f_string_dynamic_partial_mish_) || !defined(_di_f_string_dynamic_partial_mish_nulless_) || !defined(_di_f_string_dynamic_partial_prepend_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) #if !defined(_di_f_string_append_assure_nulless_) || !defined(_di_f_string_append_nulless_) || !defined(_di_f_string_dynamic_append_assure_nulless_) || !defined(_di_f_string_dynamic_append_nulless_) || !defined(_di_f_string_dynamic_mash_nulless_) || !defined(_di_f_string_dynamic_partial_append_assure_nulless_) || !defined(_di_f_string_dynamic_partial_append_nulless_) || !defined(_di_f_string_dynamic_partial_mash_nulless_) || !defined(_di_f_string_mash_nulless_) f_status_t private_f_string_append_nulless(const f_string_t source, const f_array_length_t length, f_string_dynamic_t * const destination) { diff --git a/level_0/f_string/c/private-string.h b/level_0/f_string/c/private-string.h index f207c29..8830fcb 100644 --- a/level_0/f_string/c/private-string.h +++ b/level_0/f_string/c/private-string.h @@ -44,15 +44,18 @@ extern "C" { * @see f_string_dynamic_partial_append) * @see f_string_dynamic_partial_append_assure() * @see f_string_dynamic_partial_mash() + * @see f_string_dynamic_partial_mash_nulless() + * @see f_string_dynamic_partial_mish() + * @see f_string_dynamic_partial_mish_nulless() * @see f_string_dynamics_append() * @see f_string_map_multis_append() * @see f_string_mash() * @see f_string_maps_append() * @see f_string_triples_append() */ -#if !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(f_string_dynamic_partial_append) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) +#if !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(_di_f_string_dynamic_partial_append_) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamic_partial_mash_nulless_) || !defined(_di_f_string_dynamic_partial_mish_) || !defined(_di_f_string_dynamic_partial_mish_nulless_) || !defined(_di_f_string_dynamic_partial_prepend_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) extern f_status_t private_f_string_append(const f_string_t source, const f_array_length_t length, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(f_string_dynamic_partial_append) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) +#endif // !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(_di_f_string_dynamic_partial_append_) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamic_partial_mash_nulless_) || !defined(_di_f_string_dynamic_partial_mish_) || !defined(_di_f_string_dynamic_partial_mish_nulless_) || !defined(_di_f_string_dynamic_partial_prepend_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) /** * Private implementation of f_string_append_nulless(). diff --git a/level_0/f_string/c/string.h b/level_0/f_string/c/string.h index bef274c..5291350 100644 --- a/level_0/f_string/c/string.h +++ b/level_0/f_string/c/string.h @@ -24,12 +24,26 @@ // FLL-0 string includes. #include #include +#include +#include #include +#include +#include #include +#include +#include #include +#include +#include #include +#include +#include #include +#include +#include #include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/level_0/f_string/c/string/dynamic.c b/level_0/f_string/c/string/dynamic.c index 8cdd46d..3ba742b 100644 --- a/level_0/f_string/c/string/dynamic.c +++ b/level_0/f_string/c/string/dynamic.c @@ -739,13 +739,8 @@ extern "C" { if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (destination->used && !destination->string[destination->used - 1]) { - return F_none; - } - - if (destination->used == F_string_t_size_d) { - return F_status_set_error(F_string_too_large); - } + if (destination->used && !destination->string[destination->used - 1]) return F_none; + if (destination->used == F_string_t_size_d) return F_status_set_error(F_string_too_large); if (destination->used + 1 > destination->size) { const f_status_t status = private_f_string_dynamic_resize(destination->used + (destination->used + 1 == F_string_t_size_d ? 1 : F_memory_default_allocation_small_d), destination); @@ -770,9 +765,7 @@ extern "C" { } } - if (destination->used == F_string_t_size_d) { - return F_status_set_error(F_string_too_large); - } + if (destination->used == F_string_t_size_d) return F_status_set_error(F_string_too_large); if (destination->used + 1 > destination->size) { const f_status_t status = private_f_string_dynamic_resize(destination->used + (destination->used + 1 == F_string_t_size_d ? 1 : F_memory_default_allocation_small_d), destination); @@ -785,281 +778,6 @@ extern "C" { } #endif // _di_f_string_dynamic_terminate_after_ -#ifndef _di_f_string_dynamics_adjust_ - f_status_t f_string_dynamics_adjust(const f_array_length_t length, f_string_dynamics_t * const dynamics) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamics) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_dynamics_adjust(length, dynamics); - } -#endif // _di_f_string_dynamics_adjust_ - -#ifndef _di_f_string_dynamics_append_ - f_status_t f_string_dynamics_append(const f_string_dynamic_t source, f_string_dynamics_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - return private_f_string_dynamics_append(source, destination); - } -#endif // _di_f_string_dynamics_append_ - -#ifndef _di_f_string_dynamics_append_all_ - f_status_t f_string_dynamics_append_all(const f_string_dynamics_t source, f_string_dynamics_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - return private_f_string_dynamics_append_all(source, destination); - } -#endif // _di_f_string_dynamics_append_all_ - -#ifndef _di_f_string_dynamics_decimate_by_ - f_status_t f_string_dynamics_decimate_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamics) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (dynamics->size > amount) { - return private_f_string_dynamics_adjust(dynamics->size - amount, dynamics); - } - - return private_f_string_dynamics_adjust(0, dynamics); - } -#endif // _di_f_string_dynamics_decimate_by_ - -#ifndef _di_f_string_dynamics_decrease_by_ - f_status_t f_string_dynamics_decrease_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamics) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (dynamics->size > amount) { - return private_f_string_dynamics_resize(dynamics->size - amount, dynamics); - } - - return private_f_string_dynamics_resize(0, dynamics); - } -#endif // _di_f_string_dynamics_decrease_by_ - -#ifndef _di_f_string_dynamics_increase_ - f_status_t f_string_dynamics_increase(const f_array_length_t step, f_string_dynamics_t * const dynamics) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamics) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!step) return F_data_not; - - if (dynamics->used + 1 > dynamics->size) { - f_array_length_t size = dynamics->used + step; - - if (size > F_array_length_t_size_d) { - if (dynamics->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_dynamics_resize(size, dynamics); - } - - return F_data_not; - } -#endif // _di_f_string_dynamics_increase_ - -#ifndef _di_f_string_dynamics_increase_by_ - f_status_t f_string_dynamics_increase_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamics) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (dynamics->used + amount > dynamics->size) { - if (dynamics->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_dynamics_resize(dynamics->used + amount, dynamics); - } - - return F_data_not; - } -#endif // _di_f_string_dynamics_increase_by_ - -#ifndef _di_f_string_dynamics_resize_ - f_status_t f_string_dynamics_resize(const f_array_length_t length, f_string_dynamics_t * const dynamics) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamics) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_dynamics_resize(length, dynamics); - } -#endif // _di_f_string_dynamics_resize_ - -#ifndef _di_f_string_dynamicss_adjust_ - f_status_t f_string_dynamicss_adjust(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamicss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_dynamicss_adjust(length, dynamicss); - } -#endif // _di_f_string_dynamicss_adjust_ - -#ifndef _di_f_string_dynamicss_append_ - f_status_t f_string_dynamicss_append(const f_string_dynamics_t source, f_string_dynamicss_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_dynamicss_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].used = 0; - - if (source.used) { - status = private_f_string_dynamics_append_all(source, &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // _di_f_string_dynamicss_append_ - -#ifndef _di_f_string_dynamicss_append_all_ - f_status_t f_string_dynamicss_append_all(const f_string_dynamicss_t source, f_string_dynamicss_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_string_dynamicss_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } - - for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { - - destination->array[destination->used].used = 0; - - if (source.array[i].used) { - status = private_f_string_dynamics_append_all(source.array[i], &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - } // for - - return F_none; - } -#endif // _di_f_string_dynamicss_append_all_ - -#ifndef _di_f_string_dynamicss_decimate_by_ - f_status_t f_string_dynamicss_decimate_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamicss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (dynamicss->size > amount) { - return private_f_string_dynamicss_adjust(dynamicss->size - amount, dynamicss); - } - - return private_f_string_dynamicss_adjust(0, dynamicss); - } -#endif // _di_f_string_dynamicss_decimate_by_ - -#ifndef _di_f_string_dynamicss_decrease_by_ - f_status_t f_string_dynamicss_decrease_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamicss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (dynamicss->size > amount) { - return private_f_string_dynamicss_resize(dynamicss->size - amount, dynamicss); - } - - return private_f_string_dynamicss_resize(0, dynamicss); - } -#endif // _di_f_string_dynamicss_decrease_by_ - -#ifndef _di_f_string_dynamicss_increase_ - f_status_t f_string_dynamicss_increase(const f_array_length_t step, f_string_dynamicss_t * const dynamicss) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamicss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!step) return F_data_not; - - if (dynamicss->used + 1 > dynamicss->size) { - f_array_length_t size = dynamicss->used + step; - - if (size > F_array_length_t_size_d) { - if (dynamicss->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_dynamicss_resize(size, dynamicss); - } - - return F_data_not; - } -#endif // _di_f_string_dynamicss_increase_ - -#ifndef _di_f_string_dynamicss_increase_by_ - f_status_t f_string_dynamicss_increase_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamicss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (dynamicss->used + amount > dynamicss->size) { - if (dynamicss->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_dynamicss_resize(dynamicss->used + amount, dynamicss); - } - - return F_data_not; - } -#endif // _di_f_string_dynamicss_increase_by_ - -#ifndef _di_f_string_dynamicss_resize_ - f_status_t f_string_dynamicss_resize(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) { - #ifndef _di_level_0_parameter_checking_ - if (!dynamicss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_dynamicss_resize(length, dynamicss); - } -#endif // _di_f_string_dynamicss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/dynamic.h b/level_0/f_string/c/string/dynamic.h index a721b34..ae7a832 100644 --- a/level_0/f_string/c/string/dynamic.h +++ b/level_0/f_string/c/string/dynamic.h @@ -53,64 +53,6 @@ extern "C" { #endif // _di_f_string_dynamic_t_ /** - * An array of dynamic dynamics. - * - * array: The array of dynamic dynamics. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_string_dynamics_t_ - typedef f_string_statics_t f_string_dynamics_t; - - #define f_string_dynamics_t_initialize f_string_statics_t_initialize - - #define macro_f_string_dynamics_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_dynamics_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_dynamics_t_clear(dynamics) macro_f_string_statics_t_clear(dynamics) - - #define macro_f_string_dynamics_t_resize(status, dynamics, length) status = f_string_dynamics_resize(length, &dynamics); - #define macro_f_string_dynamics_t_adjust(status, dynamics, length) status = f_string_dynamics_adjust(length, &dynamics); - - #define macro_f_string_dynamics_t_delete_simple(dynamics) f_string_dynamics_resize(0, &dynamics); - #define macro_f_string_dynamics_t_destroy_simple(dynamics) f_string_dynamics_adjust(0, &dynamics); - - #define macro_f_string_dynamics_t_increase(status, step, dynamics) status = f_string_dynamics_increase(step, &dynamics); - #define macro_f_string_dynamics_t_increase_by(status, dynamics, amount) status = f_string_dynamics_increase_by(amount, &dynamics); - #define macro_f_string_dynamics_t_decrease_by(status, dynamics, amount) status = f_string_dynamics_decrease_by(amount, &dynamics); - #define macro_f_string_dynamics_t_decimate_by(status, dynamics, amount) status = f_string_dynamics_decimate_by(amount, &dynamics); -#endif // _di_f_string_dynamics_t_ - -/** - * An array of dynamic dynamicss. - * - * array: The array of dynamic dynamicss. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_string_dynamicss_t_ - typedef f_string_staticss_t f_string_dynamicss_t; - - #define f_string_dynamicss_t_initialize f_string_staticss_t_initialize - - #define macro_f_string_dynamicss_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_dynamicss_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_dynamicss_t_clear(dynamicss) macro_f_string_staticss_t_clear(dynamicss) - - #define macro_f_string_dynamicss_t_resize(status, dynamicss, length) status = f_string_dynamicss_resize(length, &dynamicss); - #define macro_f_string_dynamicss_t_adjust(status, dynamicss, length) status = f_string_dynamicss_adjust(length, &dynamicss); - - #define macro_f_string_dynamicss_t_delete_simple(dynamicss) f_string_dynamicss_resize(0, &dynamicss); - #define macro_f_string_dynamicss_t_destroy_simple(dynamicss) f_string_dynamicss_adjust(0, &dynamicss); - - #define macro_f_string_dynamicss_t_increase(status, step, dynamicss) status = f_string_dynamicss_increase(step, &dynamicss); - #define macro_f_string_dynamicss_t_increase_by(status, dynamicss, amount) status = f_string_dynamicss_increase_by(amount, &dynamicss); - #define macro_f_string_dynamicss_t_decrease_by(status, dynamicss, amount) status = f_string_dynamicss_decrease_by(amount, &dynamicss); - #define macro_f_string_dynamicss_t_decimate_by(status, dynamicss, amount) status = f_string_dynamicss_decimate_by(amount, &dynamicss); -#endif // _di_f_string_dynamicss_t_ - -/** * Resize the dynamic string. * * @param length @@ -996,362 +938,6 @@ extern "C" { extern f_status_t f_string_dynamic_terminate_after(f_string_dynamic_t * const destination); #endif // _di_f_string_dynamic_terminate_after_ -/** - * Resize the dynamic string array. - * - * @param length - * The new size to use. - * @param dynamics - * The array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_adjust(). - */ -#ifndef _di_f_string_dynamics_adjust_ - extern f_status_t f_string_dynamics_adjust(const f_array_length_t length, f_string_dynamics_t * const dynamics); -#endif // _di_f_string_dynamics_adjust_ - -/** - * Append the single source string onto the destination. - * - * @param source - * The source string to append. - * @param destination - * The destination strings the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamics_append_ - extern f_status_t f_string_dynamics_append(const f_string_dynamic_t source, f_string_dynamics_t * const destination); -#endif // _di_f_string_dynamics_append_ - -/** - * Append the source strings onto the destination. - * - * @param source - * The source strings to append. - * @param destination - * The destination strings the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamics_append_all_ - extern f_status_t f_string_dynamics_append_all(const f_string_dynamics_t source, f_string_dynamics_t * const destination); -#endif // _di_f_string_dynamics_append_all_ - -/** - * Resize the dynamic string 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 decimate the size by. - * @param dynamics - * The array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (size == 0) (or amount is 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamics_decimate_by_ - extern f_status_t f_string_dynamics_decimate_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics); -#endif // _di_f_string_dynamics_decimate_by_ - -/** - * Resize the dynamic string 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 dynamics - * The array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (size == 0) (or amount is 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamics_decrease_by_ - extern f_status_t f_string_dynamics_decrease_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics); -#endif // _di_f_string_dynamics_decrease_by_ - -/** - * Increase the size of the dynamic string 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param dynamics - * The array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamics_increase_ - extern f_status_t f_string_dynamics_increase(const f_array_length_t step, f_string_dynamics_t * const dynamics); -#endif // _di_f_string_dynamics_increase_ - -/** - * Resize the dynamic string array to a larger size. - * - * This will resize making the array 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_d). - * 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 dynamics - * The array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamics_increase_by_ - extern f_status_t f_string_dynamics_increase_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics); -#endif // _di_f_string_dynamics_increase_by_ - -/** - * Resize the dynamic string array. - * - * @param length - * The new size to use. - * @param dynamics - * The array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamics_resize_ - extern f_status_t f_string_dynamics_resize(const f_array_length_t length, f_string_dynamics_t * const dynamics); -#endif // _di_f_string_dynamics_resize_ - -/** - * Resize the dynamics string array. - * - * @param length - * The new size to use. - * @param dynamicss - * The array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_adjust(). - */ -#ifndef _di_f_string_dynamicss_adjust_ - extern f_status_t f_string_dynamicss_adjust(const f_array_length_t length, f_string_dynamicss_t * const dynamicss); -#endif // _di_f_string_dynamicss_adjust_ - -/** - * Append the single source string onto the destination. - * - * @param source - * The source string to append. - * @param destination - * The destination strings the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamicss_append_ - extern f_status_t f_string_dynamicss_append(const f_string_dynamics_t source, f_string_dynamicss_t * const destination); -#endif // _di_f_string_dynamicss_append_ - -/** - * Append the source strings onto the destination. - * - * @param source - * The source strings to append. - * @param destination - * The destination strings the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamicss_append_all_ - extern f_status_t f_string_dynamicss_append_all(const f_string_dynamicss_t source, f_string_dynamicss_t * const destination); -#endif // _di_f_string_dynamicss_append_all_ - -/** - * Resize the dynamics string 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 decimate the size by. - * @param dynamicss - * The array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (size == 0) (or amount is 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamicss_decimate_by_ - extern f_status_t f_string_dynamicss_decimate_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss); -#endif // _di_f_string_dynamicss_decimate_by_ - -/** - * Resize the dynamics string 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 dynamicss - * The array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (size == 0) (or amount is 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamicss_decrease_by_ - extern f_status_t f_string_dynamicss_decrease_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss); -#endif // _di_f_string_dynamicss_decrease_by_ - -/** - * Increase the size of the dynamics string 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param dynamicss - * The array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamicss_increase_ - extern f_status_t f_string_dynamicss_increase(const f_array_length_t step, f_string_dynamicss_t * const dynamicss); -#endif // _di_f_string_dynamicss_increase_ - -/** - * Resize the dynamics string array to a larger size. - * - * This will resize making the array 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_d). - * 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 dynamicss - * The array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamicss_increase_by_ - extern f_status_t f_string_dynamicss_increase_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss); -#endif // _di_f_string_dynamicss_increase_by_ - -/** - * Resize the dynamics string array. - * - * @param length - * The new size to use. - * @param dynamicss - * The array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_dynamicss_resize_ - extern f_status_t f_string_dynamicss_resize(const f_array_length_t length, f_string_dynamicss_t * const dynamicss); -#endif // _di_f_string_dynamicss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/dynamics.c b/level_0/f_string/c/string/dynamics.c new file mode 100644 index 0000000..7af991a --- /dev/null +++ b/level_0/f_string/c/string/dynamics.c @@ -0,0 +1,132 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-dynamic.h" +#include "private-dynamics.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_dynamics_adjust_ + f_status_t f_string_dynamics_adjust(const f_array_length_t length, f_string_dynamics_t * const dynamics) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamics) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_dynamics_adjust(length, dynamics); + } +#endif // _di_f_string_dynamics_adjust_ + +#ifndef _di_f_string_dynamics_append_ + f_status_t f_string_dynamics_append(const f_string_dynamic_t source, f_string_dynamics_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + return private_f_string_dynamics_append(source, destination); + } +#endif // _di_f_string_dynamics_append_ + +#ifndef _di_f_string_dynamics_append_all_ + f_status_t f_string_dynamics_append_all(const f_string_dynamics_t source, f_string_dynamics_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + return private_f_string_dynamics_append_all(source, destination); + } +#endif // _di_f_string_dynamics_append_all_ + +#ifndef _di_f_string_dynamics_decimate_by_ + f_status_t f_string_dynamics_decimate_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamics) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (dynamics->size > amount) { + return private_f_string_dynamics_adjust(dynamics->size - amount, dynamics); + } + + return private_f_string_dynamics_adjust(0, dynamics); + } +#endif // _di_f_string_dynamics_decimate_by_ + +#ifndef _di_f_string_dynamics_decrease_by_ + f_status_t f_string_dynamics_decrease_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamics) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (dynamics->size > amount) { + return private_f_string_dynamics_resize(dynamics->size - amount, dynamics); + } + + return private_f_string_dynamics_resize(0, dynamics); + } +#endif // _di_f_string_dynamics_decrease_by_ + +#ifndef _di_f_string_dynamics_increase_ + f_status_t f_string_dynamics_increase(const f_array_length_t step, f_string_dynamics_t * const dynamics) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamics) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!step) return F_data_not; + + if (dynamics->used + 1 > dynamics->size) { + f_array_length_t size = dynamics->used + step; + + if (size > F_array_length_t_size_d) { + if (dynamics->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_dynamics_resize(size, dynamics); + } + + return F_data_not; + } +#endif // _di_f_string_dynamics_increase_ + +#ifndef _di_f_string_dynamics_increase_by_ + f_status_t f_string_dynamics_increase_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamics) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (dynamics->used + amount > dynamics->size) { + if (dynamics->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_dynamics_resize(dynamics->used + amount, dynamics); + } + + return F_data_not; + } +#endif // _di_f_string_dynamics_increase_by_ + +#ifndef _di_f_string_dynamics_resize_ + f_status_t f_string_dynamics_resize(const f_array_length_t length, f_string_dynamics_t * const dynamics) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamics) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_dynamics_resize(length, dynamics); + } +#endif // _di_f_string_dynamics_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/dynamics.h b/level_0/f_string/c/string/dynamics.h new file mode 100644 index 0000000..2bd9c67 --- /dev/null +++ b/level_0/f_string/c/string/dynamics.h @@ -0,0 +1,230 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines dynamic string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_dynamics_h +#define _F_string_dynamics_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of dynamic strings. + * + * array: The array of dynamic dynamics. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_string_dynamics_t_ + typedef f_string_statics_t f_string_dynamics_t; + + #define f_string_dynamics_t_initialize f_string_statics_t_initialize + + #define macro_f_string_dynamics_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_dynamics_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_dynamics_t_clear(dynamics) macro_f_string_statics_t_clear(dynamics) + + #define macro_f_string_dynamics_t_resize(status, dynamics, length) status = f_string_dynamics_resize(length, &dynamics); + #define macro_f_string_dynamics_t_adjust(status, dynamics, length) status = f_string_dynamics_adjust(length, &dynamics); + + #define macro_f_string_dynamics_t_delete_simple(dynamics) f_string_dynamics_resize(0, &dynamics); + #define macro_f_string_dynamics_t_destroy_simple(dynamics) f_string_dynamics_adjust(0, &dynamics); + + #define macro_f_string_dynamics_t_increase(status, step, dynamics) status = f_string_dynamics_increase(step, &dynamics); + #define macro_f_string_dynamics_t_increase_by(status, dynamics, amount) status = f_string_dynamics_increase_by(amount, &dynamics); + #define macro_f_string_dynamics_t_decrease_by(status, dynamics, amount) status = f_string_dynamics_decrease_by(amount, &dynamics); + #define macro_f_string_dynamics_t_decimate_by(status, dynamics, amount) status = f_string_dynamics_decimate_by(amount, &dynamics); +#endif // _di_f_string_dynamics_t_ + +/** + * Resize the dynamic string array. + * + * @param length + * The new size to use. + * @param dynamics + * The array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_adjust(). + */ +#ifndef _di_f_string_dynamics_adjust_ + extern f_status_t f_string_dynamics_adjust(const f_array_length_t length, f_string_dynamics_t * const dynamics); +#endif // _di_f_string_dynamics_adjust_ + +/** + * Append the single source string onto the destination. + * + * @param source + * The source string to append. + * @param destination + * The destination strings the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamics_append_ + extern f_status_t f_string_dynamics_append(const f_string_dynamic_t source, f_string_dynamics_t * const destination); +#endif // _di_f_string_dynamics_append_ + +/** + * Append the source strings onto the destination. + * + * @param source + * The source strings to append. + * @param destination + * The destination strings the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamics_append_all_ + extern f_status_t f_string_dynamics_append_all(const f_string_dynamics_t source, f_string_dynamics_t * const destination); +#endif // _di_f_string_dynamics_append_all_ + +/** + * Resize the dynamic string 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 decimate the size by. + * @param dynamics + * The array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (size == 0) (or amount is 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamics_decimate_by_ + extern f_status_t f_string_dynamics_decimate_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics); +#endif // _di_f_string_dynamics_decimate_by_ + +/** + * Resize the dynamic string 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 dynamics + * The array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (size == 0) (or amount is 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamics_decrease_by_ + extern f_status_t f_string_dynamics_decrease_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics); +#endif // _di_f_string_dynamics_decrease_by_ + +/** + * Increase the size of the dynamic string 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param dynamics + * The array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamics_increase_ + extern f_status_t f_string_dynamics_increase(const f_array_length_t step, f_string_dynamics_t * const dynamics); +#endif // _di_f_string_dynamics_increase_ + +/** + * Resize the dynamic string array to a larger size. + * + * This will resize making the array 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_d). + * 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 dynamics + * The array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamics_increase_by_ + extern f_status_t f_string_dynamics_increase_by(const f_array_length_t amount, f_string_dynamics_t * const dynamics); +#endif // _di_f_string_dynamics_increase_by_ + +/** + * Resize the dynamic string array. + * + * @param length + * The new size to use. + * @param dynamics + * The array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamics_resize_ + extern f_status_t f_string_dynamics_resize(const f_array_length_t length, f_string_dynamics_t * const dynamics); +#endif // _di_f_string_dynamics_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_dynamics_h diff --git a/level_0/f_string/c/string/dynamicss.c b/level_0/f_string/c/string/dynamicss.c new file mode 100644 index 0000000..df3733b --- /dev/null +++ b/level_0/f_string/c/string/dynamicss.c @@ -0,0 +1,168 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-dynamic.h" +#include "private-dynamics.h" +#include "private-dynamicss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_dynamicss_adjust_ + f_status_t f_string_dynamicss_adjust(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamicss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_dynamicss_adjust(length, dynamicss); + } +#endif // _di_f_string_dynamicss_adjust_ + +#ifndef _di_f_string_dynamicss_append_ + f_status_t f_string_dynamicss_append(const f_string_dynamics_t source, f_string_dynamicss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_dynamicss_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].used = 0; + + if (source.used) { + status = private_f_string_dynamics_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_dynamicss_append_ + +#ifndef _di_f_string_dynamicss_append_all_ + f_status_t f_string_dynamicss_append_all(const f_string_dynamicss_t source, f_string_dynamicss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + source.used > destination->size) { + status = private_f_string_dynamicss_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].used = 0; + + if (source.array[i].used) { + status = private_f_string_dynamics_append_all(source.array[i], &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + } // for + + return F_none; + } +#endif // _di_f_string_dynamicss_append_all_ + +#ifndef _di_f_string_dynamicss_decimate_by_ + f_status_t f_string_dynamicss_decimate_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamicss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (dynamicss->size > amount) { + return private_f_string_dynamicss_adjust(dynamicss->size - amount, dynamicss); + } + + return private_f_string_dynamicss_adjust(0, dynamicss); + } +#endif // _di_f_string_dynamicss_decimate_by_ + +#ifndef _di_f_string_dynamicss_decrease_by_ + f_status_t f_string_dynamicss_decrease_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamicss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (dynamicss->size > amount) { + return private_f_string_dynamicss_resize(dynamicss->size - amount, dynamicss); + } + + return private_f_string_dynamicss_resize(0, dynamicss); + } +#endif // _di_f_string_dynamicss_decrease_by_ + +#ifndef _di_f_string_dynamicss_increase_ + f_status_t f_string_dynamicss_increase(const f_array_length_t step, f_string_dynamicss_t * const dynamicss) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamicss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!step) return F_data_not; + + if (dynamicss->used + 1 > dynamicss->size) { + f_array_length_t size = dynamicss->used + step; + + if (size > F_array_length_t_size_d) { + if (dynamicss->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_dynamicss_resize(size, dynamicss); + } + + return F_data_not; + } +#endif // _di_f_string_dynamicss_increase_ + +#ifndef _di_f_string_dynamicss_increase_by_ + f_status_t f_string_dynamicss_increase_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamicss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (dynamicss->used + amount > dynamicss->size) { + if (dynamicss->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_dynamicss_resize(dynamicss->used + amount, dynamicss); + } + + return F_data_not; + } +#endif // _di_f_string_dynamicss_increase_by_ + +#ifndef _di_f_string_dynamicss_resize_ + f_status_t f_string_dynamicss_resize(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) { + #ifndef _di_level_0_parameter_checking_ + if (!dynamicss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_dynamicss_resize(length, dynamicss); + } +#endif // _di_f_string_dynamicss_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/dynamicss.h b/level_0/f_string/c/string/dynamicss.h new file mode 100644 index 0000000..d87e880 --- /dev/null +++ b/level_0/f_string/c/string/dynamicss.h @@ -0,0 +1,230 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines dynamic string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_dynamicss_h +#define _F_string_dynamicss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of dynamic string arrays. + * + * array: The array of dynamic dynamicss. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_string_dynamicss_t_ + typedef f_string_staticss_t f_string_dynamicss_t; + + #define f_string_dynamicss_t_initialize f_string_staticss_t_initialize + + #define macro_f_string_dynamicss_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_dynamicss_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_dynamicss_t_clear(dynamicss) macro_f_string_staticss_t_clear(dynamicss) + + #define macro_f_string_dynamicss_t_resize(status, dynamicss, length) status = f_string_dynamicss_resize(length, &dynamicss); + #define macro_f_string_dynamicss_t_adjust(status, dynamicss, length) status = f_string_dynamicss_adjust(length, &dynamicss); + + #define macro_f_string_dynamicss_t_delete_simple(dynamicss) f_string_dynamicss_resize(0, &dynamicss); + #define macro_f_string_dynamicss_t_destroy_simple(dynamicss) f_string_dynamicss_adjust(0, &dynamicss); + + #define macro_f_string_dynamicss_t_increase(status, step, dynamicss) status = f_string_dynamicss_increase(step, &dynamicss); + #define macro_f_string_dynamicss_t_increase_by(status, dynamicss, amount) status = f_string_dynamicss_increase_by(amount, &dynamicss); + #define macro_f_string_dynamicss_t_decrease_by(status, dynamicss, amount) status = f_string_dynamicss_decrease_by(amount, &dynamicss); + #define macro_f_string_dynamicss_t_decimate_by(status, dynamicss, amount) status = f_string_dynamicss_decimate_by(amount, &dynamicss); +#endif // _di_f_string_dynamicss_t_ + +/** + * Resize the dynamics string array. + * + * @param length + * The new size to use. + * @param dynamicss + * The array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_adjust(). + */ +#ifndef _di_f_string_dynamicss_adjust_ + extern f_status_t f_string_dynamicss_adjust(const f_array_length_t length, f_string_dynamicss_t * const dynamicss); +#endif // _di_f_string_dynamicss_adjust_ + +/** + * Append the single source string onto the destination. + * + * @param source + * The source string to append. + * @param destination + * The destination strings the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamicss_append_ + extern f_status_t f_string_dynamicss_append(const f_string_dynamics_t source, f_string_dynamicss_t * const destination); +#endif // _di_f_string_dynamicss_append_ + +/** + * Append the source strings onto the destination. + * + * @param source + * The source strings to append. + * @param destination + * The destination strings the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamicss_append_all_ + extern f_status_t f_string_dynamicss_append_all(const f_string_dynamicss_t source, f_string_dynamicss_t * const destination); +#endif // _di_f_string_dynamicss_append_all_ + +/** + * Resize the dynamics string 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 decimate the size by. + * @param dynamicss + * The array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (size == 0) (or amount is 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamicss_decimate_by_ + extern f_status_t f_string_dynamicss_decimate_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss); +#endif // _di_f_string_dynamicss_decimate_by_ + +/** + * Resize the dynamics string 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 dynamicss + * The array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (size == 0) (or amount is 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamicss_decrease_by_ + extern f_status_t f_string_dynamicss_decrease_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss); +#endif // _di_f_string_dynamicss_decrease_by_ + +/** + * Increase the size of the dynamics string 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param dynamicss + * The array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamicss_increase_ + extern f_status_t f_string_dynamicss_increase(const f_array_length_t step, f_string_dynamicss_t * const dynamicss); +#endif // _di_f_string_dynamicss_increase_ + +/** + * Resize the dynamics string array to a larger size. + * + * This will resize making the array 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_d). + * 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 dynamicss + * The array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamicss_increase_by_ + extern f_status_t f_string_dynamicss_increase_by(const f_array_length_t amount, f_string_dynamicss_t * const dynamicss); +#endif // _di_f_string_dynamicss_increase_by_ + +/** + * Resize the dynamics string array. + * + * @param length + * The new size to use. + * @param dynamicss + * The array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_dynamicss_resize_ + extern f_status_t f_string_dynamicss_resize(const f_array_length_t length, f_string_dynamicss_t * const dynamicss); +#endif // _di_f_string_dynamicss_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_dynamicss_h diff --git a/level_0/f_string/c/string/map.c b/level_0/f_string/c/string/map.c index 13c89f0..19bfbd9 100644 --- a/level_0/f_string/c/string/map.c +++ b/level_0/f_string/c/string/map.c @@ -1,304 +1,10 @@ #include "../string.h" #include "../private-string.h" -#include "private-map.h" #ifdef __cplusplus extern "C" { #endif -#ifndef _di_f_string_maps_adjust_ - f_status_t f_string_maps_adjust(const f_array_length_t length, f_string_maps_t * const maps) { - #ifndef _di_level_0_parameter_checking_ - if (!maps) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_maps_adjust(length, maps); - } -#endif // _di_f_string_maps_adjust_ - -#ifndef _di_f_string_maps_append_ - f_status_t f_string_maps_append(const f_string_map_t source, f_string_maps_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_maps_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].name.used = 0; - destination->array[destination->used].value.used = 0; - - if (source.name.used) { - status = private_f_string_append(source.name.string, source.name.used, &destination->array[destination->used].name); - if (F_status_is_error(status)) return status; - } - - if (source.value.used) { - status = private_f_string_append(source.value.string, source.value.used, &destination->array[destination->used].value); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // _di_f_string_maps_append_ - -#ifndef _di_f_string_maps_append_all_ - f_status_t f_string_maps_append_all(const f_string_maps_t source, f_string_maps_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - return private_f_string_maps_append_all(source, destination); - } -#endif // _di_f_string_maps_append_all_ - -#ifndef _di_f_string_maps_decimate_by_ - f_status_t f_string_maps_decimate_by(const f_array_length_t amount, f_string_maps_t * const maps) { - #ifndef _di_level_0_parameter_checking_ - if (!maps) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (maps->size > amount) { - return private_f_string_maps_adjust(maps->size - amount, maps); - } - - return private_f_string_maps_adjust(0, maps); - } -#endif // _di_f_string_maps_decimate_by_ - -#ifndef _di_f_string_maps_decrease_by_ - f_status_t f_string_maps_decrease_by(const f_array_length_t amount, f_string_maps_t * const maps) { - #ifndef _di_level_0_parameter_checking_ - if (!maps) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (maps->size > amount) { - return private_f_string_maps_resize(maps->size - amount, maps); - } - - return private_f_string_maps_resize(0, maps); - } -#endif // _di_f_string_maps_decrease_by_ - -#ifndef _di_f_string_maps_increase_ - f_status_t f_string_maps_increase(const f_array_length_t step, f_string_maps_t * const maps) { - #ifndef _di_level_0_parameter_checking_ - if (!maps) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && maps->used + 1 > maps->size) { - f_array_length_t size = maps->used + step; - - if (size > F_array_length_t_size_d) { - if (maps->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_maps_resize(size, maps); - } - - return F_data_not; - } -#endif // _di_f_string_maps_increase_ - -#ifndef _di_f_string_maps_increase_by_ - f_status_t f_string_maps_increase_by(const f_array_length_t amount, f_string_maps_t * const maps) { - #ifndef _di_level_0_parameter_checking_ - if (!maps) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (maps->used + amount > maps->size) { - if (maps->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_maps_resize(maps->used + amount, maps); - } - - return F_data_not; - } -#endif // _di_f_string_maps_increase_by_ - -#ifndef _di_f_string_maps_resize_ - f_status_t f_string_maps_resize(const f_array_length_t length, f_string_maps_t * const maps) { - #ifndef _di_level_0_parameter_checking_ - if (!maps) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_maps_resize(length, maps); - } -#endif // _di_f_string_maps_resize_ - -#ifndef _di_f_string_mapss_adjust_ - f_status_t f_string_mapss_adjust(const f_array_length_t length, f_string_mapss_t * const mapss) { - #ifndef _di_level_0_parameter_checking_ - if (!mapss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_mapss_adjust(length, mapss); - } -#endif // _di_f_string_mapss_adjust_ - -#ifndef _di_f_string_mapss_append_ - f_status_t f_string_mapss_append(const f_string_maps_t source, f_string_mapss_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_mapss_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].used = 0; - - if (source.used) { - status = private_f_string_maps_append_all(source, &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // _di_f_string_mapss_append_ - -#ifndef _di_f_string_mapss_append_all_ - f_status_t f_string_mapss_append_all(const f_string_mapss_t source, f_string_mapss_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_string_mapss_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } - - for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { - - destination->array[destination->used].used = 0; - - if (source.array[i].used) { - status = private_f_string_maps_append_all(source.array[i], &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - } // for - - return F_none; - } -#endif // _di_f_string_mapss_append_all_ - -#ifndef _di_f_string_mapss_decimate_by_ - f_status_t f_string_mapss_decimate_by(const f_array_length_t amount, f_string_mapss_t * const mapss) { - #ifndef _di_level_0_parameter_checking_ - if (!mapss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (mapss->size > amount) { - return private_f_string_mapss_adjust(mapss->size - amount, mapss); - } - - return private_f_string_mapss_adjust(0, mapss); - } -#endif // _di_f_string_mapss_decimate_by_ - -#ifndef _di_f_string_mapss_decrease_by_ - f_status_t f_string_mapss_decrease_by(const f_array_length_t amount, f_string_mapss_t * const mapss) { - #ifndef _di_level_0_parameter_checking_ - if (!mapss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (mapss->size > amount) { - return private_f_string_mapss_resize(mapss->size - amount, mapss); - } - - return private_f_string_mapss_resize(0, mapss); - } -#endif // _di_f_string_mapss_decrease_by_ - -#ifndef _di_f_string_mapss_increase_ - f_status_t f_string_mapss_increase(const f_array_length_t step, f_string_mapss_t * const mapss) { - #ifndef _di_level_0_parameter_checking_ - if (!mapss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && mapss->used + 1 > mapss->size) { - f_array_length_t size = mapss->used + step; - - if (size > F_array_length_t_size_d) { - if (mapss->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_mapss_resize(size, mapss); - } - - return F_data_not; - } -#endif // _di_f_string_mapss_increase_ - -#ifndef _di_f_string_mapss_increase_by_ - f_status_t f_string_mapss_increase_by(const f_array_length_t amount, f_string_mapss_t * const mapss) { - #ifndef _di_level_0_parameter_checking_ - if (!mapss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (mapss->used + amount > mapss->size) { - if (mapss->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_mapss_resize(mapss->used + amount, mapss); - } - - return F_data_not; - } -#endif // _di_f_string_mapss_increase_by_ - -#ifndef _di_f_string_mapss_resize_ - f_status_t f_string_mapss_resize(const f_array_length_t length, f_string_mapss_t * const mapss) { - #ifndef _di_level_0_parameter_checking_ - if (!mapss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_mapss_resize(length, mapss); - } -#endif // _di_f_string_mapss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/map.h b/level_0/f_string/c/string/map.h index b1d856e..a63a7fb 100644 --- a/level_0/f_string/c/string/map.h +++ b/level_0/f_string/c/string/map.h @@ -45,427 +45,6 @@ extern "C" { macro_f_string_dynamic_t_destroy_simple(map.value) #endif // _di_f_string_map_t_ -/** - * An array of string maps. - * - * array: the array of string maps. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_maps_t_ - typedef struct { - f_string_map_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_maps_t; - - #define f_string_maps_t_initialize f_string_statics_t_initialize - - #define macro_f_string_maps_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_maps_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_maps_t_clear(maps) macro_f_memory_structure_clear(maps) - - #define macro_f_string_maps_t_resize(status, maps, length) status = f_string_maps_resize(length, &maps); - #define macro_f_string_maps_t_adjust(status, maps, length) status = f_string_maps_adjust(length, &maps); - - #define macro_f_string_maps_t_delete_simple(maps) f_string_maps_resize(0, &maps); - #define macro_f_string_maps_t_destroy_simple(maps) f_string_maps_adjust(0, &maps); - - #define macro_f_string_maps_t_increase(status, step, maps) status = f_string_maps_increase(step, maps); - #define macro_f_string_maps_t_increase_by(status, maps, amount) status = f_string_maps_increase_by(amount, maps); - #define macro_f_string_maps_t_decrease_by(status, maps, amount) status = f_string_maps_decrease_by(amount, maps); - #define macro_f_string_maps_t_decimate_by(status, maps, amount) status = f_string_maps_decimate_by(amount, maps); -#endif // _di_f_string_maps_t_ - -/** - * An array of string maps. - * - * array: the array of an array of string maps. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_mapss_t_ - typedef struct { - f_string_maps_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_mapss_t; - - #define f_string_mapss_t_initialize f_string_statics_t_initialize - - #define macro_f_string_mapss_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_mapss_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_mapss_t_clear(maps) macro_f_memory_structure_clear(maps) - - #define macro_f_string_mapss_t_resize(status, maps, length) status = f_string_mapss_resize(length, &maps); - #define macro_f_string_mapss_t_adjust(status, maps, length) status = f_string_mapss_adjust(length, &maps); - - #define macro_f_string_mapss_t_delete_simple(maps) f_string_mapss_resize(0, &maps); - #define macro_f_string_mapss_t_destroy_simple(maps) f_string_mapss_adjust(0, &maps); - - #define macro_f_string_mapss_t_increase(status, step, maps) status = f_string_mapss_increase(step, maps); - #define macro_f_string_mapss_t_increase_by(status, maps, amount) status = f_string_mapss_increase_by(amount, maps); - #define macro_f_string_mapss_t_decrease_by(status, maps, amount) status = f_string_mapss_decrease_by(amount, maps); - #define macro_f_string_mapss_t_decimate_by(status, maps, amount) status = f_string_mapss_decimate_by(amount, maps); -#endif // _di_f_string_mapss_t_ - -/** - * Resize the string maps array. - * - * @param length - * The new size to use. - * @param maps - * The string maps array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_maps_adjust_ - extern f_status_t f_string_maps_adjust(const f_array_length_t length, f_string_maps_t * const maps); -#endif // _di_f_string_maps_adjust_ - -/** - * Append a single source map onto the destination. - * - * @param source - * The source maps to append. - * @param destination - * The destination maps the source is appended onto. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_maps_append_ - extern f_status_t f_string_maps_append(const f_string_map_t source, f_string_maps_t * const destination); -#endif // _di_f_string_maps_append_ - -/** - * Append the source maps onto the destination. - * - * @param source - * The source maps to append. - * @param destination - * The destination maps the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_maps_append_all_ - extern f_status_t f_string_maps_append_all(const f_string_maps_t source, f_string_maps_t * const destination); -#endif // _di_f_string_maps_append_all_ - -/** - * 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 decimate the size by. - * @param maps - * The string maps array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_maps_decimate_by_ - extern f_status_t f_string_maps_decimate_by(const f_array_length_t amount, f_string_maps_t * const maps); -#endif // _di_f_string_maps_decimate_by_ - -/** - * 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_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_maps_decrease_by_ - extern f_status_t f_string_maps_decrease_by(const f_array_length_t amount, f_string_maps_t * const maps); -#endif // _di_f_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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param maps - * The string maps array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_maps_increase_ - extern f_status_t f_string_maps_increase(const f_array_length_t step, f_string_maps_t * const maps); -#endif // _di_f_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_d). - * 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_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_maps_increase_by_ - extern f_status_t f_string_maps_increase_by(const f_array_length_t amount, f_string_maps_t * const maps); -#endif // _di_f_string_maps_increase_by_ - -/** - * Resize the string maps array. - * - * @param length - * The new size to use. - * @param maps - * The string maps array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_maps_resize_ - extern f_status_t f_string_maps_resize(const f_array_length_t length, f_string_maps_t * const maps); -#endif // _di_f_string_maps_resize_ - -/** - * Resize the string mapss array. - * - * @param length - * The new size to use. - * @param mapss - * The string mapss array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_mapss_adjust_ - extern f_status_t f_string_mapss_adjust(const f_array_length_t length, f_string_mapss_t * const mapss); -#endif // _di_f_string_mapss_adjust_ - -/** - * Append a single source maps onto the destination. - * - * @param source - * The source mapss to append. - * @param destination - * The destination mapss the source is appended onto. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_mapss_append_ - extern f_status_t f_string_mapss_append(const f_string_maps_t source, f_string_mapss_t * const destination); -#endif // _di_f_string_mapss_append_ - -/** - * Append the source mapss onto the destination. - * - * @param source - * The source mapss to append. - * @param destination - * The destination mapss the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_mapss_append_all_ - extern f_status_t f_string_mapss_append_all(const f_string_mapss_t source, f_string_mapss_t * const destination); -#endif // _di_f_string_mapss_append_all_ - -/** - * Resize the string mapss 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 decimate the size by. - * @param mapss - * The string mapss array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_mapss_decimate_by_ - extern f_status_t f_string_mapss_decimate_by(const f_array_length_t amount, f_string_mapss_t * const mapss); -#endif // _di_f_string_mapss_decimate_by_ - -/** - * Resize the string mapss 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 mapss - * The string mapss array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_mapss_decrease_by_ - extern f_status_t f_string_mapss_decrease_by(const f_array_length_t amount, f_string_mapss_t * const mapss); -#endif // _di_f_string_mapss_decrease_by_ - -/** - * Increase the size of the string mapss 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param mapss - * The string mapss array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size) (or step is 0). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_mapss_increase_ - extern f_status_t f_string_mapss_increase(const f_array_length_t step, f_string_mapss_t * const mapss); -#endif // _di_f_string_mapss_increase_ - -/** - * Resize the string mapss 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_d). - * 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 mapss - * The string mapss array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_mapss_increase_by_ - extern f_status_t f_string_mapss_increase_by(const f_array_length_t amount, f_string_mapss_t * const mapss); -#endif // _di_f_string_mapss_increase_by_ - -/** - * Resize the string mapss array. - * - * @param length - * The new size to use. - * @param mapss - * The string mapss array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_mapss_resize_ - extern f_status_t f_string_mapss_resize(const f_array_length_t length, f_string_mapss_t * const mapss); -#endif // _di_f_string_mapss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/map_multi.c b/level_0/f_string/c/string/map_multi.c index 67d7de5..b947a17 100644 --- a/level_0/f_string/c/string/map_multi.c +++ b/level_0/f_string/c/string/map_multi.c @@ -1,305 +1,11 @@ #include "../string.h" #include "../private-string.h" #include "private-dynamic.h" -#include "private-map_multi.h" #ifdef __cplusplus extern "C" { #endif -#ifndef _di_f_string_map_multis_adjust_ - f_status_t f_string_map_multis_adjust(const f_array_length_t length, f_string_map_multis_t * const map_multis) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multis) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_map_multis_adjust(length, map_multis); - } -#endif // _di_f_string_map_multis_adjust_ - -#ifndef _di_f_string_map_multis_append_ - f_status_t f_string_map_multis_append(const f_string_map_multi_t source, f_string_map_multis_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_map_multis_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].name.used = 0; - destination->array[destination->used].value.used = 0; - - if (source.name.used) { - status = private_f_string_append(source.name.string, source.name.used, &destination->array[destination->used].name); - if (F_status_is_error(status)) return status; - } - - if (source.value.used) { - status = private_f_string_dynamics_append_all(source.value, &destination->array[destination->used].value); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // _di_f_string_map_multis_append_ - -#ifndef _di_f_string_map_multis_append_all_ - f_status_t f_string_map_multis_append_all(const f_string_map_multis_t source, f_string_map_multis_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - return private_f_string_map_multis_append_all(source, destination); - } -#endif // _di_f_string_map_multis_append_all_ - -#ifndef _di_f_string_map_multis_decimate_by_ - f_status_t f_string_map_multis_decimate_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multis) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (map_multis->size > amount) { - return private_f_string_map_multis_adjust(map_multis->size - amount, map_multis); - } - - return private_f_string_map_multis_adjust(0, map_multis); - } -#endif // _di_f_string_map_multis_decimate_by_ - -#ifndef _di_f_string_map_multis_decrease_by_ - f_status_t f_string_map_multis_decrease_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multis) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (map_multis->size > amount) { - return private_f_string_map_multis_resize(map_multis->size - amount, map_multis); - } - - return private_f_string_map_multis_resize(0, map_multis); - } -#endif // _di_f_string_map_multis_decrease_by_ - -#ifndef _di_f_string_map_multis_increase_ - f_status_t f_string_map_multis_increase(const f_array_length_t step, f_string_map_multis_t * const map_multis) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multis) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && map_multis->used + 1 > map_multis->size) { - f_array_length_t size = map_multis->used + step; - - if (size > F_array_length_t_size_d) { - if (map_multis->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_map_multis_resize(size, map_multis); - } - - return F_data_not; - } -#endif // _di_f_string_map_multis_increase_ - -#ifndef _di_f_string_map_multis_increase_by_ - f_status_t f_string_map_multis_increase_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multis) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (map_multis->used + amount > map_multis->size) { - if (map_multis->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_map_multis_resize(map_multis->used + amount, map_multis); - } - - return F_data_not; - } -#endif // _di_f_string_map_multis_increase_by_ - -#ifndef _di_f_string_map_multis_resize_ - f_status_t f_string_map_multis_resize(const f_array_length_t length, f_string_map_multis_t * const map_multis) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multis) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_map_multis_resize(length, map_multis); - } -#endif // _di_f_string_map_multis_resize_ - -#ifndef _di_f_string_map_multiss_adjust_ - f_status_t f_string_map_multiss_adjust(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multiss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_map_multiss_adjust(length, map_multiss); - } -#endif // _di_f_string_map_multiss_adjust_ - -#ifndef _di_f_string_map_multiss_append_ - f_status_t f_string_map_multiss_append(const f_string_map_multis_t source, f_string_map_multiss_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_map_multiss_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].used = 0; - - if (source.used) { - status = private_f_string_map_multis_append_all(source, &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // _di_f_string_map_multiss_append_ - -#ifndef _di_f_string_map_multiss_append_all_ - f_status_t f_string_map_multiss_append_all(const f_string_map_multiss_t source, f_string_map_multiss_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_string_map_multiss_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } - - for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { - - destination->array[destination->used].used = 0; - - if (source.array[i].used) { - status = private_f_string_map_multis_append_all(source.array[i], &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - } // for - - return F_none; - } -#endif // _di_f_string_map_multiss_append_all_ - -#ifndef _di_f_string_map_multiss_decimate_by_ - f_status_t f_string_map_multiss_decimate_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multiss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (map_multiss->size > amount) { - return private_f_string_map_multiss_adjust(map_multiss->size - amount, map_multiss); - } - - return private_f_string_map_multiss_adjust(0, map_multiss); - } -#endif // _di_f_string_map_multiss_decimate_by_ - -#ifndef _di_f_string_map_multiss_decrease_by_ - f_status_t f_string_map_multiss_decrease_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multiss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (map_multiss->size > amount) { - return private_f_string_map_multiss_resize(map_multiss->size - amount, map_multiss); - } - - return private_f_string_map_multiss_resize(0, map_multiss); - } -#endif // _di_f_string_map_multiss_decrease_by_ - -#ifndef _di_f_string_map_multiss_increase_ - f_status_t f_string_map_multiss_increase(const f_array_length_t step, f_string_map_multiss_t * const map_multiss) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multiss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && map_multiss->used + 1 > map_multiss->size) { - f_array_length_t size = map_multiss->used + step; - - if (size > F_array_length_t_size_d) { - if (map_multiss->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_map_multiss_resize(size, map_multiss); - } - - return F_data_not; - } -#endif // _di_f_string_map_multiss_increase_ - -#ifndef _di_f_string_map_multiss_increase_by_ - f_status_t f_string_map_multiss_increase_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multiss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (map_multiss->used + amount > map_multiss->size) { - if (map_multiss->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_map_multiss_resize(map_multiss->used + amount, map_multiss); - } - - return F_data_not; - } -#endif // _di_f_string_map_multiss_increase_by_ - -#ifndef _di_f_string_map_multiss_resize_ - f_status_t f_string_map_multiss_resize(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) { - #ifndef _di_level_0_parameter_checking_ - if (!map_multiss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_map_multiss_resize(length, map_multiss); - } -#endif // _di_f_string_map_multiss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/map_multi.h b/level_0/f_string/c/string/map_multi.h index a0b3ec6..2fa93d8 100644 --- a/level_0/f_string/c/string/map_multi.h +++ b/level_0/f_string/c/string/map_multi.h @@ -45,426 +45,6 @@ extern "C" { macro_f_string_dynamics_t_destroy_simple(map.value) #endif // _di_f_string_map_multi_t_ -/** - * An array of string maps. - * - * array: the array of string maps. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_map_multis_t_ - typedef struct { - f_string_map_multi_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_map_multis_t; - - #define f_string_map_multis_t_initialize f_string_statics_t_initialize - - #define macro_f_string_map_multis_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_map_multis_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_map_multis_t_clear(map_multis) macro_f_memory_structure_clear(map_multis) - - #define macro_f_string_map_multis_t_resize(status, map_multis, length) status = f_string_map_multis_resize(length, &map_multis); - #define macro_f_string_map_multis_t_adjust(status, map_multis, length) status = f_string_map_multis_adjust(length, &map_multis); - - #define macro_f_string_map_multis_t_delete_simple(map_multis) f_string_map_multis_resize(0, &map_multis); - #define macro_f_string_map_multis_t_destroy_simple(map_multis) f_string_map_multis_adjust(0, &map_multis); - - #define macro_f_string_map_multis_t_increase(status, step, map_multis) status = f_string_map_multis_increase(step, &map_multis); - #define macro_f_string_map_multis_t_increase_by(status, map_multis, amount) status = f_string_map_multis_increase_by(amount, &map_multis); - #define macro_f_string_map_multis_t_decrease_by(status, map_multis, amount) status = f_string_map_multis_decrease_by(amount, &map_multis); - #define macro_f_string_map_multis_t_decimate_by(status, map_multis, amount) status = f_string_map_multis_decimate_by(amount, &map_multis); -#endif // _di_f_string_map_multis_t_ - -/** - * An array of string maps. - * - * array: the array of an array of string maps. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_map_multiss_t_ - typedef struct { - f_string_map_multis_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_map_multiss_t; - - #define f_string_map_multiss_t_initialize f_string_statics_t_initialize - - #define macro_f_string_map_multiss_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_map_multiss_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_map_multiss_t_clear(map_multis) macro_f_memory_structure_clear(map_multis) - - #define macro_f_string_map_multiss_t_resize(status, map_multis, length) status = f_string_map_multiss_resize(length, &map_multis); - #define macro_f_string_map_multiss_t_adjust(status, map_multis, length) status = f_string_map_multiss_adjust(length, &map_multis); - - #define macro_f_string_map_multiss_t_delete_simple(map_multis) f_string_map_multiss_resize(0, &map_multis); - #define macro_f_string_map_multiss_t_destroy_simple(map_multis) f_string_map_multiss_adjust(0, &map_multis); - - #define macro_f_string_map_multiss_t_increase(status, step, map_multis) status = f_string_map_multiss_increase(step, &map_multis); - #define macro_f_string_map_multiss_t_increase_by(status, map_multis, amount) status = f_string_map_multiss_increase_by(amount, &map_multis); - #define macro_f_string_map_multiss_t_decrease_by(status, map_multis, amount) status = f_string_map_multiss_decrease_by(amount, &map_multis); - #define macro_f_string_map_multiss_t_decimate_by(status, map_multis, amount) status = f_string_map_multiss_decimate_by(amount, &map_multis); -#endif // _di_f_string_map_multiss_t_ - -/** - * Resize the map_multis array. - * - * @param length - * The new size to use. - * @param map_multis - * The map_multis array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multis_adjust_ - extern f_status_t f_string_map_multis_adjust(const f_array_length_t length, f_string_map_multis_t * const map_multis); -#endif // _di_f_string_map_multis_adjust_ - -/** - * Append a single source map_multi onto the destination. - * - * @param source - * The source maps to append. - * @param destination - * The destination maps the source is appended onto. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multis_append_ - f_status_t f_string_map_multis_append(const f_string_map_multi_t source, f_string_map_multis_t *destination); -#endif // _di_f_string_map_multis_append_ - -/** - * Append the source map_multis onto the destination. - * - * @param source - * The source maps to append. - * @param destination - * The destination maps the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multis_append_all_ - f_status_t f_string_map_multis_append_all(const f_string_map_multis_t source, f_string_map_multis_t *destination); -#endif // _di_f_string_map_multis_append_all_ - -/** - * Resize the map_multis 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 decimate the size by. - * @param map_multis - * The map_multis array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multis_decimate_by_ - extern f_status_t f_string_map_multis_decimate_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis); -#endif // _di_f_string_map_multis_decimate_by_ - -/** - * Resize the map_multis 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 map_multis - * The map_multis array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multis_decrease_by_ - extern f_status_t f_string_map_multis_decrease_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis); -#endif // _di_f_string_map_multis_decrease_by_ - -/** - * Increase the size of the map_multis 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param map_multis - * The map_multis array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multis_increase_ - extern f_status_t f_string_map_multis_increase(const f_array_length_t step, f_string_map_multis_t * const map_multis); -#endif // _di_f_string_map_multis_increase_ - -/** - * Resize the map_multis 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_d). - * 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 map_multis - * The map_multis array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multis_increase_by_ - extern f_status_t f_string_map_multis_increase_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis); -#endif // _di_f_string_map_multis_increase_by_ - -/** - * Resize the map_multis array. - * - * @param length - * The new size to use. - * @param map_multis - * The map_multis array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multis_resize_ - extern f_status_t f_string_map_multis_resize(const f_array_length_t length, f_string_map_multis_t * const map_multis); -#endif // _di_f_string_map_multis_resize_ - -/** - * Resize the map_multiss array. - * - * @param length - * The new size to use. - * @param map_multiss - * The map_multiss array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multiss_adjust_ - extern f_status_t f_string_map_multiss_adjust(const f_array_length_t length, f_string_map_multiss_t * const map_multiss); -#endif // _di_f_string_map_multiss_adjust_ - -/** - * Append a single source map_multis onto the destination. - * - * @param source - * The source maps to append. - * @param destination - * The destination maps the source is appended onto. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multiss_append_ - f_status_t f_string_map_multiss_append(const f_string_map_multis_t source, f_string_map_multiss_t *destination); -#endif // _di_f_string_map_multiss_append_ - -/** - * Append the source map_multiss onto the destination. - * - * @param source - * The source maps to append. - * @param destination - * The destination maps the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multiss_append_all_ - f_status_t f_string_map_multiss_append_all(const f_string_map_multiss_t source, f_string_map_multiss_t *destination); -#endif // _di_f_string_map_multiss_append_all_ - -/** - * Resize the map_multiss 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 decimate the size by. - * @param map_multiss - * The map_multiss array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multiss_decimate_by_ - extern f_status_t f_string_map_multiss_decimate_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss); -#endif // _di_f_string_map_multiss_decimate_by_ - -/** - * Resize the map_multiss 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 map_multiss - * The map_multiss array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multiss_decrease_by_ - extern f_status_t f_string_map_multiss_decrease_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss); -#endif // _di_f_string_map_multiss_decrease_by_ - -/** - * Increase the size of the map_multiss 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param map_multiss - * The map_multiss array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multiss_increase_ - extern f_status_t f_string_map_multiss_increase(const f_array_length_t step, f_string_map_multiss_t * const map_multiss); -#endif // _di_f_string_map_multiss_increase_ - -/** - * Resize the map_multiss 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_d). - * 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 map_multiss - * The map_multiss array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multiss_increase_by_ - extern f_status_t f_string_map_multiss_increase_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss); -#endif // _di_f_string_map_multiss_increase_by_ - -/** - * Resize the map_multiss array. - * - * @param length - * The new size to use. - * @param map_multiss - * The map_multiss array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_map_multiss_resize_ - extern f_status_t f_string_map_multiss_resize(const f_array_length_t length, f_string_map_multiss_t * const map_multiss); -#endif // _di_f_string_map_multiss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/map_multis.c b/level_0/f_string/c/string/map_multis.c new file mode 100644 index 0000000..8144836 --- /dev/null +++ b/level_0/f_string/c/string/map_multis.c @@ -0,0 +1,153 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-dynamic.h" +#include "private-dynamics.h" +#include "private-map_multis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_map_multis_adjust_ + f_status_t f_string_map_multis_adjust(const f_array_length_t length, f_string_map_multis_t * const map_multis) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multis) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_map_multis_adjust(length, map_multis); + } +#endif // _di_f_string_map_multis_adjust_ + +#ifndef _di_f_string_map_multis_append_ + f_status_t f_string_map_multis_append(const f_string_map_multi_t source, f_string_map_multis_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_map_multis_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].name.used = 0; + destination->array[destination->used].value.used = 0; + + if (source.name.used) { + status = private_f_string_append(source.name.string, source.name.used, &destination->array[destination->used].name); + if (F_status_is_error(status)) return status; + } + + if (source.value.used) { + status = private_f_string_dynamics_append_all(source.value, &destination->array[destination->used].value); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_map_multis_append_ + +#ifndef _di_f_string_map_multis_append_all_ + f_status_t f_string_map_multis_append_all(const f_string_map_multis_t source, f_string_map_multis_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + return private_f_string_map_multis_append_all(source, destination); + } +#endif // _di_f_string_map_multis_append_all_ + +#ifndef _di_f_string_map_multis_decimate_by_ + f_status_t f_string_map_multis_decimate_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multis) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (map_multis->size > amount) { + return private_f_string_map_multis_adjust(map_multis->size - amount, map_multis); + } + + return private_f_string_map_multis_adjust(0, map_multis); + } +#endif // _di_f_string_map_multis_decimate_by_ + +#ifndef _di_f_string_map_multis_decrease_by_ + f_status_t f_string_map_multis_decrease_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multis) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (map_multis->size > amount) { + return private_f_string_map_multis_resize(map_multis->size - amount, map_multis); + } + + return private_f_string_map_multis_resize(0, map_multis); + } +#endif // _di_f_string_map_multis_decrease_by_ + +#ifndef _di_f_string_map_multis_increase_ + f_status_t f_string_map_multis_increase(const f_array_length_t step, f_string_map_multis_t * const map_multis) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multis) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && map_multis->used + 1 > map_multis->size) { + f_array_length_t size = map_multis->used + step; + + if (size > F_array_length_t_size_d) { + if (map_multis->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_map_multis_resize(size, map_multis); + } + + return F_data_not; + } +#endif // _di_f_string_map_multis_increase_ + +#ifndef _di_f_string_map_multis_increase_by_ + f_status_t f_string_map_multis_increase_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multis) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (map_multis->used + amount > map_multis->size) { + if (map_multis->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_map_multis_resize(map_multis->used + amount, map_multis); + } + + return F_data_not; + } +#endif // _di_f_string_map_multis_increase_by_ + +#ifndef _di_f_string_map_multis_resize_ + f_status_t f_string_map_multis_resize(const f_array_length_t length, f_string_map_multis_t * const map_multis) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multis) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_map_multis_resize(length, map_multis); + } +#endif // _di_f_string_map_multis_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/map_multis.h b/level_0/f_string/c/string/map_multis.h new file mode 100644 index 0000000..9270605 --- /dev/null +++ b/level_0/f_string/c/string/map_multis.h @@ -0,0 +1,233 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines map string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_map_multis_h +#define _F_string_map_multis_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of string maps. + * + * array: the array of string maps. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_map_multis_t_ + typedef struct { + f_string_map_multi_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_map_multis_t; + + #define f_string_map_multis_t_initialize f_string_statics_t_initialize + + #define macro_f_string_map_multis_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_map_multis_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_map_multis_t_clear(map_multis) macro_f_memory_structure_clear(map_multis) + + #define macro_f_string_map_multis_t_resize(status, map_multis, length) status = f_string_map_multis_resize(length, &map_multis); + #define macro_f_string_map_multis_t_adjust(status, map_multis, length) status = f_string_map_multis_adjust(length, &map_multis); + + #define macro_f_string_map_multis_t_delete_simple(map_multis) f_string_map_multis_resize(0, &map_multis); + #define macro_f_string_map_multis_t_destroy_simple(map_multis) f_string_map_multis_adjust(0, &map_multis); + + #define macro_f_string_map_multis_t_increase(status, step, map_multis) status = f_string_map_multis_increase(step, &map_multis); + #define macro_f_string_map_multis_t_increase_by(status, map_multis, amount) status = f_string_map_multis_increase_by(amount, &map_multis); + #define macro_f_string_map_multis_t_decrease_by(status, map_multis, amount) status = f_string_map_multis_decrease_by(amount, &map_multis); + #define macro_f_string_map_multis_t_decimate_by(status, map_multis, amount) status = f_string_map_multis_decimate_by(amount, &map_multis); +#endif // _di_f_string_map_multis_t_ + +/** + * Resize the map_multis array. + * + * @param length + * The new size to use. + * @param map_multis + * The map_multis array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multis_adjust_ + extern f_status_t f_string_map_multis_adjust(const f_array_length_t length, f_string_map_multis_t * const map_multis); +#endif // _di_f_string_map_multis_adjust_ + +/** + * Append a single source map_multi onto the destination. + * + * @param source + * The source maps to append. + * @param destination + * The destination maps the source is appended onto. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multis_append_ + f_status_t f_string_map_multis_append(const f_string_map_multi_t source, f_string_map_multis_t *destination); +#endif // _di_f_string_map_multis_append_ + +/** + * Append the source map_multis onto the destination. + * + * @param source + * The source maps to append. + * @param destination + * The destination maps the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multis_append_all_ + f_status_t f_string_map_multis_append_all(const f_string_map_multis_t source, f_string_map_multis_t *destination); +#endif // _di_f_string_map_multis_append_all_ + +/** + * Resize the map_multis 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 decimate the size by. + * @param map_multis + * The map_multis array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multis_decimate_by_ + extern f_status_t f_string_map_multis_decimate_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis); +#endif // _di_f_string_map_multis_decimate_by_ + +/** + * Resize the map_multis 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 map_multis + * The map_multis array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multis_decrease_by_ + extern f_status_t f_string_map_multis_decrease_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis); +#endif // _di_f_string_map_multis_decrease_by_ + +/** + * Increase the size of the map_multis 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param map_multis + * The map_multis array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multis_increase_ + extern f_status_t f_string_map_multis_increase(const f_array_length_t step, f_string_map_multis_t * const map_multis); +#endif // _di_f_string_map_multis_increase_ + +/** + * Resize the map_multis 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_d). + * 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 map_multis + * The map_multis array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multis_increase_by_ + extern f_status_t f_string_map_multis_increase_by(const f_array_length_t amount, f_string_map_multis_t * const map_multis); +#endif // _di_f_string_map_multis_increase_by_ + +/** + * Resize the map_multis array. + * + * @param length + * The new size to use. + * @param map_multis + * The map_multis array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multis_resize_ + extern f_status_t f_string_map_multis_resize(const f_array_length_t length, f_string_map_multis_t * const map_multis); +#endif // _di_f_string_map_multis_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_map_multis_h diff --git a/level_0/f_string/c/string/map_multiss.c b/level_0/f_string/c/string/map_multiss.c new file mode 100644 index 0000000..6aff10d --- /dev/null +++ b/level_0/f_string/c/string/map_multiss.c @@ -0,0 +1,167 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-dynamic.h" +#include "private-dynamics.h" +#include "private-map_multis.h" +#include "private-map_multiss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_map_multiss_adjust_ + f_status_t f_string_map_multiss_adjust(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multiss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_map_multiss_adjust(length, map_multiss); + } +#endif // _di_f_string_map_multiss_adjust_ + +#ifndef _di_f_string_map_multiss_append_ + f_status_t f_string_map_multiss_append(const f_string_map_multis_t source, f_string_map_multiss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_map_multiss_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].used = 0; + + if (source.used) { + status = private_f_string_map_multis_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_map_multiss_append_ + +#ifndef _di_f_string_map_multiss_append_all_ + f_status_t f_string_map_multiss_append_all(const f_string_map_multiss_t source, f_string_map_multiss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + source.used > destination->size) { + status = private_f_string_map_multiss_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].used = 0; + + if (source.array[i].used) { + status = private_f_string_map_multis_append_all(source.array[i], &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + } // for + + return F_none; + } +#endif // _di_f_string_map_multiss_append_all_ + +#ifndef _di_f_string_map_multiss_decimate_by_ + f_status_t f_string_map_multiss_decimate_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multiss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (map_multiss->size > amount) { + return private_f_string_map_multiss_adjust(map_multiss->size - amount, map_multiss); + } + + return private_f_string_map_multiss_adjust(0, map_multiss); + } +#endif // _di_f_string_map_multiss_decimate_by_ + +#ifndef _di_f_string_map_multiss_decrease_by_ + f_status_t f_string_map_multiss_decrease_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multiss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (map_multiss->size > amount) { + return private_f_string_map_multiss_resize(map_multiss->size - amount, map_multiss); + } + + return private_f_string_map_multiss_resize(0, map_multiss); + } +#endif // _di_f_string_map_multiss_decrease_by_ + +#ifndef _di_f_string_map_multiss_increase_ + f_status_t f_string_map_multiss_increase(const f_array_length_t step, f_string_map_multiss_t * const map_multiss) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multiss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && map_multiss->used + 1 > map_multiss->size) { + f_array_length_t size = map_multiss->used + step; + + if (size > F_array_length_t_size_d) { + if (map_multiss->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_map_multiss_resize(size, map_multiss); + } + + return F_data_not; + } +#endif // _di_f_string_map_multiss_increase_ + +#ifndef _di_f_string_map_multiss_increase_by_ + f_status_t f_string_map_multiss_increase_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multiss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (map_multiss->used + amount > map_multiss->size) { + if (map_multiss->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_map_multiss_resize(map_multiss->used + amount, map_multiss); + } + + return F_data_not; + } +#endif // _di_f_string_map_multiss_increase_by_ + +#ifndef _di_f_string_map_multiss_resize_ + f_status_t f_string_map_multiss_resize(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) { + #ifndef _di_level_0_parameter_checking_ + if (!map_multiss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_map_multiss_resize(length, map_multiss); + } +#endif // _di_f_string_map_multiss_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/map_multiss.h b/level_0/f_string/c/string/map_multiss.h new file mode 100644 index 0000000..c6d4ca6 --- /dev/null +++ b/level_0/f_string/c/string/map_multiss.h @@ -0,0 +1,233 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines map string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_map_multiss_h +#define _F_string_map_multiss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of string maps arrays. + * + * array: the array of an array of string maps. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_map_multiss_t_ + typedef struct { + f_string_map_multis_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_map_multiss_t; + + #define f_string_map_multiss_t_initialize f_string_statics_t_initialize + + #define macro_f_string_map_multiss_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_map_multiss_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_map_multiss_t_clear(map_multis) macro_f_memory_structure_clear(map_multis) + + #define macro_f_string_map_multiss_t_resize(status, map_multis, length) status = f_string_map_multiss_resize(length, &map_multis); + #define macro_f_string_map_multiss_t_adjust(status, map_multis, length) status = f_string_map_multiss_adjust(length, &map_multis); + + #define macro_f_string_map_multiss_t_delete_simple(map_multis) f_string_map_multiss_resize(0, &map_multis); + #define macro_f_string_map_multiss_t_destroy_simple(map_multis) f_string_map_multiss_adjust(0, &map_multis); + + #define macro_f_string_map_multiss_t_increase(status, step, map_multis) status = f_string_map_multiss_increase(step, &map_multis); + #define macro_f_string_map_multiss_t_increase_by(status, map_multis, amount) status = f_string_map_multiss_increase_by(amount, &map_multis); + #define macro_f_string_map_multiss_t_decrease_by(status, map_multis, amount) status = f_string_map_multiss_decrease_by(amount, &map_multis); + #define macro_f_string_map_multiss_t_decimate_by(status, map_multis, amount) status = f_string_map_multiss_decimate_by(amount, &map_multis); +#endif // _di_f_string_map_multiss_t_ + +/** + * Resize the map_multiss array. + * + * @param length + * The new size to use. + * @param map_multiss + * The map_multiss array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multiss_adjust_ + extern f_status_t f_string_map_multiss_adjust(const f_array_length_t length, f_string_map_multiss_t * const map_multiss); +#endif // _di_f_string_map_multiss_adjust_ + +/** + * Append a single source map_multis onto the destination. + * + * @param source + * The source maps to append. + * @param destination + * The destination maps the source is appended onto. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multiss_append_ + f_status_t f_string_map_multiss_append(const f_string_map_multis_t source, f_string_map_multiss_t *destination); +#endif // _di_f_string_map_multiss_append_ + +/** + * Append the source map_multiss onto the destination. + * + * @param source + * The source maps to append. + * @param destination + * The destination maps the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multiss_append_all_ + f_status_t f_string_map_multiss_append_all(const f_string_map_multiss_t source, f_string_map_multiss_t *destination); +#endif // _di_f_string_map_multiss_append_all_ + +/** + * Resize the map_multiss 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 decimate the size by. + * @param map_multiss + * The map_multiss array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multiss_decimate_by_ + extern f_status_t f_string_map_multiss_decimate_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss); +#endif // _di_f_string_map_multiss_decimate_by_ + +/** + * Resize the map_multiss 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 map_multiss + * The map_multiss array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multiss_decrease_by_ + extern f_status_t f_string_map_multiss_decrease_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss); +#endif // _di_f_string_map_multiss_decrease_by_ + +/** + * Increase the size of the map_multiss 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param map_multiss + * The map_multiss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multiss_increase_ + extern f_status_t f_string_map_multiss_increase(const f_array_length_t step, f_string_map_multiss_t * const map_multiss); +#endif // _di_f_string_map_multiss_increase_ + +/** + * Resize the map_multiss 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_d). + * 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 map_multiss + * The map_multiss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multiss_increase_by_ + extern f_status_t f_string_map_multiss_increase_by(const f_array_length_t amount, f_string_map_multiss_t * const map_multiss); +#endif // _di_f_string_map_multiss_increase_by_ + +/** + * Resize the map_multiss array. + * + * @param length + * The new size to use. + * @param map_multiss + * The map_multiss array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_map_multiss_resize_ + extern f_status_t f_string_map_multiss_resize(const f_array_length_t length, f_string_map_multiss_t * const map_multiss); +#endif // _di_f_string_map_multiss_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_map_multiss_h diff --git a/level_0/f_string/c/string/maps.c b/level_0/f_string/c/string/maps.c new file mode 100644 index 0000000..268f1ef --- /dev/null +++ b/level_0/f_string/c/string/maps.c @@ -0,0 +1,151 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-maps.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_maps_adjust_ + f_status_t f_string_maps_adjust(const f_array_length_t length, f_string_maps_t * const maps) { + #ifndef _di_level_0_parameter_checking_ + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_maps_adjust(length, maps); + } +#endif // _di_f_string_maps_adjust_ + +#ifndef _di_f_string_maps_append_ + f_status_t f_string_maps_append(const f_string_map_t source, f_string_maps_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_maps_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].name.used = 0; + destination->array[destination->used].value.used = 0; + + if (source.name.used) { + status = private_f_string_append(source.name.string, source.name.used, &destination->array[destination->used].name); + if (F_status_is_error(status)) return status; + } + + if (source.value.used) { + status = private_f_string_append(source.value.string, source.value.used, &destination->array[destination->used].value); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_maps_append_ + +#ifndef _di_f_string_maps_append_all_ + f_status_t f_string_maps_append_all(const f_string_maps_t source, f_string_maps_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + return private_f_string_maps_append_all(source, destination); + } +#endif // _di_f_string_maps_append_all_ + +#ifndef _di_f_string_maps_decimate_by_ + f_status_t f_string_maps_decimate_by(const f_array_length_t amount, f_string_maps_t * const maps) { + #ifndef _di_level_0_parameter_checking_ + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (maps->size > amount) { + return private_f_string_maps_adjust(maps->size - amount, maps); + } + + return private_f_string_maps_adjust(0, maps); + } +#endif // _di_f_string_maps_decimate_by_ + +#ifndef _di_f_string_maps_decrease_by_ + f_status_t f_string_maps_decrease_by(const f_array_length_t amount, f_string_maps_t * const maps) { + #ifndef _di_level_0_parameter_checking_ + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (maps->size > amount) { + return private_f_string_maps_resize(maps->size - amount, maps); + } + + return private_f_string_maps_resize(0, maps); + } +#endif // _di_f_string_maps_decrease_by_ + +#ifndef _di_f_string_maps_increase_ + f_status_t f_string_maps_increase(const f_array_length_t step, f_string_maps_t * const maps) { + #ifndef _di_level_0_parameter_checking_ + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && maps->used + 1 > maps->size) { + f_array_length_t size = maps->used + step; + + if (size > F_array_length_t_size_d) { + if (maps->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_maps_resize(size, maps); + } + + return F_data_not; + } +#endif // _di_f_string_maps_increase_ + +#ifndef _di_f_string_maps_increase_by_ + f_status_t f_string_maps_increase_by(const f_array_length_t amount, f_string_maps_t * const maps) { + #ifndef _di_level_0_parameter_checking_ + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (maps->used + amount > maps->size) { + if (maps->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_maps_resize(maps->used + amount, maps); + } + + return F_data_not; + } +#endif // _di_f_string_maps_increase_by_ + +#ifndef _di_f_string_maps_resize_ + f_status_t f_string_maps_resize(const f_array_length_t length, f_string_maps_t * const maps) { + #ifndef _di_level_0_parameter_checking_ + if (!maps) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_maps_resize(length, maps); + } +#endif // _di_f_string_maps_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/maps.h b/level_0/f_string/c/string/maps.h new file mode 100644 index 0000000..261b256 --- /dev/null +++ b/level_0/f_string/c/string/maps.h @@ -0,0 +1,233 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines map string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_maps_h +#define _F_string_maps_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of string maps. + * + * array: the array of string maps. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_maps_t_ + typedef struct { + f_string_map_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_maps_t; + + #define f_string_maps_t_initialize f_string_statics_t_initialize + + #define macro_f_string_maps_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_maps_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_maps_t_clear(maps) macro_f_memory_structure_clear(maps) + + #define macro_f_string_maps_t_resize(status, maps, length) status = f_string_maps_resize(length, &maps); + #define macro_f_string_maps_t_adjust(status, maps, length) status = f_string_maps_adjust(length, &maps); + + #define macro_f_string_maps_t_delete_simple(maps) f_string_maps_resize(0, &maps); + #define macro_f_string_maps_t_destroy_simple(maps) f_string_maps_adjust(0, &maps); + + #define macro_f_string_maps_t_increase(status, step, maps) status = f_string_maps_increase(step, maps); + #define macro_f_string_maps_t_increase_by(status, maps, amount) status = f_string_maps_increase_by(amount, maps); + #define macro_f_string_maps_t_decrease_by(status, maps, amount) status = f_string_maps_decrease_by(amount, maps); + #define macro_f_string_maps_t_decimate_by(status, maps, amount) status = f_string_maps_decimate_by(amount, maps); +#endif // _di_f_string_maps_t_ + +/** + * Resize the string maps array. + * + * @param length + * The new size to use. + * @param maps + * The string maps array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_maps_adjust_ + extern f_status_t f_string_maps_adjust(const f_array_length_t length, f_string_maps_t * const maps); +#endif // _di_f_string_maps_adjust_ + +/** + * Append a single source map onto the destination. + * + * @param source + * The source maps to append. + * @param destination + * The destination maps the source is appended onto. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_maps_append_ + extern f_status_t f_string_maps_append(const f_string_map_t source, f_string_maps_t * const destination); +#endif // _di_f_string_maps_append_ + +/** + * Append the source maps onto the destination. + * + * @param source + * The source maps to append. + * @param destination + * The destination maps the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_maps_append_all_ + extern f_status_t f_string_maps_append_all(const f_string_maps_t source, f_string_maps_t * const destination); +#endif // _di_f_string_maps_append_all_ + +/** + * 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 decimate the size by. + * @param maps + * The string maps array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_maps_decimate_by_ + extern f_status_t f_string_maps_decimate_by(const f_array_length_t amount, f_string_maps_t * const maps); +#endif // _di_f_string_maps_decimate_by_ + +/** + * 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_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_maps_decrease_by_ + extern f_status_t f_string_maps_decrease_by(const f_array_length_t amount, f_string_maps_t * const maps); +#endif // _di_f_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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param maps + * The string maps array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_maps_increase_ + extern f_status_t f_string_maps_increase(const f_array_length_t step, f_string_maps_t * const maps); +#endif // _di_f_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_d). + * 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_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_maps_increase_by_ + extern f_status_t f_string_maps_increase_by(const f_array_length_t amount, f_string_maps_t * const maps); +#endif // _di_f_string_maps_increase_by_ + +/** + * Resize the string maps array. + * + * @param length + * The new size to use. + * @param maps + * The string maps array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_maps_resize_ + extern f_status_t f_string_maps_resize(const f_array_length_t length, f_string_maps_t * const maps); +#endif // _di_f_string_maps_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_maps_h diff --git a/level_0/f_string/c/string/mapss.c b/level_0/f_string/c/string/mapss.c new file mode 100644 index 0000000..9d6b89d --- /dev/null +++ b/level_0/f_string/c/string/mapss.c @@ -0,0 +1,165 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-maps.h" +#include "private-mapss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_mapss_adjust_ + f_status_t f_string_mapss_adjust(const f_array_length_t length, f_string_mapss_t * const mapss) { + #ifndef _di_level_0_parameter_checking_ + if (!mapss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_mapss_adjust(length, mapss); + } +#endif // _di_f_string_mapss_adjust_ + +#ifndef _di_f_string_mapss_append_ + f_status_t f_string_mapss_append(const f_string_maps_t source, f_string_mapss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_mapss_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].used = 0; + + if (source.used) { + status = private_f_string_maps_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_mapss_append_ + +#ifndef _di_f_string_mapss_append_all_ + f_status_t f_string_mapss_append_all(const f_string_mapss_t source, f_string_mapss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + source.used > destination->size) { + status = private_f_string_mapss_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].used = 0; + + if (source.array[i].used) { + status = private_f_string_maps_append_all(source.array[i], &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + } // for + + return F_none; + } +#endif // _di_f_string_mapss_append_all_ + +#ifndef _di_f_string_mapss_decimate_by_ + f_status_t f_string_mapss_decimate_by(const f_array_length_t amount, f_string_mapss_t * const mapss) { + #ifndef _di_level_0_parameter_checking_ + if (!mapss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (mapss->size > amount) { + return private_f_string_mapss_adjust(mapss->size - amount, mapss); + } + + return private_f_string_mapss_adjust(0, mapss); + } +#endif // _di_f_string_mapss_decimate_by_ + +#ifndef _di_f_string_mapss_decrease_by_ + f_status_t f_string_mapss_decrease_by(const f_array_length_t amount, f_string_mapss_t * const mapss) { + #ifndef _di_level_0_parameter_checking_ + if (!mapss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (mapss->size > amount) { + return private_f_string_mapss_resize(mapss->size - amount, mapss); + } + + return private_f_string_mapss_resize(0, mapss); + } +#endif // _di_f_string_mapss_decrease_by_ + +#ifndef _di_f_string_mapss_increase_ + f_status_t f_string_mapss_increase(const f_array_length_t step, f_string_mapss_t * const mapss) { + #ifndef _di_level_0_parameter_checking_ + if (!mapss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && mapss->used + 1 > mapss->size) { + f_array_length_t size = mapss->used + step; + + if (size > F_array_length_t_size_d) { + if (mapss->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_mapss_resize(size, mapss); + } + + return F_data_not; + } +#endif // _di_f_string_mapss_increase_ + +#ifndef _di_f_string_mapss_increase_by_ + f_status_t f_string_mapss_increase_by(const f_array_length_t amount, f_string_mapss_t * const mapss) { + #ifndef _di_level_0_parameter_checking_ + if (!mapss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (mapss->used + amount > mapss->size) { + if (mapss->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_mapss_resize(mapss->used + amount, mapss); + } + + return F_data_not; + } +#endif // _di_f_string_mapss_increase_by_ + +#ifndef _di_f_string_mapss_resize_ + f_status_t f_string_mapss_resize(const f_array_length_t length, f_string_mapss_t * const mapss) { + #ifndef _di_level_0_parameter_checking_ + if (!mapss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_mapss_resize(length, mapss); + } +#endif // _di_f_string_mapss_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/mapss.h b/level_0/f_string/c/string/mapss.h new file mode 100644 index 0000000..4361bb1 --- /dev/null +++ b/level_0/f_string/c/string/mapss.h @@ -0,0 +1,234 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines map string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_mapss_h +#define _F_string_mapss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of string maps. + * + * array: the array of an array of string maps. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_mapss_t_ + typedef struct { + f_string_maps_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_mapss_t; + + #define f_string_mapss_t_initialize f_string_statics_t_initialize + + #define macro_f_string_mapss_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_mapss_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_mapss_t_clear(maps) macro_f_memory_structure_clear(maps) + + #define macro_f_string_mapss_t_resize(status, maps, length) status = f_string_mapss_resize(length, &maps); + #define macro_f_string_mapss_t_adjust(status, maps, length) status = f_string_mapss_adjust(length, &maps); + + #define macro_f_string_mapss_t_delete_simple(maps) f_string_mapss_resize(0, &maps); + #define macro_f_string_mapss_t_destroy_simple(maps) f_string_mapss_adjust(0, &maps); + + #define macro_f_string_mapss_t_increase(status, step, maps) status = f_string_mapss_increase(step, maps); + #define macro_f_string_mapss_t_increase_by(status, maps, amount) status = f_string_mapss_increase_by(amount, maps); + #define macro_f_string_mapss_t_decrease_by(status, maps, amount) status = f_string_mapss_decrease_by(amount, maps); + #define macro_f_string_mapss_t_decimate_by(status, maps, amount) status = f_string_mapss_decimate_by(amount, maps); +#endif // _di_f_string_mapss_t_ + +/** + * Resize the string mapss array. + * + * @param length + * The new size to use. + * @param mapss + * The string mapss array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_mapss_adjust_ + extern f_status_t f_string_mapss_adjust(const f_array_length_t length, f_string_mapss_t * const mapss); +#endif // _di_f_string_mapss_adjust_ + +/** + * Append a single source maps onto the destination. + * + * @param source + * The source mapss to append. + * @param destination + * The destination mapss the source is appended onto. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_mapss_append_ + extern f_status_t f_string_mapss_append(const f_string_maps_t source, f_string_mapss_t * const destination); +#endif // _di_f_string_mapss_append_ + +/** + * Append the source mapss onto the destination. + * + * @param source + * The source mapss to append. + * @param destination + * The destination mapss the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_mapss_append_all_ + extern f_status_t f_string_mapss_append_all(const f_string_mapss_t source, f_string_mapss_t * const destination); +#endif // _di_f_string_mapss_append_all_ + +/** + * Resize the string mapss 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 decimate the size by. + * @param mapss + * The string mapss array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_mapss_decimate_by_ + extern f_status_t f_string_mapss_decimate_by(const f_array_length_t amount, f_string_mapss_t * const mapss); +#endif // _di_f_string_mapss_decimate_by_ + +/** + * Resize the string mapss 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 mapss + * The string mapss array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_mapss_decrease_by_ + extern f_status_t f_string_mapss_decrease_by(const f_array_length_t amount, f_string_mapss_t * const mapss); +#endif // _di_f_string_mapss_decrease_by_ + +/** + * Increase the size of the string mapss 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param mapss + * The string mapss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size) (or step is 0). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_mapss_increase_ + extern f_status_t f_string_mapss_increase(const f_array_length_t step, f_string_mapss_t * const mapss); +#endif // _di_f_string_mapss_increase_ + +/** + * Resize the string mapss 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_d). + * 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 mapss + * The string mapss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_mapss_increase_by_ + extern f_status_t f_string_mapss_increase_by(const f_array_length_t amount, f_string_mapss_t * const mapss); +#endif // _di_f_string_mapss_increase_by_ + +/** + * Resize the string mapss array. + * + * @param length + * The new size to use. + * @param mapss + * The string mapss array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_mapss_resize_ + extern f_status_t f_string_mapss_resize(const f_array_length_t length, f_string_mapss_t * const mapss); +#endif // _di_f_string_mapss_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_mapss_h diff --git a/level_0/f_string/c/string/private-dynamic.c b/level_0/f_string/c/string/private-dynamic.c index 43a3edf..e3da0a0 100644 --- a/level_0/f_string/c/string/private-dynamic.c +++ b/level_0/f_string/c/string/private-dynamic.c @@ -53,158 +53,6 @@ extern "C" { } #endif // !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_append_mash_) || !defined(_di_f_string_append_nulless_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_append_nulless_) || !defined(_di_f_string_dynamic_decrease_by_) || !defined(_di_f_string_dynamic_increase_) || !defined(_di_f_string_dynamic_increase_by_) || !defined(_di_f_string_dynamic_mash_) || !defined(_di_f_string_dynamic_mash_nulless_) || !defined(f_string_dynamic_partial_append) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamic_prepend_) || !defined(_di_f_string_dynamic_prepend_nulless_) || !defined(_di_f_string_dynamic_terminate_) || !defined(_di_f_string_dynamic_terminate_after_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_nulless_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_prepend_) || !defined(_di_f_string_prepend_nulless_) || !defined(_di_f_string_triples_append_) -#if !defined(_di_f_string_dynamics_adjust_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_dynamics_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) - f_status_t private_f_string_dynamics_adjust(const f_array_length_t length, f_string_dynamics_t * const dynamics) { - - if (dynamics->used + length > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < dynamics->size; ++i) { - - status = private_f_string_dynamic_adjust(0, &dynamics->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_adjust(dynamics->size, length, sizeof(f_string_dynamic_t), (void **) & dynamics->array); - if (F_status_is_error(status)) return status; - - dynamics->size = length; - - if (dynamics->used > dynamics->size) { - dynamics->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_dynamics_adjust_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_dynamics_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) - -#if !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) - f_status_t private_f_string_dynamics_append(const f_string_dynamic_t source, f_string_dynamics_t * const destination) { - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_dynamics_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].used = 0; - - if (source.used) { - status = private_f_string_append(source.string, source.used, &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) - - -#if !defined(_di_f_string_dynamics_append_all_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) - f_status_t private_f_string_dynamics_append_all(const f_string_dynamics_t source, f_string_dynamics_t * const destination) { - - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_string_dynamics_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } - - for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { - - destination->array[destination->used].used = 0; - - if (source.array[i].used) { - status = private_f_string_append(source.array[i].string, source.array[i].used, &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - } // for - - return F_none; - } -#endif // !defined(_di_f_string_dynamics_append_all_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) - -#if !defined(_di_f_string_dynamics_decrease_by_) || !defined(_di_f_string_dynamics_increase_) || !defined(_di_f_string_dynamics_increase_by_) || !defined(f_string_map_multis_append) - f_status_t private_f_string_dynamics_resize(const f_array_length_t length, f_string_dynamics_t * const dynamics) { - - if (dynamics->used + length > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < dynamics->size; ++i) { - - status = private_f_string_dynamic_resize(0, &dynamics->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_resize(dynamics->size, length, sizeof(f_string_dynamic_t), (void **) & dynamics->array); - if (F_status_is_error(status)) return status; - - dynamics->size = length; - - if (dynamics->used > dynamics->size) { - dynamics->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_dynamics_decrease_by_) || !defined(_di_f_string_dynamics_increase_) || !defined(_di_f_string_dynamics_increase_by_) || !defined(f_string_map_multis_append) - -#if !defined(_di_f_string_dynamicss_adjust_) || !defined(_di_f_string_dynamicss_append_) || !defined(_di_f_string_dynamicss_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) - f_status_t private_f_string_dynamicss_adjust(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) { - - if (dynamicss->used + length > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < dynamicss->size; ++i) { - - status = private_f_string_dynamics_adjust(0, &dynamicss->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_adjust(dynamicss->size, length, sizeof(f_string_dynamics_t), (void **) & dynamicss->array); - if (F_status_is_error(status)) return status; - - dynamicss->size = length; - - if (dynamicss->used > dynamicss->size) { - dynamicss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_dynamicss_adjust_) || !defined(_di_f_string_dynamicss_append_) || !defined(_di_f_string_dynamicss_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) - -#if !defined(_di_f_string_dynamicss_decrease_by_) || !defined(_di_f_string_dynamicss_increase_) || !defined(_di_f_string_dynamicss_increase_by_) || !defined(_di_f_string_dynamicss_append_all_) || !defined(_di_f_string_map_multis_append_all_) - f_status_t private_f_string_dynamicss_resize(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) { - - if (dynamicss->used + length > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < dynamicss->size; ++i) { - - status = private_f_string_dynamics_resize(0, &dynamicss->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_resize(dynamicss->size, length, sizeof(f_string_dynamics_t), (void **) & dynamicss->array); - if (F_status_is_error(status)) return status; - - dynamicss->size = length; - - if (dynamicss->used > dynamicss->size) { - dynamicss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_dynamicss_decrease_by_) || !defined(_di_f_string_dynamicss_increase_) || !defined(_di_f_string_dynamicss_increase_by_) || !defined(_di_f_string_dynamicss_append_all_) || !defined(_di_f_string_map_multis_append_all_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/private-dynamic.h b/level_0/f_string/c/string/private-dynamic.h index e7e114d..44a2dec 100644 --- a/level_0/f_string/c/string/private-dynamic.h +++ b/level_0/f_string/c/string/private-dynamic.h @@ -16,78 +16,6 @@ extern "C" { #endif /** - * Private implementation of f_string_append(). - * - * Intended to be shared to each of the different implementation variations. - * - * @param source - * The source string to append. - * @param length - * Length of source to append. - * @param destination - * The destination string the source and glue are appended onto. - * - * @return - * F_none on success. - * - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see memcpy() - * - * @see f_string_append() - * @see f_string_append_assure() - * @see f_string_dynamic_append() - * @see f_string_dynamic_append_assure() - * @see f_string_dynamic_mash() - * @see f_string_dynamic_partial_append) - * @see f_string_dynamic_partial_append_assure() - * @see f_string_dynamic_partial_mash() - * @see f_string_dynamics_append() - * @see f_string_map_multis_append() - * @see f_string_mash() - * @see f_string_maps_append() - * @see f_string_triples_append() - */ -#if !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(f_string_dynamic_partial_append) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) - extern f_status_t private_f_string_append(const f_string_t source, const f_array_length_t length, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_mash_) || !defined(f_string_dynamic_partial_append) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_triples_append_) - -/** - * Private implementation of f_string_append_nulless(). - * - * Intended to be shared to each of the different implementation variations. - * - * @param source - * The source string to append. - * @param length - * Length of source to append. - * @param destination - * The destination string the source and glue are appended onto. - * - * @return - * F_none on success. - * - * F_string_too_large (with error bit) if the combined string is too large. - * - * @see memcpy() - * - * @see f_string_append_assure_nulless() - * @see f_string_append_nulless() - * @see f_string_dynamic_append_assure_nulless() - * @see f_string_dynamic_append_nulless() - * @see f_string_dynamic_mash_nulless() - * @see f_string_dynamic_partial_append_assure_nulless() - * @see f_string_dynamic_partial_append_nulless() - * @see f_string_dynamic_partial_mash_nulless() - * @see f_string_mash_nulless() - */ -#if !defined(_di_f_string_append_assure_nulless_) || !defined(_di_f_string_append_nulless_) || !defined(_di_f_string_dynamic_append_assure_nulless_) || !defined(_di_f_string_dynamic_append_nulless_) || !defined(_di_f_string_dynamic_mash_nulless_) || !defined(_di_f_string_dynamic_partial_append_assure_nulless_) || !defined(_di_f_string_dynamic_partial_append_nulless_) || !defined(_di_f_string_dynamic_partial_mash_nulless_) || !defined(_di_f_string_mash_nulless_) - extern f_status_t private_f_string_append_nulless(const f_string_t source, const f_array_length_t length, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_append_assure_nulless_) || !defined(_di_f_string_append_nulless_) || !defined(_di_f_string_dynamic_append_assure_nulless_) || !defined(_di_f_string_dynamic_append_nulless_) || !defined(_di_f_string_dynamic_mash_nulless_) || !defined(_di_f_string_dynamic_partial_append_assure_nulless_) || !defined(_di_f_string_dynamic_partial_append_nulless_) || !defined(_di_f_string_dynamic_partial_mash_nulless_) || !defined(_di_f_string_mash_nulless_) - -/** * Private implementation for resizing. * * Intended to be shared to each of the different implementation variations. @@ -213,168 +141,6 @@ extern "C" { extern f_status_t private_f_string_dynamic_resize(const f_array_length_t length, f_string_dynamic_t * const dynamic) F_attribute_visibility_internal_d; #endif // !defined(_di_f_string_append_) || !defined(_di_f_string_append_assure_) || !defined(_di_f_string_append_mash_) || !defined(_di_f_string_append_nulless_) || !defined(_di_f_string_dynamic_append_) || !defined(_di_f_string_dynamic_append_assure_) || !defined(_di_f_string_dynamic_append_nulless_) || !defined(_di_f_string_dynamic_decrease_by_) || !defined(_di_f_string_dynamic_increase_) || !defined(_di_f_string_dynamic_increase_by_) || !defined(_di_f_string_dynamic_mash_) || !defined(_di_f_string_dynamic_mash_nulless_) || !defined(f_string_dynamic_partial_append) || !defined(_di_f_string_dynamic_partial_append_assure_) || !defined(_di_f_string_dynamic_partial_mash_) || !defined(_di_f_string_dynamic_prepend_) || !defined(_di_f_string_dynamic_prepend_nulless_) || !defined(_di_f_string_dynamic_terminate_) || !defined(_di_f_string_dynamic_terminate_after_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_mash_nulless_) || !defined(_di_f_string_mash_) || !defined(_di_f_string_maps_append_) || !defined(_di_f_string_prepend_) || !defined(_di_f_string_prepend_nulless_) || !defined(_di_f_string_triples_append_) -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param dynamics - * The strings to adjust. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_adjust(). - * - * @see f_memory_adjust() - * @see f_string_dynamics_adjust() - * @see f_string_dynamics_append() - * @see f_string_dynamics_decimate_by() - * @see f_string_map_multis_adjust() - * @see f_string_map_multis_append() - */ -#if !defined(_di_f_string_dynamics_adjust_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_dynamics_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) - extern f_status_t private_f_string_dynamics_adjust(const f_array_length_t length, f_string_dynamics_t * const dynamics) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_dynamics_adjust_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_dynamics_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) - -/** - * Private implementation for appending. - * - * Intended to be shared to each of the different implementation variations. - * - * @param source - * The source string to append. - * @param destination - * The destination strings the source is appended onto. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamics_append() - * @see f_string_map_multis_append() - * @see f_string_map_multis_append_all() - */ -#if !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) - extern f_status_t private_f_string_dynamics_append(const f_string_dynamic_t source, f_string_dynamics_t * const destination) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) - -/** - * Private implementation for appending. - * - * Intended to be shared to each of the different implementation variations. - * - * @param source - * The source strings to append. - * @param destination - * The destination strings the source is appended onto. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamics_append_all() - * @see f_string_map_multis_append() - * @see f_string_map_multis_append_all() - */ -#if !defined(_di_f_string_dynamics_append_all_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) - extern f_status_t private_f_string_dynamics_append_all(const f_string_dynamics_t source, f_string_dynamics_t * const destination) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_dynamics_append_all_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) - -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param dynamics - * The strings to resize. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamics_decrease_by() - * @see f_string_dynamics_increase() - * @see f_string_dynamics_increase_by() - */ -#if !defined(_di_f_string_dynamics_decrease_by_) || !defined(_di_f_string_dynamics_increase_) || !defined(_di_f_string_dynamics_increase_by_) - extern f_status_t private_f_string_dynamics_resize(const f_array_length_t length, f_string_dynamics_t * const dynamics) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_dynamics_decrease_by_) || !defined(_di_f_string_dynamics_increase_) || !defined(_di_f_string_dynamics_increase_by_) - -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param dynamicss - * The strings to adjust. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_adjust(). - * - * @see f_memory_adjust() - * @see f_string_dynamicss_adjust() - * @see f_string_dynamicss_append() - * @see f_string_dynamicss_decimate_by() - * @see f_string_map_multis_adjust() - * @see f_string_map_multis_append() - */ -#if !defined(_di_f_string_dynamicss_adjust_) || !defined(_di_f_string_dynamicss_append_) || !defined(_di_f_string_dynamicss_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) - extern f_status_t private_f_string_dynamicss_adjust(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_dynamicss_adjust_) || !defined(_di_f_string_dynamicss_append_) || !defined(_di_f_string_dynamicss_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) - -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param dynamicss - * The strings to resize. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_memory_resize() - * @see f_string_dynamicss_append_all() - * @see f_string_dynamicss_decrease_by() - * @see f_string_dynamicss_increase() - * @see f_string_dynamicss_increase_by() - * @see f_string_map_multis_append_all() - */ -#if !defined(_di_f_string_dynamicss_decrease_by_) || !defined(_di_f_string_dynamicss_increase_) || !defined(_di_f_string_dynamicss_increase_by_) || !defined(_di_f_string_dynamicss_append_all_) || !defined(_di_f_string_map_multis_append_all_) - extern f_status_t private_f_string_dynamicss_resize(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_dynamicss_decrease_by_) || !defined(_di_f_string_dynamicss_increase_) || !defined(_di_f_string_dynamicss_increase_by_) || !defined(_di_f_string_dynamicss_append_all_) || !defined(_di_f_string_map_multis_append_all_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/private-dynamics.c b/level_0/f_string/c/string/private-dynamics.c new file mode 100644 index 0000000..7c8e833 --- /dev/null +++ b/level_0/f_string/c/string/private-dynamics.c @@ -0,0 +1,111 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-dynamic.h" +#include "private-dynamics.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_string_dynamics_adjust_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_dynamics_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) + f_status_t private_f_string_dynamics_adjust(const f_array_length_t length, f_string_dynamics_t * const dynamics) { + + if (dynamics->used + length > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < dynamics->size; ++i) { + + status = private_f_string_dynamic_adjust(0, &dynamics->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(dynamics->size, length, sizeof(f_string_dynamic_t), (void **) & dynamics->array); + if (F_status_is_error(status)) return status; + + dynamics->size = length; + + if (dynamics->used > dynamics->size) { + dynamics->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_dynamics_adjust_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_dynamics_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) + +#if !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) + f_status_t private_f_string_dynamics_append(const f_string_dynamic_t source, f_string_dynamics_t * const destination) { + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_dynamics_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].used = 0; + + if (source.used) { + status = private_f_string_append(source.string, source.used, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) + +#if !defined(_di_f_string_dynamics_append_all_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) + f_status_t private_f_string_dynamics_append_all(const f_string_dynamics_t source, f_string_dynamics_t * const destination) { + + f_status_t status = F_none; + + if (destination->used + source.used > destination->size) { + status = private_f_string_dynamics_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].used = 0; + + if (source.array[i].used) { + status = private_f_string_append(source.array[i].string, source.array[i].used, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + } // for + + return F_none; + } +#endif // !defined(_di_f_string_dynamics_append_all_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) + +#if !defined(_di_f_string_dynamics_decrease_by_) || !defined(_di_f_string_dynamics_increase_) || !defined(_di_f_string_dynamics_increase_by_) || !defined(f_string_map_multis_append) + f_status_t private_f_string_dynamics_resize(const f_array_length_t length, f_string_dynamics_t * const dynamics) { + + if (dynamics->used + length > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < dynamics->size; ++i) { + + status = private_f_string_dynamic_resize(0, &dynamics->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(dynamics->size, length, sizeof(f_string_dynamic_t), (void **) & dynamics->array); + if (F_status_is_error(status)) return status; + + dynamics->size = length; + + if (dynamics->used > dynamics->size) { + dynamics->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_dynamics_decrease_by_) || !defined(_di_f_string_dynamics_increase_) || !defined(_di_f_string_dynamics_increase_by_) || !defined(f_string_map_multis_append) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/private-dynamics.h b/level_0/f_string/c/string/private-dynamics.h new file mode 100644 index 0000000..73e52bc --- /dev/null +++ b/level_0/f_string/c/string/private-dynamics.h @@ -0,0 +1,128 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_string_dynamics_h +#define _PRIVATE_F_string_dynamics_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param dynamics + * The strings to adjust. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_string_dynamics_adjust() + * @see f_string_dynamics_append() + * @see f_string_dynamics_decimate_by() + * @see f_string_map_multis_adjust() + * @see f_string_map_multis_append() + */ +#if !defined(_di_f_string_dynamics_adjust_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_dynamics_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) + extern f_status_t private_f_string_dynamics_adjust(const f_array_length_t length, f_string_dynamics_t * const dynamics) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_dynamics_adjust_) || !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_dynamics_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) + +/** + * Private implementation for appending. + * + * Intended to be shared to each of the different implementation variations. + * + * @param source + * The source string to append. + * @param destination + * The destination strings the source is appended onto. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_string_dynamics_append() + * @see f_string_map_multis_append() + * @see f_string_map_multis_append_all() + */ +#if !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) + extern f_status_t private_f_string_dynamics_append(const f_string_dynamic_t source, f_string_dynamics_t * const destination) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_dynamics_append_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) + +/** + * Private implementation for appending. + * + * Intended to be shared to each of the different implementation variations. + * + * @param source + * The source strings to append. + * @param destination + * The destination strings the source is appended onto. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_string_dynamics_append_all() + * @see f_string_map_multis_append() + * @see f_string_map_multis_append_all() + */ +#if !defined(_di_f_string_dynamics_append_all_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) + extern f_status_t private_f_string_dynamics_append_all(const f_string_dynamics_t source, f_string_dynamics_t * const destination) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_dynamics_append_all_) || !defined(_di_f_string_map_multis_append_) || !defined(_di_f_string_map_multis_append_all_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param dynamics + * The strings to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_string_dynamics_decrease_by() + * @see f_string_dynamics_increase() + * @see f_string_dynamics_increase_by() + */ +#if !defined(_di_f_string_dynamics_decrease_by_) || !defined(_di_f_string_dynamics_increase_) || !defined(_di_f_string_dynamics_increase_by_) + extern f_status_t private_f_string_dynamics_resize(const f_array_length_t length, f_string_dynamics_t * const dynamics) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_dynamics_decrease_by_) || !defined(_di_f_string_dynamics_increase_) || !defined(_di_f_string_dynamics_increase_by_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_string_dynamics_h diff --git a/level_0/f_string/c/string/private-dynamicss.c b/level_0/f_string/c/string/private-dynamicss.c new file mode 100644 index 0000000..09a69fb --- /dev/null +++ b/level_0/f_string/c/string/private-dynamicss.c @@ -0,0 +1,65 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-dynamic.h" +#include "private-dynamics.h" +#include "private-dynamicss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_string_dynamicss_adjust_) || !defined(_di_f_string_dynamicss_append_) || !defined(_di_f_string_dynamicss_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) + f_status_t private_f_string_dynamicss_adjust(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) { + + if (dynamicss->used + length > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < dynamicss->size; ++i) { + + status = private_f_string_dynamics_adjust(0, &dynamicss->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(dynamicss->size, length, sizeof(f_string_dynamics_t), (void **) & dynamicss->array); + if (F_status_is_error(status)) return status; + + dynamicss->size = length; + + if (dynamicss->used > dynamicss->size) { + dynamicss->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_dynamicss_adjust_) || !defined(_di_f_string_dynamicss_append_) || !defined(_di_f_string_dynamicss_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) + +#if !defined(_di_f_string_dynamicss_decrease_by_) || !defined(_di_f_string_dynamicss_increase_) || !defined(_di_f_string_dynamicss_increase_by_) || !defined(_di_f_string_dynamicss_append_all_) || !defined(_di_f_string_map_multis_append_all_) + f_status_t private_f_string_dynamicss_resize(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) { + + if (dynamicss->used + length > F_array_length_t_size_d) return F_status_set_error(F_array_too_large); + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < dynamicss->size; ++i) { + + status = private_f_string_dynamics_resize(0, &dynamicss->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(dynamicss->size, length, sizeof(f_string_dynamics_t), (void **) & dynamicss->array); + if (F_status_is_error(status)) return status; + + dynamicss->size = length; + + if (dynamicss->used > dynamicss->size) { + dynamicss->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_dynamicss_decrease_by_) || !defined(_di_f_string_dynamicss_increase_) || !defined(_di_f_string_dynamicss_increase_by_) || !defined(_di_f_string_dynamicss_append_all_) || !defined(_di_f_string_map_multis_append_all_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/private-dynamicss.h b/level_0/f_string/c/string/private-dynamicss.h new file mode 100644 index 0000000..a4ffac0 --- /dev/null +++ b/level_0/f_string/c/string/private-dynamicss.h @@ -0,0 +1,78 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_string_dynamicss_h +#define _PRIVATE_F_string_dynamicss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param dynamicss + * The strings to adjust. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_string_dynamicss_adjust() + * @see f_string_dynamicss_append() + * @see f_string_dynamicss_decimate_by() + * @see f_string_map_multis_adjust() + * @see f_string_map_multis_append() + */ +#if !defined(_di_f_string_dynamicss_adjust_) || !defined(_di_f_string_dynamicss_append_) || !defined(_di_f_string_dynamicss_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) + extern f_status_t private_f_string_dynamicss_adjust(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_dynamicss_adjust_) || !defined(_di_f_string_dynamicss_append_) || !defined(_di_f_string_dynamicss_decimate_by_) || !defined(_di_f_string_map_multis_adjust_) || !defined(_di_f_string_map_multis_append_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param dynamicss + * The strings to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_string_dynamicss_append_all() + * @see f_string_dynamicss_decrease_by() + * @see f_string_dynamicss_increase() + * @see f_string_dynamicss_increase_by() + * @see f_string_map_multis_append_all() + */ +#if !defined(_di_f_string_dynamicss_decrease_by_) || !defined(_di_f_string_dynamicss_increase_) || !defined(_di_f_string_dynamicss_increase_by_) || !defined(_di_f_string_dynamicss_append_all_) || !defined(_di_f_string_map_multis_append_all_) + extern f_status_t private_f_string_dynamicss_resize(const f_array_length_t length, f_string_dynamicss_t * const dynamicss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_dynamicss_decrease_by_) || !defined(_di_f_string_dynamicss_increase_) || !defined(_di_f_string_dynamicss_increase_by_) || !defined(_di_f_string_dynamicss_append_all_) || !defined(_di_f_string_map_multis_append_all_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_string_dynamicss_h diff --git a/level_0/f_string/c/string/private-map_multi.c b/level_0/f_string/c/string/private-map_multis.c similarity index 63% rename from level_0/f_string/c/string/private-map_multi.c rename to level_0/f_string/c/string/private-map_multis.c index b7f9604..faa2ab0 100644 --- a/level_0/f_string/c/string/private-map_multi.c +++ b/level_0/f_string/c/string/private-map_multis.c @@ -1,7 +1,8 @@ #include "../string.h" #include "../private-string.h" #include "private-dynamic.h" -#include "private-map_multi.h" +#include "private-dynamics.h" +#include "private-map_multis.h" #ifdef __cplusplus extern "C" { @@ -99,62 +100,6 @@ extern "C" { } #endif // !defined(_di_f_string_map_multis_decrease_by_) || !defined(_di_f_string_map_multis_increase_) || !defined(_di_f_string_map_multis_increase_by_) || !defined(_di_f_string_map_multis_terminate_) || !defined(_di_f_string_map_multis_terminate_after_) -#if !defined(_di_f_string_map_multiss_adjust_) || !defined(_di_f_string_map_multiss_decimate_by_) - f_status_t private_f_string_map_multiss_adjust(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) { - - if (map_multiss->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < map_multiss->size; ++i) { - - status = private_f_string_map_multis_adjust(0, &map_multiss->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_adjust(map_multiss->size, length, sizeof(f_string_map_multis_t), (void **) & map_multiss->array); - if (F_status_is_error(status)) return status; - - map_multiss->size = length; - - if (map_multiss->used > map_multiss->size) { - map_multiss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_map_multiss_adjust_) || !defined(_di_f_string_map_multiss_decimate_by_) - -#if !defined(_di_f_string_map_multiss_decrease_by_) || !defined(_di_f_string_map_multiss_increase_) || !defined(_di_f_string_map_multiss_increase_by_) || !defined(_di_f_string_map_multiss_terminate_) || !defined(_di_f_string_map_multiss_terminate_after_) - f_status_t private_f_string_map_multiss_resize(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) { - - if (map_multiss->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < map_multiss->size; ++i) { - - status = private_f_string_map_multis_resize(0, &map_multiss->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_resize(map_multiss->size, length, sizeof(f_string_map_multis_t), (void **) & map_multiss->array); - if (F_status_is_error(status)) return status; - - map_multiss->size = length; - - if (map_multiss->used > map_multiss->size) { - map_multiss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_map_multiss_decrease_by_) || !defined(_di_f_string_map_multiss_increase_) || !defined(_di_f_string_map_multiss_increase_by_) || !defined(_di_f_string_map_multiss_terminate_) || !defined(_di_f_string_map_multiss_terminate_after_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/private-map_multi.h b/level_0/f_string/c/string/private-map_multis.h similarity index 60% rename from level_0/f_string/c/string/private-map_multi.h rename to level_0/f_string/c/string/private-map_multis.h index ea67e1d..af085ef 100644 --- a/level_0/f_string/c/string/private-map_multi.h +++ b/level_0/f_string/c/string/private-map_multis.h @@ -8,8 +8,8 @@ * These are provided for internal reduction in redundant code. * These should not be exposed/used outside of this project. */ -#ifndef _PRIVATE_F_string_map_multi_h -#define _PRIVATE_F_string_map_multi_h +#ifndef _PRIVATE_F_string_map_multis_h +#define _PRIVATE_F_string_map_multis_h #ifdef __cplusplus extern "C" { @@ -93,60 +93,8 @@ extern "C" { extern f_status_t private_f_string_map_multis_resize(const f_array_length_t length, f_string_map_multis_t * const map_multis) F_attribute_visibility_internal_d; #endif // !defined(_di_f_string_map_multis_decrease_by_) || !defined(_di_f_string_map_multis_increase_) || !defined(_di_f_string_map_multis_increase_by_) || !defined(_di_f_string_map_multis_terminate_) || !defined(_di_f_string_map_multis_terminate_after_) -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param map_multiss - * The map_multiss to adjust. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_adjust(). - * - * @see f_memory_adjust() - * @see f_string_map_multiss_adjust() - */ -#if !defined(_di_f_string_map_multiss_adjust_) || !defined(_di_f_string_map_multiss_decimate_by_) - extern f_status_t private_f_string_map_multiss_adjust(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_map_multiss_adjust_) || !defined(_di_f_string_map_multiss_decimate_by_) - -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param map_multiss - * The map_multiss to resize. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_memory_adjust() - * @see f_string_map_multiss_decrease_by() - * @see f_string_map_multiss_increase() - * @see f_string_map_multiss_increase_by() - * @see f_string_map_multiss_terminate() - * @see f_string_map_multiss_terminate_after() - */ -#if !defined(_di_f_string_map_multiss_decrease_by_) || !defined(_di_f_string_map_multiss_increase_) || !defined(_di_f_string_map_multiss_increase_by_) || !defined(_di_f_string_map_multiss_terminate_) || !defined(_di_f_string_map_multiss_terminate_after_) - extern f_status_t private_f_string_map_multiss_resize(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_map_multiss_decrease_by_) || !defined(_di_f_string_map_multiss_increase_) || !defined(_di_f_string_map_multiss_increase_by_) || !defined(_di_f_string_map_multiss_terminate_) || !defined(_di_f_string_map_multiss_terminate_after_) - #ifdef __cplusplus } // extern "C" #endif -#endif // _PRIVATE_F_string_map_multi_h +#endif // _PRIVATE_F_string_map_multis_h diff --git a/level_0/f_string/c/string/private-map_multiss.c b/level_0/f_string/c/string/private-map_multiss.c new file mode 100644 index 0000000..f0b8c94 --- /dev/null +++ b/level_0/f_string/c/string/private-map_multiss.c @@ -0,0 +1,70 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-dynamic.h" +#include "private-dynamics.h" +#include "private-map_multis.h" +#include "private-map_multiss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_string_map_multiss_adjust_) || !defined(_di_f_string_map_multiss_decimate_by_) + f_status_t private_f_string_map_multiss_adjust(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) { + + if (map_multiss->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < map_multiss->size; ++i) { + + status = private_f_string_map_multis_adjust(0, &map_multiss->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(map_multiss->size, length, sizeof(f_string_map_multis_t), (void **) & map_multiss->array); + if (F_status_is_error(status)) return status; + + map_multiss->size = length; + + if (map_multiss->used > map_multiss->size) { + map_multiss->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_map_multiss_adjust_) || !defined(_di_f_string_map_multiss_decimate_by_) + +#if !defined(_di_f_string_map_multiss_decrease_by_) || !defined(_di_f_string_map_multiss_increase_) || !defined(_di_f_string_map_multiss_increase_by_) || !defined(_di_f_string_map_multiss_terminate_) || !defined(_di_f_string_map_multiss_terminate_after_) + f_status_t private_f_string_map_multiss_resize(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) { + + if (map_multiss->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < map_multiss->size; ++i) { + + status = private_f_string_map_multis_resize(0, &map_multiss->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(map_multiss->size, length, sizeof(f_string_map_multis_t), (void **) & map_multiss->array); + if (F_status_is_error(status)) return status; + + map_multiss->size = length; + + if (map_multiss->used > map_multiss->size) { + map_multiss->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_map_multiss_decrease_by_) || !defined(_di_f_string_map_multiss_increase_) || !defined(_di_f_string_map_multiss_increase_by_) || !defined(_di_f_string_map_multiss_terminate_) || !defined(_di_f_string_map_multiss_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/private-map_multiss.h b/level_0/f_string/c/string/private-map_multiss.h new file mode 100644 index 0000000..d132c3b --- /dev/null +++ b/level_0/f_string/c/string/private-map_multiss.h @@ -0,0 +1,74 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_string_map_multiss_h +#define _PRIVATE_F_string_map_multiss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param map_multiss + * The map_multiss to adjust. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_string_map_multiss_adjust() + */ +#if !defined(_di_f_string_map_multiss_adjust_) || !defined(_di_f_string_map_multiss_decimate_by_) + extern f_status_t private_f_string_map_multiss_adjust(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_map_multiss_adjust_) || !defined(_di_f_string_map_multiss_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param map_multiss + * The map_multiss to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_adjust() + * @see f_string_map_multiss_decrease_by() + * @see f_string_map_multiss_increase() + * @see f_string_map_multiss_increase_by() + * @see f_string_map_multiss_terminate() + * @see f_string_map_multiss_terminate_after() + */ +#if !defined(_di_f_string_map_multiss_decrease_by_) || !defined(_di_f_string_map_multiss_increase_) || !defined(_di_f_string_map_multiss_increase_by_) || !defined(_di_f_string_map_multiss_terminate_) || !defined(_di_f_string_map_multiss_terminate_after_) + extern f_status_t private_f_string_map_multiss_resize(const f_array_length_t length, f_string_map_multiss_t * const map_multiss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_map_multiss_decrease_by_) || !defined(_di_f_string_map_multiss_increase_) || !defined(_di_f_string_map_multiss_increase_by_) || !defined(_di_f_string_map_multiss_terminate_) || !defined(_di_f_string_map_multiss_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_string_map_multiss_h diff --git a/level_0/f_string/c/string/private-map.c b/level_0/f_string/c/string/private-maps.c similarity index 64% rename from level_0/f_string/c/string/private-map.c rename to level_0/f_string/c/string/private-maps.c index da7a9b1..c766f9d 100644 --- a/level_0/f_string/c/string/private-map.c +++ b/level_0/f_string/c/string/private-maps.c @@ -1,7 +1,7 @@ #include "../string.h" #include "../private-string.h" #include "private-dynamic.h" -#include "private-map.h" +#include "private-maps.h" #ifdef __cplusplus extern "C" { @@ -99,62 +99,6 @@ extern "C" { } #endif // !defined(_di_f_string_maps_decrease_by_) || !defined(_di_f_string_maps_increase_) || !defined(_di_f_string_maps_increase_by_) || !defined(_di_f_string_maps_terminate_) || !defined(_di_f_string_maps_terminate_after_) -#if !defined(_di_f_string_mapss_adjust_) || !defined(_di_f_string_mapss_decimate_by_) - f_status_t private_f_string_mapss_adjust(const f_array_length_t length, f_string_mapss_t * const mapss) { - - if (mapss->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < mapss->size; ++i) { - - status = private_f_string_maps_adjust(0, &mapss->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_adjust(mapss->size, length, sizeof(f_string_maps_t), (void **) & mapss->array); - if (F_status_is_error(status)) return status; - - mapss->size = length; - - if (mapss->used > mapss->size) { - mapss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_mapss_adjust_) || !defined(_di_f_string_mapss_decimate_by_) - -#if !defined(_di_f_string_mapss_decrease_by_) || !defined(_di_f_string_mapss_increase_) || !defined(_di_f_string_mapss_increase_by_) || !defined(_di_f_string_mapss_terminate_) || !defined(_di_f_string_mapss_terminate_after_) - f_status_t private_f_string_mapss_resize(const f_array_length_t length, f_string_mapss_t * const mapss) { - - if (mapss->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < mapss->size; ++i) { - - status = private_f_string_maps_resize(0, &mapss->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_resize(mapss->size, length, sizeof(f_string_maps_t), (void **) & mapss->array); - if (F_status_is_error(status)) return status; - - mapss->size = length; - - if (mapss->used > mapss->size) { - mapss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_mapss_decrease_by_) || !defined(_di_f_string_mapss_increase_) || !defined(_di_f_string_mapss_increase_by_) || !defined(_di_f_string_mapss_terminate_) || !defined(_di_f_string_mapss_terminate_after_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/private-map.h b/level_0/f_string/c/string/private-maps.h similarity index 60% rename from level_0/f_string/c/string/private-map.h rename to level_0/f_string/c/string/private-maps.h index c156172..e9ea424 100644 --- a/level_0/f_string/c/string/private-map.h +++ b/level_0/f_string/c/string/private-maps.h @@ -8,8 +8,8 @@ * These are provided for internal reduction in redundant code. * These should not be exposed/used outside of this project. */ -#ifndef _PRIVATE_F_string_map_h -#define _PRIVATE_F_string_map_h +#ifndef _PRIVATE_F_string_maps_h +#define _PRIVATE_F_string_maps_h #ifdef __cplusplus extern "C" { @@ -93,60 +93,8 @@ extern "C" { extern f_status_t private_f_string_maps_resize(const f_array_length_t length, f_string_maps_t * const maps) F_attribute_visibility_internal_d; #endif // !defined(_di_f_string_maps_decrease_by_) || !defined(_di_f_string_maps_increase_) || !defined(_di_f_string_maps_increase_by_) || !defined(_di_f_string_maps_terminate_) || !defined(_di_f_string_maps_terminate_after_) -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param mapss - * The mapss to adjust. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_adjust(). - * - * @see f_memory_adjust() - * @see f_string_mapss_adjust() - */ -#if !defined(_di_f_string_mapss_adjust_) || !defined(_di_f_string_mapss_decimate_by_) - extern f_status_t private_f_string_mapss_adjust(const f_array_length_t length, f_string_mapss_t * const mapss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_mapss_adjust_) || !defined(_di_f_string_mapss_decimate_by_) - -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param mapss - * The mapss to resize. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_memory_adjust() - * @see f_string_mapss_decrease_by() - * @see f_string_mapss_increase() - * @see f_string_mapss_increase_by() - * @see f_string_mapss_terminate() - * @see f_string_mapss_terminate_after() - */ -#if !defined(_di_f_string_mapss_decrease_by_) || !defined(_di_f_string_mapss_increase_) || !defined(_di_f_string_mapss_increase_by_) || !defined(_di_f_string_mapss_terminate_) || !defined(_di_f_string_mapss_terminate_after_) - extern f_status_t private_f_string_mapss_resize(const f_array_length_t length, f_string_mapss_t * const mapss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_mapss_decrease_by_) || !defined(_di_f_string_mapss_increase_) || !defined(_di_f_string_mapss_increase_by_) || !defined(_di_f_string_mapss_terminate_) || !defined(_di_f_string_mapss_terminate_after_) - #ifdef __cplusplus } // extern "C" #endif -#endif // _PRIVATE_F_string_map_h +#endif // _PRIVATE_F_string_maps_h diff --git a/level_0/f_string/c/string/private-mapss.c b/level_0/f_string/c/string/private-mapss.c new file mode 100644 index 0000000..e975fac --- /dev/null +++ b/level_0/f_string/c/string/private-mapss.c @@ -0,0 +1,69 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-dynamic.h" +#include "private-maps.h" +#include "private-mapss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_string_mapss_adjust_) || !defined(_di_f_string_mapss_decimate_by_) + f_status_t private_f_string_mapss_adjust(const f_array_length_t length, f_string_mapss_t * const mapss) { + + if (mapss->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < mapss->size; ++i) { + + status = private_f_string_maps_adjust(0, &mapss->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(mapss->size, length, sizeof(f_string_maps_t), (void **) & mapss->array); + if (F_status_is_error(status)) return status; + + mapss->size = length; + + if (mapss->used > mapss->size) { + mapss->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_mapss_adjust_) || !defined(_di_f_string_mapss_decimate_by_) + +#if !defined(_di_f_string_mapss_decrease_by_) || !defined(_di_f_string_mapss_increase_) || !defined(_di_f_string_mapss_increase_by_) || !defined(_di_f_string_mapss_terminate_) || !defined(_di_f_string_mapss_terminate_after_) + f_status_t private_f_string_mapss_resize(const f_array_length_t length, f_string_mapss_t * const mapss) { + + if (mapss->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < mapss->size; ++i) { + + status = private_f_string_maps_resize(0, &mapss->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(mapss->size, length, sizeof(f_string_maps_t), (void **) & mapss->array); + if (F_status_is_error(status)) return status; + + mapss->size = length; + + if (mapss->used > mapss->size) { + mapss->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_mapss_decrease_by_) || !defined(_di_f_string_mapss_increase_) || !defined(_di_f_string_mapss_increase_by_) || !defined(_di_f_string_mapss_terminate_) || !defined(_di_f_string_mapss_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/private-mapss.h b/level_0/f_string/c/string/private-mapss.h new file mode 100644 index 0000000..36deb45 --- /dev/null +++ b/level_0/f_string/c/string/private-mapss.h @@ -0,0 +1,74 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_string_mapss_h +#define _PRIVATE_F_string_mapss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param mapss + * The mapss to adjust. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_string_mapss_adjust() + */ +#if !defined(_di_f_string_mapss_adjust_) || !defined(_di_f_string_mapss_decimate_by_) + extern f_status_t private_f_string_mapss_adjust(const f_array_length_t length, f_string_mapss_t * const mapss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_mapss_adjust_) || !defined(_di_f_string_mapss_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param mapss + * The mapss to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_adjust() + * @see f_string_mapss_decrease_by() + * @see f_string_mapss_increase() + * @see f_string_mapss_increase_by() + * @see f_string_mapss_terminate() + * @see f_string_mapss_terminate_after() + */ +#if !defined(_di_f_string_mapss_decrease_by_) || !defined(_di_f_string_mapss_increase_) || !defined(_di_f_string_mapss_increase_by_) || !defined(_di_f_string_mapss_terminate_) || !defined(_di_f_string_mapss_terminate_after_) + extern f_status_t private_f_string_mapss_resize(const f_array_length_t length, f_string_mapss_t * const mapss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_mapss_decrease_by_) || !defined(_di_f_string_mapss_increase_) || !defined(_di_f_string_mapss_increase_by_) || !defined(_di_f_string_mapss_terminate_) || !defined(_di_f_string_mapss_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_string_mapss_h diff --git a/level_0/f_string/c/string/private-quantity.c b/level_0/f_string/c/string/private-quantitys.c similarity index 54% rename from level_0/f_string/c/string/private-quantity.c rename to level_0/f_string/c/string/private-quantitys.c index 9056663..7197d25 100644 --- a/level_0/f_string/c/string/private-quantity.c +++ b/level_0/f_string/c/string/private-quantitys.c @@ -1,6 +1,6 @@ #include "../string.h" #include "../private-string.h" -#include "private-quantity.h" +#include "private-quantitys.h" #ifdef __cplusplus extern "C" { @@ -64,62 +64,6 @@ extern "C" { } #endif // !defined(_di_f_string_quantitys_decrease_) || !defined(_di_f_string_quantitys_decrease_by_) || !defined(_di_f_string_quantitys_increase_) || !defined(_di_f_string_quantitys_increase_by_) || !defined(_di_f_string_quantitys_terminate_) || !defined(_di_f_string_quantitys_terminate_after_) -#if !defined(_di_f_string_quantityss_adjust_) || !defined(_di_f_string_quantityss_decimate_by_) - f_status_t private_f_string_quantityss_adjust(const f_array_length_t length, f_string_quantityss_t * const quantityss) { - - if (quantityss->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < quantityss->size; ++i) { - - status = private_f_string_quantitys_adjust(0, &quantityss->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_adjust(quantityss->size, length, sizeof(f_string_quantitys_t), (void **) & quantityss->array); - if (F_status_is_error(status)) return status; - - quantityss->size = length; - - if (quantityss->used > quantityss->size) { - quantityss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_quantityss_adjust_) || !defined(_di_f_string_quantityss_decimate_by_) - -#if !defined(_di_f_string_quantityss_decrease_) || !defined(_di_f_string_quantityss_decrease_by_) || !defined(_di_f_string_quantityss_increase_) || !defined(_di_f_string_quantityss_increase_by_) || !defined(_di_f_string_quantityss_terminate_) || !defined(_di_f_string_quantityss_terminate_after_) - f_status_t private_f_string_quantityss_resize(const f_array_length_t length, f_string_quantityss_t * const quantityss) { - - if (quantityss->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < quantityss->size; ++i) { - - status = private_f_string_quantitys_resize(0, &quantityss->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_resize(quantityss->size, length, sizeof(f_string_quantitys_t), (void **) & quantityss->array); - if (F_status_is_error(status)) return status; - - quantityss->size = length; - - if (quantityss->used > quantityss->size) { - quantityss->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_quantityss_decrease_) || !defined(_di_f_string_quantityss_decrease_by_) || !defined(_di_f_string_quantityss_increase_) || !defined(_di_f_string_quantityss_increase_by_) || !defined(_di_f_string_quantityss_terminate_) || !defined(_di_f_string_quantityss_terminate_after_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/private-quantity.h b/level_0/f_string/c/string/private-quantitys.h similarity index 60% rename from level_0/f_string/c/string/private-quantity.h rename to level_0/f_string/c/string/private-quantitys.h index 4ed3791..d3e2929 100644 --- a/level_0/f_string/c/string/private-quantity.h +++ b/level_0/f_string/c/string/private-quantitys.h @@ -8,8 +8,8 @@ * These are provided for internal reduction in redundant code. * These should not be exposed/used outside of this project. */ -#ifndef _PRIVATE_F_string_quantity_h -#define _PRIVATE_F_string_quantity_h +#ifndef _PRIVATE_F_string_quantitys_h +#define _PRIVATE_F_string_quantitys_h #ifdef __cplusplus extern "C" { @@ -93,60 +93,8 @@ extern "C" { extern f_status_t private_f_string_quantitys_resize(const f_array_length_t length, f_string_quantitys_t * const quantitys) F_attribute_visibility_internal_d; #endif // !defined(_di_f_string_quantitys_decrease_by_) || !defined(_di_f_string_quantitys_increase_) || !defined(_di_f_string_quantitys_increase_by_) || !defined(_di_f_string_quantitys_terminate_) || !defined(_di_f_string_quantitys_terminate_after_) -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param quantityss - * The quantityss to adjust. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_adjust(). - * - * @see f_memory_adjust() - * @see f_string_quantityss_adjust() - */ -#if !defined(_di_f_string_quantityss_adjust_) || !defined(_di_f_string_quantityss_decimate_by_) - extern f_status_t private_f_string_quantityss_adjust(const f_array_length_t length, f_string_quantityss_t * const quantityss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_quantityss_adjust_) || !defined(_di_f_string_quantityss_decimate_by_) - -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param quantityss - * The quantityss to resize. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_memory_adjust() - * @see f_string_quantityss_decrease_by() - * @see f_string_quantityss_increase() - * @see f_string_quantityss_increase_by() - * @see f_string_quantityss_terminate() - * @see f_string_quantityss_terminate_after() - */ -#if !defined(_di_f_string_quantityss_decrease_by_) || !defined(_di_f_string_quantityss_increase_) || !defined(_di_f_string_quantityss_increase_by_) || !defined(_di_f_string_quantityss_terminate_) || !defined(_di_f_string_quantityss_terminate_after_) - extern f_status_t private_f_string_quantityss_resize(const f_array_length_t length, f_string_quantityss_t * const quantityss) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_quantityss_decrease_by_) || !defined(_di_f_string_quantityss_increase_) || !defined(_di_f_string_quantityss_increase_by_) || !defined(_di_f_string_quantityss_terminate_) || !defined(_di_f_string_quantityss_terminate_after_) - #ifdef __cplusplus } // extern "C" #endif -#endif // _PRIVATE_F_string_quantity_h +#endif // _PRIVATE_F_string_quantitys_h diff --git a/level_0/f_string/c/string/private-quantityss.c b/level_0/f_string/c/string/private-quantityss.c new file mode 100644 index 0000000..18ac32e --- /dev/null +++ b/level_0/f_string/c/string/private-quantityss.c @@ -0,0 +1,68 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-quantitys.h" +#include "private-quantityss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_string_quantityss_adjust_) || !defined(_di_f_string_quantityss_decimate_by_) + f_status_t private_f_string_quantityss_adjust(const f_array_length_t length, f_string_quantityss_t * const quantityss) { + + if (quantityss->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < quantityss->size; ++i) { + + status = private_f_string_quantitys_adjust(0, &quantityss->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(quantityss->size, length, sizeof(f_string_quantitys_t), (void **) & quantityss->array); + if (F_status_is_error(status)) return status; + + quantityss->size = length; + + if (quantityss->used > quantityss->size) { + quantityss->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_quantityss_adjust_) || !defined(_di_f_string_quantityss_decimate_by_) + +#if !defined(_di_f_string_quantityss_decrease_) || !defined(_di_f_string_quantityss_decrease_by_) || !defined(_di_f_string_quantityss_increase_) || !defined(_di_f_string_quantityss_increase_by_) || !defined(_di_f_string_quantityss_terminate_) || !defined(_di_f_string_quantityss_terminate_after_) + f_status_t private_f_string_quantityss_resize(const f_array_length_t length, f_string_quantityss_t * const quantityss) { + + if (quantityss->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < quantityss->size; ++i) { + + status = private_f_string_quantitys_resize(0, &quantityss->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(quantityss->size, length, sizeof(f_string_quantitys_t), (void **) & quantityss->array); + if (F_status_is_error(status)) return status; + + quantityss->size = length; + + if (quantityss->used > quantityss->size) { + quantityss->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_quantityss_decrease_) || !defined(_di_f_string_quantityss_decrease_by_) || !defined(_di_f_string_quantityss_increase_) || !defined(_di_f_string_quantityss_increase_by_) || !defined(_di_f_string_quantityss_terminate_) || !defined(_di_f_string_quantityss_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/private-quantityss.h b/level_0/f_string/c/string/private-quantityss.h new file mode 100644 index 0000000..474dc38 --- /dev/null +++ b/level_0/f_string/c/string/private-quantityss.h @@ -0,0 +1,74 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_string_quantityss_h +#define _PRIVATE_F_string_quantityss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param quantityss + * The quantityss to adjust. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_string_quantityss_adjust() + */ +#if !defined(_di_f_string_quantityss_adjust_) || !defined(_di_f_string_quantityss_decimate_by_) + extern f_status_t private_f_string_quantityss_adjust(const f_array_length_t length, f_string_quantityss_t * const quantityss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_quantityss_adjust_) || !defined(_di_f_string_quantityss_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param quantityss + * The quantityss to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_adjust() + * @see f_string_quantityss_decrease_by() + * @see f_string_quantityss_increase() + * @see f_string_quantityss_increase_by() + * @see f_string_quantityss_terminate() + * @see f_string_quantityss_terminate_after() + */ +#if !defined(_di_f_string_quantityss_decrease_by_) || !defined(_di_f_string_quantityss_increase_) || !defined(_di_f_string_quantityss_increase_by_) || !defined(_di_f_string_quantityss_terminate_) || !defined(_di_f_string_quantityss_terminate_after_) + extern f_status_t private_f_string_quantityss_resize(const f_array_length_t length, f_string_quantityss_t * const quantityss) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_quantityss_decrease_by_) || !defined(_di_f_string_quantityss_increase_) || !defined(_di_f_string_quantityss_increase_by_) || !defined(_di_f_string_quantityss_terminate_) || !defined(_di_f_string_quantityss_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_string_quantityss_h diff --git a/level_0/f_string/c/string/private-range.c b/level_0/f_string/c/string/private-ranges.c similarity index 55% rename from level_0/f_string/c/string/private-range.c rename to level_0/f_string/c/string/private-ranges.c index 2091fa3..5a0758e 100644 --- a/level_0/f_string/c/string/private-range.c +++ b/level_0/f_string/c/string/private-ranges.c @@ -1,6 +1,6 @@ #include "../string.h" #include "../private-string.h" -#include "private-range.h" +#include "private-ranges.h" #ifdef __cplusplus extern "C" { @@ -64,62 +64,6 @@ extern "C" { } #endif // !defined(_di_f_string_ranges_decrease_by_) || !defined(_di_f_string_ranges_increase_) || !defined(_di_f_string_ranges_increase_by_) || !defined(_di_f_string_ranges_terminate_) || !defined(_di_f_string_ranges_terminate_after_) -#if !defined(_di_f_string_rangess_adjust_) || !defined(_di_f_string_rangess_decimate_by_) - f_status_t private_f_string_rangess_adjust(const f_array_length_t length, f_string_rangess_t * const rangess) { - - if (rangess->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < rangess->size; ++i) { - - status = private_f_string_ranges_adjust(0, &rangess->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_adjust(rangess->size, length, sizeof(f_string_ranges_t), (void **) & rangess->array); - if (F_status_is_error(status)) return status; - - rangess->size = length; - - if (rangess->used > rangess->size) { - rangess->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_rangess_adjust_) || !defined(_di_f_string_rangess_decimate_by_) - -#if !defined(_di_f_string_rangess_decrease_by_) || !defined(_di_f_string_rangess_increase_) || !defined(_di_f_string_rangess_increase_by_) || !defined(_di_f_string_rangess_terminate_) || !defined(_di_f_string_rangess_terminate_after_) - f_status_t private_f_string_rangess_resize(const f_array_length_t length, f_string_rangess_t * const rangess) { - - if (rangess->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < rangess->size; ++i) { - - status = private_f_string_ranges_resize(0, &rangess->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_resize(rangess->size, length, sizeof(f_string_ranges_t), (void **) & rangess->array); - if (F_status_is_error(status)) return status; - - rangess->size = length; - - if (rangess->used > rangess->size) { - rangess->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_rangess_decrease_by_) || !defined(_di_f_string_rangess_increase_) || !defined(_di_f_string_rangess_increase_by_) || !defined(_di_f_string_rangess_terminate_) || !defined(_di_f_string_rangess_terminate_after_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/private-range.h b/level_0/f_string/c/string/private-ranges.h similarity index 60% rename from level_0/f_string/c/string/private-range.h rename to level_0/f_string/c/string/private-ranges.h index 5229908..7c5d263 100644 --- a/level_0/f_string/c/string/private-range.h +++ b/level_0/f_string/c/string/private-ranges.h @@ -8,8 +8,8 @@ * These are provided for internal reduction in redundant code. * These should not be exposed/used outside of this project. */ -#ifndef _PRIVATE_F_string_range_h -#define _PRIVATE_F_string_range_h +#ifndef _PRIVATE_F_string_ranges_h +#define _PRIVATE_F_string_ranges_h #ifdef __cplusplus extern "C" { @@ -93,60 +93,8 @@ extern "C" { extern f_status_t private_f_string_ranges_resize(const f_array_length_t length, f_string_ranges_t * const ranges) F_attribute_visibility_internal_d; #endif // !defined(_di_f_string_ranges_decrease_by_) || !defined(_di_f_string_ranges_increase_) || !defined(_di_f_string_ranges_increase_by_) || !defined(_di_f_string_ranges_terminate_) || !defined(_di_f_string_ranges_terminate_after_) -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param rangess - * The rangess to adjust. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_adjust(). - * - * @see f_memory_adjust() - * @see f_string_rangess_adjust() - */ -#if !defined(_di_f_string_rangess_adjust_) || !defined(_di_f_string_rangess_decimate_by_) - extern f_status_t private_f_string_rangess_adjust(const f_array_length_t length, f_string_rangess_t * const rangess) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_rangess_adjust_) || !defined(_di_f_string_rangess_decimate_by_) - -/** - * Private implementation for resizing. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The new size to use. - * @param rangess - * The rangess to resize. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_memory_adjust() - * @see f_string_rangess_decrease_by() - * @see f_string_rangess_increase() - * @see f_string_rangess_increase_by() - * @see f_string_rangess_terminate() - * @see f_string_rangess_terminate_after() - */ -#if !defined(_di_f_string_rangess_decrease_by_) || !defined(_di_f_string_rangess_increase_) || !defined(_di_f_string_rangess_increase_by_) || !defined(_di_f_string_rangess_terminate_) || !defined(_di_f_string_rangess_terminate_after_) - extern f_status_t private_f_string_rangess_resize(const f_array_length_t length, f_string_rangess_t * const rangess) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_string_rangess_decrease_by_) || !defined(_di_f_string_rangess_increase_) || !defined(_di_f_string_rangess_increase_by_) || !defined(_di_f_string_rangess_terminate_) || !defined(_di_f_string_rangess_terminate_after_) - #ifdef __cplusplus } // extern "C" #endif -#endif // _PRIVATE_F_string_range_h +#endif // _PRIVATE_F_string_ranges_h diff --git a/level_0/f_string/c/string/private-rangess.c b/level_0/f_string/c/string/private-rangess.c new file mode 100644 index 0000000..1f84881 --- /dev/null +++ b/level_0/f_string/c/string/private-rangess.c @@ -0,0 +1,68 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-ranges.h" +#include "private-rangess.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_string_rangess_adjust_) || !defined(_di_f_string_rangess_decimate_by_) + f_status_t private_f_string_rangess_adjust(const f_array_length_t length, f_string_rangess_t * const rangess) { + + if (rangess->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < rangess->size; ++i) { + + status = private_f_string_ranges_adjust(0, &rangess->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(rangess->size, length, sizeof(f_string_ranges_t), (void **) & rangess->array); + if (F_status_is_error(status)) return status; + + rangess->size = length; + + if (rangess->used > rangess->size) { + rangess->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_rangess_adjust_) || !defined(_di_f_string_rangess_decimate_by_) + +#if !defined(_di_f_string_rangess_decrease_by_) || !defined(_di_f_string_rangess_increase_) || !defined(_di_f_string_rangess_increase_by_) || !defined(_di_f_string_rangess_terminate_) || !defined(_di_f_string_rangess_terminate_after_) + f_status_t private_f_string_rangess_resize(const f_array_length_t length, f_string_rangess_t * const rangess) { + + if (rangess->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < rangess->size; ++i) { + + status = private_f_string_ranges_resize(0, &rangess->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(rangess->size, length, sizeof(f_string_ranges_t), (void **) & rangess->array); + if (F_status_is_error(status)) return status; + + rangess->size = length; + + if (rangess->used > rangess->size) { + rangess->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_rangess_decrease_by_) || !defined(_di_f_string_rangess_increase_) || !defined(_di_f_string_rangess_increase_by_) || !defined(_di_f_string_rangess_terminate_) || !defined(_di_f_string_rangess_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/private-rangess.h b/level_0/f_string/c/string/private-rangess.h new file mode 100644 index 0000000..0c539f3 --- /dev/null +++ b/level_0/f_string/c/string/private-rangess.h @@ -0,0 +1,74 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_string_rangess_h +#define _PRIVATE_F_string_rangess_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param rangess + * The rangess to adjust. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_string_rangess_adjust() + */ +#if !defined(_di_f_string_rangess_adjust_) || !defined(_di_f_string_rangess_decimate_by_) + extern f_status_t private_f_string_rangess_adjust(const f_array_length_t length, f_string_rangess_t * const rangess) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_rangess_adjust_) || !defined(_di_f_string_rangess_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param rangess + * The rangess to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_adjust() + * @see f_string_rangess_decrease_by() + * @see f_string_rangess_increase() + * @see f_string_rangess_increase_by() + * @see f_string_rangess_terminate() + * @see f_string_rangess_terminate_after() + */ +#if !defined(_di_f_string_rangess_decrease_by_) || !defined(_di_f_string_rangess_increase_) || !defined(_di_f_string_rangess_increase_by_) || !defined(_di_f_string_rangess_terminate_) || !defined(_di_f_string_rangess_terminate_after_) + extern f_status_t private_f_string_rangess_resize(const f_array_length_t length, f_string_rangess_t * const rangess) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_rangess_decrease_by_) || !defined(_di_f_string_rangess_increase_) || !defined(_di_f_string_rangess_increase_by_) || !defined(_di_f_string_rangess_terminate_) || !defined(_di_f_string_rangess_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_string_rangess_h diff --git a/level_0/f_string/c/string/private-triple.c b/level_0/f_string/c/string/private-triples.c similarity index 66% rename from level_0/f_string/c/string/private-triple.c rename to level_0/f_string/c/string/private-triples.c index 3f46a3e..6237c8a 100644 --- a/level_0/f_string/c/string/private-triple.c +++ b/level_0/f_string/c/string/private-triples.c @@ -1,7 +1,7 @@ #include "../string.h" #include "../private-string.h" #include "private-dynamic.h" -#include "private-triple.h" +#include "private-triples.h" #ifdef __cplusplus extern "C" { @@ -111,62 +111,6 @@ extern "C" { } #endif // !defined(_di_f_string_triples_decrease_by_) || !defined(_di_f_string_triples_increase_) || !defined(_di_f_string_triples_increase_by_) || !defined(_di_f_string_triples_terminate_) || !defined(_di_f_string_triples_terminate_after_) -#if !defined(_di_f_string_tripless_adjust_) || !defined(_di_f_string_tripless_decimate_by_) - f_status_t private_f_string_tripless_adjust(const f_array_length_t length, f_string_tripless_t * const tripless) { - - if (tripless->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < tripless->size; ++i) { - - status = private_f_string_triples_adjust(0, &tripless->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_adjust(tripless->size, length, sizeof(f_string_triples_t), (void **) & tripless->array); - if (F_status_is_error(status)) return status; - - tripless->size = length; - - if (tripless->used > tripless->size) { - tripless->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_tripless_adjust_) || !defined(_di_f_string_tripless_decimate_by_) - -#if !defined(_di_f_string_tripless_decrease_by_) || !defined(_di_f_string_tripless_increase_) || !defined(_di_f_string_tripless_increase_by_) || !defined(_di_f_string_tripless_terminate_) || !defined(_di_f_string_tripless_terminate_after_) - f_status_t private_f_string_tripless_resize(const f_array_length_t length, f_string_tripless_t * const tripless) { - - if (tripless->used + length > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - f_status_t status = F_none; - - for (f_array_length_t i = length; i < tripless->size; ++i) { - - status = private_f_string_triples_resize(0, &tripless->array[i]); - if (F_status_is_error(status)) return status; - } // for - - status = f_memory_resize(tripless->size, length, sizeof(f_string_triples_t), (void **) & tripless->array); - if (F_status_is_error(status)) return status; - - tripless->size = length; - - if (tripless->used > tripless->size) { - tripless->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_string_tripless_decrease_by_) || !defined(_di_f_string_tripless_increase_) || !defined(_di_f_string_tripless_increase_by_) || !defined(_di_f_string_tripless_terminate_) || !defined(_di_f_string_tripless_terminate_after_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/private-triple.h b/level_0/f_string/c/string/private-triples.h similarity index 100% rename from level_0/f_string/c/string/private-triple.h rename to level_0/f_string/c/string/private-triples.h diff --git a/level_0/f_string/c/string/private-tripless.c b/level_0/f_string/c/string/private-tripless.c new file mode 100644 index 0000000..192335c --- /dev/null +++ b/level_0/f_string/c/string/private-tripless.c @@ -0,0 +1,69 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-dynamic.h" +#include "private-triples.h" +#include "private-tripless.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_string_tripless_adjust_) || !defined(_di_f_string_tripless_decimate_by_) + f_status_t private_f_string_tripless_adjust(const f_array_length_t length, f_string_tripless_t * const tripless) { + + if (tripless->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < tripless->size; ++i) { + + status = private_f_string_triples_adjust(0, &tripless->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_adjust(tripless->size, length, sizeof(f_string_triples_t), (void **) & tripless->array); + if (F_status_is_error(status)) return status; + + tripless->size = length; + + if (tripless->used > tripless->size) { + tripless->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_tripless_adjust_) || !defined(_di_f_string_tripless_decimate_by_) + +#if !defined(_di_f_string_tripless_decrease_by_) || !defined(_di_f_string_tripless_increase_) || !defined(_di_f_string_tripless_increase_by_) || !defined(_di_f_string_tripless_terminate_) || !defined(_di_f_string_tripless_terminate_after_) + f_status_t private_f_string_tripless_resize(const f_array_length_t length, f_string_tripless_t * const tripless) { + + if (tripless->used + length > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + f_status_t status = F_none; + + for (f_array_length_t i = length; i < tripless->size; ++i) { + + status = private_f_string_triples_resize(0, &tripless->array[i]); + if (F_status_is_error(status)) return status; + } // for + + status = f_memory_resize(tripless->size, length, sizeof(f_string_triples_t), (void **) & tripless->array); + if (F_status_is_error(status)) return status; + + tripless->size = length; + + if (tripless->used > tripless->size) { + tripless->used = length; + } + + return F_none; + } +#endif // !defined(_di_f_string_tripless_decrease_by_) || !defined(_di_f_string_tripless_increase_) || !defined(_di_f_string_tripless_increase_by_) || !defined(_di_f_string_tripless_terminate_) || !defined(_di_f_string_tripless_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/private-tripless.h b/level_0/f_string/c/string/private-tripless.h new file mode 100644 index 0000000..5d70807 --- /dev/null +++ b/level_0/f_string/c/string/private-tripless.h @@ -0,0 +1,74 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_string_tripless_h +#define _PRIVATE_F_string_tripless_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param tripless + * The tripless to adjust. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_adjust() + * @see f_string_tripless_adjust() + */ +#if !defined(_di_f_string_tripless_adjust_) || !defined(_di_f_string_tripless_decimate_by_) + extern f_status_t private_f_string_tripless_adjust(const f_array_length_t length, f_string_tripless_t * const tripless) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_tripless_adjust_) || !defined(_di_f_string_tripless_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param tripless + * The tripless to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the combined array is too large. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_adjust() + * @see f_string_tripless_decrease_by() + * @see f_string_tripless_increase() + * @see f_string_tripless_increase_by() + * @see f_string_tripless_terminate() + * @see f_string_tripless_terminate_after() + */ +#if !defined(_di_f_string_tripless_decrease_by_) || !defined(_di_f_string_tripless_increase_) || !defined(_di_f_string_tripless_increase_by_) || !defined(_di_f_string_tripless_terminate_) || !defined(_di_f_string_tripless_terminate_after_) + extern f_status_t private_f_string_tripless_resize(const f_array_length_t length, f_string_tripless_t * const tripless) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_string_tripless_decrease_by_) || !defined(_di_f_string_tripless_increase_) || !defined(_di_f_string_tripless_increase_by_) || !defined(_di_f_string_tripless_terminate_) || !defined(_di_f_string_tripless_terminate_after_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_string_tripless_h diff --git a/level_0/f_string/c/string/quantity.c b/level_0/f_string/c/string/quantity.c index 1a53234..19bfbd9 100644 --- a/level_0/f_string/c/string/quantity.c +++ b/level_0/f_string/c/string/quantity.c @@ -1,290 +1,10 @@ #include "../string.h" #include "../private-string.h" -#include "private-quantity.h" #ifdef __cplusplus extern "C" { #endif -#ifndef _di_f_string_quantitys_adjust_ - f_status_t f_string_quantitys_adjust(const f_array_length_t length, f_string_quantitys_t * const quantitys) { - #ifndef _di_level_0_parameter_checking_ - if (!quantitys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_quantitys_adjust(length, quantitys); - } -#endif // _di_f_string_quantitys_adjust_ - -#ifndef _di_f_string_quantitys_append_ - f_status_t f_string_quantitys_append(const f_string_quantity_t source, f_string_quantitys_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (destination->used + 1 > destination->size) { - const f_status_t status = private_f_string_quantitys_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].start = source.start; - destination->array[destination->used++].total = source.total; - - return F_none; - } -#endif // _di_f_string_quantitys_append_ - -#ifndef _di_f_string_quantitys_append_all_ - f_status_t f_string_quantitys_append_all(const f_string_quantitys_t source, f_string_quantitys_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - return private_f_string_quantitys_append_all(source, destination); - } -#endif // _di_f_string_quantitys_append_all_ - -#ifndef _di_f_string_quantitys_decimate_by_ - f_status_t f_string_quantitys_decimate_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys) { - #ifndef _di_level_0_parameter_checking_ - if (!quantitys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (quantitys->size > amount) { - return private_f_string_quantitys_adjust(quantitys->size - amount, quantitys); - } - - return private_f_string_quantitys_adjust(0, quantitys); - } -#endif // _di_f_string_quantitys_decimate_by_ - -#ifndef _di_f_string_quantitys_decrease_by_ - f_status_t f_string_quantitys_decrease_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys) { - #ifndef _di_level_0_parameter_checking_ - if (!quantitys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (quantitys->size > amount) { - return private_f_string_quantitys_resize(quantitys->size - amount, quantitys); - } - - return private_f_string_quantitys_resize(0, quantitys); - } -#endif // _di_f_string_quantitys_decrease_by_ - -#ifndef _di_f_string_quantitys_increase_ - f_status_t f_string_quantitys_increase(const f_array_length_t step, f_string_quantitys_t * const quantitys) { - #ifndef _di_level_0_parameter_checking_ - if (!quantitys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && quantitys->used + 1 > quantitys->size) { - f_array_length_t size = quantitys->used + step; - - if (size > F_array_length_t_size_d) { - if (quantitys->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_quantitys_resize(size, quantitys); - } - - return F_data_not; - } -#endif // _di_f_string_quantitys_increase_ - -#ifndef _di_f_string_quantitys_increase_by_ - f_status_t f_string_quantitys_increase_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys) { - #ifndef _di_level_0_parameter_checking_ - if (!quantitys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (quantitys->used + amount > quantitys->size) { - if (quantitys->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_quantitys_resize(quantitys->used + amount, quantitys); - } - - return F_data_not; - } -#endif // _di_f_string_quantitys_increase_by_ - -#ifndef _di_f_string_quantitys_resize_ - f_status_t f_string_quantitys_resize(const f_array_length_t length, f_string_quantitys_t * const quantitys) { - #ifndef _di_level_0_parameter_checking_ - if (!quantitys) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_quantitys_resize(length, quantitys); - } -#endif // _di_f_string_quantitys_resize_ - -#ifndef _di_f_string_quantityss_adjust_ - f_status_t f_string_quantityss_adjust(const f_array_length_t length, f_string_quantityss_t * const quantityss) { - #ifndef _di_level_0_parameter_checking_ - if (!quantityss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_quantityss_adjust(length, quantityss); - } -#endif // _di_f_string_quantityss_adjust_ - -#ifndef _di_f_string_quantityss_append_ - f_status_t f_string_quantityss_append(const f_string_quantitys_t source, f_string_quantityss_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_quantityss_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].used = 0; - - if (source.used) { - status = private_f_string_quantitys_append_all(source, &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // _di_f_string_quantityss_append_ - -#ifndef _di_f_string_quantityss_append_all_ - f_status_t f_string_quantityss_append_all(const f_string_quantityss_t source, f_string_quantityss_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_string_quantityss_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } - - for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { - - destination->array[destination->used].used = 0; - - if (source.array[i].used) { - status = private_f_string_quantitys_append_all(source.array[i], &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - } // for - - return F_none; - } -#endif // _di_f_string_quantityss_append_all_ - -#ifndef _di_f_string_quantityss_decimate_by_ - f_status_t f_string_quantityss_decimate_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss) { - #ifndef _di_level_0_parameter_checking_ - if (!quantityss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (quantityss->size > amount) { - return private_f_string_quantityss_adjust(quantityss->size - amount, quantityss); - } - - return private_f_string_quantityss_adjust(0, quantityss); - } -#endif // _di_f_string_quantityss_decimate_by_ - -#ifndef _di_f_string_quantityss_decrease_by_ - f_status_t f_string_quantityss_decrease_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss) { - #ifndef _di_level_0_parameter_checking_ - if (!quantityss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (quantityss->size > amount) { - return private_f_string_quantityss_resize(quantityss->size - amount, quantityss); - } - - return private_f_string_quantityss_resize(0, quantityss); - } -#endif // _di_f_string_quantityss_decrease_by_ - -#ifndef _di_f_string_quantityss_increase_ - f_status_t f_string_quantityss_increase(const f_array_length_t step, f_string_quantityss_t * const quantityss) { - #ifndef _di_level_0_parameter_checking_ - if (!quantityss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && quantityss->used + 1 > quantityss->size) { - f_array_length_t size = quantityss->used + step; - - if (size > F_array_length_t_size_d) { - if (quantityss->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_quantityss_resize(size, quantityss); - } - - return F_data_not; - } -#endif // _di_f_string_quantityss_increase_ - -#ifndef _di_f_string_quantityss_increase_by_ - f_status_t f_string_quantityss_increase_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss) { - #ifndef _di_level_0_parameter_checking_ - if (!quantityss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (quantityss->used + amount > quantityss->size) { - if (quantityss->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_quantityss_resize(quantityss->used + amount, quantityss); - } - - return F_data_not; - } -#endif // _di_f_string_quantityss_increase_by_ - -#ifndef _di_f_string_quantityss_resize_ - f_status_t f_string_quantityss_resize(const f_array_length_t length, f_string_quantityss_t * const quantityss) { - #ifndef _di_level_0_parameter_checking_ - if (!quantityss) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_quantityss_resize(length, quantityss); - } -#endif // _di_f_string_quantityss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/quantity.h b/level_0/f_string/c/string/quantity.h index 0bb14d2..c8fc152 100644 --- a/level_0/f_string/c/string/quantity.h +++ b/level_0/f_string/c/string/quantity.h @@ -43,422 +43,6 @@ extern "C" { quantity.total = 0; #endif // _di_f_string_quantity_t_ -/** - * An array of string quantitys. - * - * array: the array of string quantitys. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_quantitys_t_ - typedef struct { - f_string_quantity_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_quantitys_t; - - #define f_string_quantitys_t_initialize { 0, 0, 0 } - - #define macro_f_string_quantitys_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_quantitys_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_quantitys_t_clear(quantitys) macro_f_memory_structure_clear(quantitys) - - #define macro_f_string_quantitys_t_resize(status, quantitys, length) status = f_string_quantitys_resize(length, &quantitys); - #define macro_f_string_quantitys_t_adjust(status, quantitys, length) status = f_string_quantitys_adjust(length, &quantitys); - - #define macro_f_string_quantitys_t_delete_simple(quantitys) f_string_quantitys_resize(0, &quantitys); - #define macro_f_string_quantitys_t_destroy_simple(quantitys) f_string_quantitys_adjust(0, &quantitys); - - #define macro_f_string_quantitys_t_increase(status, step, quantitys) status = f_string_quantitys_increase(step, &quantitys); - #define macro_f_string_quantitys_t_increase_by(status, quantitys, amount) status = f_string_quantitys_increase_by(amount, &quantitys); - #define macro_f_string_quantitys_t_decrease_by(status, quantitys, amount) status = f_string_quantitys_decrease_by(amount, &quantitys); - #define macro_f_string_quantitys_t_decimate_by(status, quantitys, amount) status = f_string_quantitys_decimate_by(amount, &quantitys); -#endif // _di_f_string_quantitys_t_ - -/** - * This holds an array of f_string_quantitys_t. - * - * array: The array of quantitys arrays. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_string_quantityss_t_ - typedef struct { - f_string_quantitys_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_quantityss_t; - - #define f_string_quantityss_t_initialize { 0, 0, 0 } - - #define macro_f_string_quantityss_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_quantityss_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_quantityss_t_clear(quantityss) macro_f_memory_structures_clear(quantityss) - - #define macro_f_string_quantityss_t_resize(status, quantityss, length) status = f_string_quantityss_resize(length, &quantityss); - #define macro_f_string_quantityss_t_adjust(status, quantityss, length) status = f_string_quantityss_adjust(length, &quantityss); - - #define macro_f_string_quantityss_t_delete_simple(quantityss) f_string_quantityss_resize(0, &quantityss); - #define macro_f_string_quantityss_t_destroy_simple(quantityss) f_string_quantityss_adjust(0, &quantityss); - - #define macro_f_string_quantityss_t_increase(status, step, quantityss) status = f_string_quantityss_increase(step, &quantityss); - #define macro_f_string_quantityss_t_increase_by(status, quantityss, amount) status = f_string_quantityss_increase_by(amount, &quantityss); - #define macro_f_string_quantityss_t_decrease_by(status, quantityss, amount) status = f_string_quantityss_decrease_by(amount, &quantityss); - #define macro_f_string_quantityss_t_decimate_by(status, quantityss, amount) status = f_string_quantityss_decimate_by(amount, &quantityss); -#endif // _di_f_string_quantityss_t_ - -/** - * Resize the string quantitys array. - * - * @param length - * The new size to use. - * @param quantitys - * The string quantitys array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantitys_adjust_ - extern f_status_t f_string_quantitys_adjust(const f_array_length_t length, f_string_quantitys_t * const quantitys); -#endif // _di_f_string_quantitys_adjust_ - -/** - * Append the single source quantity onto the destination. - * - * @param source - * The source quantity to append. - * @param destination - * The destination quantitys the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantitys_append_ - extern f_status_t f_string_quantitys_append(const f_string_quantity_t source, f_string_quantitys_t * const destination); -#endif // _di_f_string_quantitys_append_ - -/** - * Append the source quantitys onto the destination. - * - * @param source - * The source quantitys to append. - * @param destination - * The destination quantitys the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantitys_append_all_ - extern f_status_t f_string_quantitys_append_all(const f_string_quantitys_t source, f_string_quantitys_t * const destination); -#endif // _di_f_string_quantitys_append_all_ - -/** - * Resize the string quantitys 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 decimate the size by. - * @param quantitys - * The string quantitys array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantitys_decimate_by_ - extern f_status_t f_string_quantitys_decimate_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys); -#endif // _di_f_string_quantitys_decimate_by_ - -/** - * Resize the string quantitys 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 quantitys - * The string quantitys array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantitys_decrease_by_ - extern f_status_t f_string_quantitys_decrease_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys); -#endif // _di_f_string_quantitys_decrease_by_ - -/** - * Increase the size of the string quantitys 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param quantitys - * The string quantitys array to resize. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantitys_increase_ - extern f_status_t f_string_quantitys_increase(const f_array_length_t step, f_string_quantitys_t * const quantitys); -#endif // _di_f_string_quantitys_increase_ - -/** - * Resize the string quantitys 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_d). - * 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 quantitys - * The string quantitys array to resize. - * - * @return - * F_none on success. - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantitys_increase_by_ - extern f_status_t f_string_quantitys_increase_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys); -#endif // _di_f_string_quantitys_increase_by_ - -/** - * Resize the string quantitys array. - * - * @param length - * The new size to use. - * @param quantitys - * The string quantitys array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantitys_resize_ - extern f_status_t f_string_quantitys_resize(const f_array_length_t length, f_string_quantitys_t * const quantitys); -#endif // _di_f_string_quantitys_resize_ - -/** - * Resize the string quantityss array. - * - * @param length - * The new size to use. - * @param quantityss - * The string quantityss array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantityss_adjust_ - extern f_status_t f_string_quantityss_adjust(const f_array_length_t length, f_string_quantityss_t * const quantityss); -#endif // _di_f_string_quantityss_adjust_ - -/** - * Append the single source quantitys onto the destination. - * - * @param source - * The source quantitys to append. - * @param destination - * The destination quantityss the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantityss_append_ - extern f_status_t f_string_quantityss_append(const f_string_quantitys_t source, f_string_quantityss_t * const destination); -#endif // _di_f_string_quantityss_append_ - -/** - * Append the source quantityss onto the destination. - * - * @param source - * The source quantityss to append. - * @param destination - * The destination quantityss the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantityss_append_all_ - extern f_status_t f_string_quantityss_append_all(const f_string_quantityss_t source, f_string_quantityss_t * const destination); -#endif // _di_f_string_quantityss_append_all_ - -/** - * Resize the string quantityss 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 decimate the size by. - * @param quantityss - * The string quantityss array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantityss_decimate_by_ - extern f_status_t f_string_quantityss_decimate_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss); -#endif // _di_f_string_quantityss_decimate_by_ - -/** - * Resize the string quantityss 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 quantityss - * The string quantityss array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantityss_decrease_by_ - extern f_status_t f_string_quantityss_decrease_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss); -#endif // _di_f_string_quantityss_decrease_by_ - -/** - * Increase the size of the string quantityss 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param quantityss - * The string quantityss array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantityss_increase_ - extern f_status_t f_string_quantityss_increase(const f_array_length_t step, f_string_quantityss_t * const quantityss); -#endif // _di_f_string_quantityss_increase_ - -/** - * Resize the string quantityss 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_d). - * 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 quantityss - * The string quantityss array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantityss_increase_by_ - extern f_status_t f_string_quantityss_increase_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss); -#endif // _di_f_string_quantityss_increase_by_ - -/** - * Resize the string quantityss array. - * - * @param length - * The new size to use. - * @param quantityss - * The string quantityss array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_quantityss_resize_ - extern f_status_t f_string_quantityss_resize(const f_array_length_t length, f_string_quantityss_t * const quantityss); -#endif // _di_f_string_quantityss_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/quantitys.c b/level_0/f_string/c/string/quantitys.c new file mode 100644 index 0000000..64f3a58 --- /dev/null +++ b/level_0/f_string/c/string/quantitys.c @@ -0,0 +1,137 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-quantitys.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_quantitys_adjust_ + f_status_t f_string_quantitys_adjust(const f_array_length_t length, f_string_quantitys_t * const quantitys) { + #ifndef _di_level_0_parameter_checking_ + if (!quantitys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_quantitys_adjust(length, quantitys); + } +#endif // _di_f_string_quantitys_adjust_ + +#ifndef _di_f_string_quantitys_append_ + f_status_t f_string_quantitys_append(const f_string_quantity_t source, f_string_quantitys_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (destination->used + 1 > destination->size) { + const f_status_t status = private_f_string_quantitys_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].start = source.start; + destination->array[destination->used++].total = source.total; + + return F_none; + } +#endif // _di_f_string_quantitys_append_ + +#ifndef _di_f_string_quantitys_append_all_ + f_status_t f_string_quantitys_append_all(const f_string_quantitys_t source, f_string_quantitys_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + return private_f_string_quantitys_append_all(source, destination); + } +#endif // _di_f_string_quantitys_append_all_ + +#ifndef _di_f_string_quantitys_decimate_by_ + f_status_t f_string_quantitys_decimate_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys) { + #ifndef _di_level_0_parameter_checking_ + if (!quantitys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (quantitys->size > amount) { + return private_f_string_quantitys_adjust(quantitys->size - amount, quantitys); + } + + return private_f_string_quantitys_adjust(0, quantitys); + } +#endif // _di_f_string_quantitys_decimate_by_ + +#ifndef _di_f_string_quantitys_decrease_by_ + f_status_t f_string_quantitys_decrease_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys) { + #ifndef _di_level_0_parameter_checking_ + if (!quantitys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (quantitys->size > amount) { + return private_f_string_quantitys_resize(quantitys->size - amount, quantitys); + } + + return private_f_string_quantitys_resize(0, quantitys); + } +#endif // _di_f_string_quantitys_decrease_by_ + +#ifndef _di_f_string_quantitys_increase_ + f_status_t f_string_quantitys_increase(const f_array_length_t step, f_string_quantitys_t * const quantitys) { + #ifndef _di_level_0_parameter_checking_ + if (!quantitys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && quantitys->used + 1 > quantitys->size) { + f_array_length_t size = quantitys->used + step; + + if (size > F_array_length_t_size_d) { + if (quantitys->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_quantitys_resize(size, quantitys); + } + + return F_data_not; + } +#endif // _di_f_string_quantitys_increase_ + +#ifndef _di_f_string_quantitys_increase_by_ + f_status_t f_string_quantitys_increase_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys) { + #ifndef _di_level_0_parameter_checking_ + if (!quantitys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (quantitys->used + amount > quantitys->size) { + if (quantitys->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_quantitys_resize(quantitys->used + amount, quantitys); + } + + return F_data_not; + } +#endif // _di_f_string_quantitys_increase_by_ + +#ifndef _di_f_string_quantitys_resize_ + f_status_t f_string_quantitys_resize(const f_array_length_t length, f_string_quantitys_t * const quantitys) { + #ifndef _di_level_0_parameter_checking_ + if (!quantitys) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_quantitys_resize(length, quantitys); + } +#endif // _di_f_string_quantitys_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/quantitys.h b/level_0/f_string/c/string/quantitys.h new file mode 100644 index 0000000..d6ade2f --- /dev/null +++ b/level_0/f_string/c/string/quantitys.h @@ -0,0 +1,230 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines quantity string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_quantitys_h +#define _F_string_quantitys_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of string quantitys. + * + * array: the array of string quantitys. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_quantitys_t_ + typedef struct { + f_string_quantity_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_quantitys_t; + + #define f_string_quantitys_t_initialize { 0, 0, 0 } + + #define macro_f_string_quantitys_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_quantitys_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_quantitys_t_clear(quantitys) macro_f_memory_structure_clear(quantitys) + + #define macro_f_string_quantitys_t_resize(status, quantitys, length) status = f_string_quantitys_resize(length, &quantitys); + #define macro_f_string_quantitys_t_adjust(status, quantitys, length) status = f_string_quantitys_adjust(length, &quantitys); + + #define macro_f_string_quantitys_t_delete_simple(quantitys) f_string_quantitys_resize(0, &quantitys); + #define macro_f_string_quantitys_t_destroy_simple(quantitys) f_string_quantitys_adjust(0, &quantitys); + + #define macro_f_string_quantitys_t_increase(status, step, quantitys) status = f_string_quantitys_increase(step, &quantitys); + #define macro_f_string_quantitys_t_increase_by(status, quantitys, amount) status = f_string_quantitys_increase_by(amount, &quantitys); + #define macro_f_string_quantitys_t_decrease_by(status, quantitys, amount) status = f_string_quantitys_decrease_by(amount, &quantitys); + #define macro_f_string_quantitys_t_decimate_by(status, quantitys, amount) status = f_string_quantitys_decimate_by(amount, &quantitys); +#endif // _di_f_string_quantitys_t_ + +/** + * Resize the string quantitys array. + * + * @param length + * The new size to use. + * @param quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_adjust_ + extern f_status_t f_string_quantitys_adjust(const f_array_length_t length, f_string_quantitys_t * const quantitys); +#endif // _di_f_string_quantitys_adjust_ + +/** + * Append the single source quantity onto the destination. + * + * @param source + * The source quantity to append. + * @param destination + * The destination quantitys the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_append_ + extern f_status_t f_string_quantitys_append(const f_string_quantity_t source, f_string_quantitys_t * const destination); +#endif // _di_f_string_quantitys_append_ + +/** + * Append the source quantitys onto the destination. + * + * @param source + * The source quantitys to append. + * @param destination + * The destination quantitys the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_append_all_ + extern f_status_t f_string_quantitys_append_all(const f_string_quantitys_t source, f_string_quantitys_t * const destination); +#endif // _di_f_string_quantitys_append_all_ + +/** + * Resize the string quantitys 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 decimate the size by. + * @param quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_decimate_by_ + extern f_status_t f_string_quantitys_decimate_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys); +#endif // _di_f_string_quantitys_decimate_by_ + +/** + * Resize the string quantitys 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 quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_decrease_by_ + extern f_status_t f_string_quantitys_decrease_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys); +#endif // _di_f_string_quantitys_decrease_by_ + +/** + * Increase the size of the string quantitys 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_increase_ + extern f_status_t f_string_quantitys_increase(const f_array_length_t step, f_string_quantitys_t * const quantitys); +#endif // _di_f_string_quantitys_increase_ + +/** + * Resize the string quantitys 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_d). + * 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 quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_increase_by_ + extern f_status_t f_string_quantitys_increase_by(const f_array_length_t amount, f_string_quantitys_t * const quantitys); +#endif // _di_f_string_quantitys_increase_by_ + +/** + * Resize the string quantitys array. + * + * @param length + * The new size to use. + * @param quantitys + * The string quantitys array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_resize_ + extern f_status_t f_string_quantitys_resize(const f_array_length_t length, f_string_quantitys_t * const quantitys); +#endif // _di_f_string_quantitys_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_quantitys_h diff --git a/level_0/f_string/c/string/quantityss.c b/level_0/f_string/c/string/quantityss.c new file mode 100644 index 0000000..7d09f4e --- /dev/null +++ b/level_0/f_string/c/string/quantityss.c @@ -0,0 +1,165 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-quantitys.h" +#include "private-quantityss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_quantityss_adjust_ + f_status_t f_string_quantityss_adjust(const f_array_length_t length, f_string_quantityss_t * const quantityss) { + #ifndef _di_level_0_parameter_checking_ + if (!quantityss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_quantityss_adjust(length, quantityss); + } +#endif // _di_f_string_quantityss_adjust_ + +#ifndef _di_f_string_quantityss_append_ + f_status_t f_string_quantityss_append(const f_string_quantitys_t source, f_string_quantityss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_quantityss_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].used = 0; + + if (source.used) { + status = private_f_string_quantitys_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_quantityss_append_ + +#ifndef _di_f_string_quantityss_append_all_ + f_status_t f_string_quantityss_append_all(const f_string_quantityss_t source, f_string_quantityss_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + source.used > destination->size) { + status = private_f_string_quantityss_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].used = 0; + + if (source.array[i].used) { + status = private_f_string_quantitys_append_all(source.array[i], &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + } // for + + return F_none; + } +#endif // _di_f_string_quantityss_append_all_ + +#ifndef _di_f_string_quantityss_decimate_by_ + f_status_t f_string_quantityss_decimate_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss) { + #ifndef _di_level_0_parameter_checking_ + if (!quantityss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (quantityss->size > amount) { + return private_f_string_quantityss_adjust(quantityss->size - amount, quantityss); + } + + return private_f_string_quantityss_adjust(0, quantityss); + } +#endif // _di_f_string_quantityss_decimate_by_ + +#ifndef _di_f_string_quantityss_decrease_by_ + f_status_t f_string_quantityss_decrease_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss) { + #ifndef _di_level_0_parameter_checking_ + if (!quantityss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (quantityss->size > amount) { + return private_f_string_quantityss_resize(quantityss->size - amount, quantityss); + } + + return private_f_string_quantityss_resize(0, quantityss); + } +#endif // _di_f_string_quantityss_decrease_by_ + +#ifndef _di_f_string_quantityss_increase_ + f_status_t f_string_quantityss_increase(const f_array_length_t step, f_string_quantityss_t * const quantityss) { + #ifndef _di_level_0_parameter_checking_ + if (!quantityss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && quantityss->used + 1 > quantityss->size) { + f_array_length_t size = quantityss->used + step; + + if (size > F_array_length_t_size_d) { + if (quantityss->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_quantityss_resize(size, quantityss); + } + + return F_data_not; + } +#endif // _di_f_string_quantityss_increase_ + +#ifndef _di_f_string_quantityss_increase_by_ + f_status_t f_string_quantityss_increase_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss) { + #ifndef _di_level_0_parameter_checking_ + if (!quantityss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (quantityss->used + amount > quantityss->size) { + if (quantityss->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_quantityss_resize(quantityss->used + amount, quantityss); + } + + return F_data_not; + } +#endif // _di_f_string_quantityss_increase_by_ + +#ifndef _di_f_string_quantityss_resize_ + f_status_t f_string_quantityss_resize(const f_array_length_t length, f_string_quantityss_t * const quantityss) { + #ifndef _di_level_0_parameter_checking_ + if (!quantityss) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_quantityss_resize(length, quantityss); + } +#endif // _di_f_string_quantityss_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/quantityss.h b/level_0/f_string/c/string/quantityss.h new file mode 100644 index 0000000..025880f --- /dev/null +++ b/level_0/f_string/c/string/quantityss.h @@ -0,0 +1,232 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines quantity string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_quantityss_h +#define _F_string_quantityss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * This holds an array of f_string_quantitys_t. + * + * array: The array of quantitys arrays. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_string_quantityss_t_ + typedef struct { + f_string_quantitys_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_quantityss_t; + + #define f_string_quantityss_t_initialize { 0, 0, 0 } + + #define macro_f_string_quantityss_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_quantityss_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_quantityss_t_clear(quantityss) macro_f_memory_structures_clear(quantityss) + + #define macro_f_string_quantityss_t_resize(status, quantityss, length) status = f_string_quantityss_resize(length, &quantityss); + #define macro_f_string_quantityss_t_adjust(status, quantityss, length) status = f_string_quantityss_adjust(length, &quantityss); + + #define macro_f_string_quantityss_t_delete_simple(quantityss) f_string_quantityss_resize(0, &quantityss); + #define macro_f_string_quantityss_t_destroy_simple(quantityss) f_string_quantityss_adjust(0, &quantityss); + + #define macro_f_string_quantityss_t_increase(status, step, quantityss) status = f_string_quantityss_increase(step, &quantityss); + #define macro_f_string_quantityss_t_increase_by(status, quantityss, amount) status = f_string_quantityss_increase_by(amount, &quantityss); + #define macro_f_string_quantityss_t_decrease_by(status, quantityss, amount) status = f_string_quantityss_decrease_by(amount, &quantityss); + #define macro_f_string_quantityss_t_decimate_by(status, quantityss, amount) status = f_string_quantityss_decimate_by(amount, &quantityss); +#endif // _di_f_string_quantityss_t_ + +/** + * Resize the string quantityss array. + * + * @param length + * The new size to use. + * @param quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_adjust_ + extern f_status_t f_string_quantityss_adjust(const f_array_length_t length, f_string_quantityss_t * const quantityss); +#endif // _di_f_string_quantityss_adjust_ + +/** + * Append the single source quantitys onto the destination. + * + * @param source + * The source quantitys to append. + * @param destination + * The destination quantityss the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_append_ + extern f_status_t f_string_quantityss_append(const f_string_quantitys_t source, f_string_quantityss_t * const destination); +#endif // _di_f_string_quantityss_append_ + +/** + * Append the source quantityss onto the destination. + * + * @param source + * The source quantityss to append. + * @param destination + * The destination quantityss the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_append_all_ + extern f_status_t f_string_quantityss_append_all(const f_string_quantityss_t source, f_string_quantityss_t * const destination); +#endif // _di_f_string_quantityss_append_all_ + +/** + * Resize the string quantityss 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 decimate the size by. + * @param quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_decimate_by_ + extern f_status_t f_string_quantityss_decimate_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss); +#endif // _di_f_string_quantityss_decimate_by_ + +/** + * Resize the string quantityss 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 quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_decrease_by_ + extern f_status_t f_string_quantityss_decrease_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss); +#endif // _di_f_string_quantityss_decrease_by_ + +/** + * Increase the size of the string quantityss 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_increase_ + extern f_status_t f_string_quantityss_increase(const f_array_length_t step, f_string_quantityss_t * const quantityss); +#endif // _di_f_string_quantityss_increase_ + +/** + * Resize the string quantityss 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_d). + * 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 quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_increase_by_ + extern f_status_t f_string_quantityss_increase_by(const f_array_length_t amount, f_string_quantityss_t * const quantityss); +#endif // _di_f_string_quantityss_increase_by_ + +/** + * Resize the string quantityss array. + * + * @param length + * The new size to use. + * @param quantityss + * The string quantityss array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_resize_ + extern f_status_t f_string_quantityss_resize(const f_array_length_t length, f_string_quantityss_t * const quantityss); +#endif // _di_f_string_quantityss_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_quantityss_h diff --git a/level_0/f_string/c/string/range.c b/level_0/f_string/c/string/range.c index fc9fa28..f5d0dad 100644 --- a/level_0/f_string/c/string/range.c +++ b/level_0/f_string/c/string/range.c @@ -1,301 +1,11 @@ #include "../string.h" #include "../private-string.h" -#include "private-range.h" +#include "private-ranges.h" #ifdef __cplusplus extern "C" { #endif -#ifndef _di_f_string_ranges_adjust_ - f_status_t f_string_ranges_adjust(const f_array_length_t length, f_string_ranges_t * const ranges) { - #ifndef _di_level_0_parameter_checking_ - if (!ranges) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_ranges_adjust(length, ranges); - } -#endif // _di_f_string_ranges_adjust_ - -#ifndef _di_f_string_ranges_append_ - f_status_t f_string_ranges_append(const f_string_range_t source, f_string_ranges_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (destination->used + 1 > destination->size) { - const f_status_t status = private_f_string_ranges_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].start = source.start; - destination->array[destination->used++].stop = source.stop; - - return F_none; - } -#endif // _di_f_string_ranges_append_ - -#ifndef _di_f_string_ranges_append_all_ - f_status_t f_string_ranges_append_all(const f_string_ranges_t source, f_string_ranges_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - if (destination->used + source.used > destination->size) { - const f_status_t status = private_f_string_ranges_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } - - for (f_array_length_t i = 0; i < source.used; ++i) { - - destination->array[destination->used].start = source.array[i].start; - destination->array[destination->used++].stop = source.array[i].stop; - } // for - - return F_none; - } -#endif // _di_f_string_ranges_append_all_ - -#ifndef _di_f_string_ranges_decimate_by_ - f_status_t f_string_ranges_decimate_by(const f_array_length_t amount, f_string_ranges_t * const ranges) { - #ifndef _di_level_0_parameter_checking_ - if (!ranges) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (ranges->size > amount) { - return private_f_string_ranges_adjust(ranges->size - amount, ranges); - } - - return private_f_string_ranges_adjust(0, ranges); - } -#endif // _di_f_string_ranges_decimate_by_ - -#ifndef _di_f_string_ranges_decrease_by_ - f_status_t f_string_ranges_decrease_by(const f_array_length_t amount, f_string_ranges_t * const ranges) { - #ifndef _di_level_0_parameter_checking_ - if (!ranges) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (ranges->size > amount) { - return private_f_string_ranges_resize(ranges->size - amount, ranges); - } - - return private_f_string_ranges_resize(0, ranges); - } -#endif // _di_f_string_ranges_decrease_by_ - -#ifndef _di_f_string_ranges_increase_ - f_status_t f_string_ranges_increase(const f_array_length_t step, f_string_ranges_t * const ranges) { - #ifndef _di_level_0_parameter_checking_ - if (!ranges) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && ranges->used + 1 > ranges->size) { - f_array_length_t size = ranges->used + step; - - if (size > F_array_length_t_size_d) { - if (ranges->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_ranges_resize(size, ranges); - } - - return F_data_not; - } -#endif // _di_f_string_ranges_increase_ - -#ifndef _di_f_string_ranges_increase_by_ - f_status_t f_string_ranges_increase_by(const f_array_length_t amount, f_string_ranges_t * const ranges) { - #ifndef _di_level_0_parameter_checking_ - if (!ranges) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (ranges->used + amount > ranges->size) { - if (ranges->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_ranges_resize(ranges->used + amount, ranges); - } - - return F_data_not; - } -#endif // _di_f_string_ranges_increase_by_ - -#ifndef _di_f_string_ranges_resize_ - f_status_t f_string_ranges_resize(const f_array_length_t length, f_string_ranges_t * const ranges) { - #ifndef _di_level_0_parameter_checking_ - if (!ranges) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_ranges_resize(length, ranges); - } -#endif // _di_f_string_ranges_resize_ - -#ifndef _di_f_string_rangess_adjust_ - f_status_t f_string_rangess_adjust(const f_array_length_t length, f_string_rangess_t * const rangess) { - #ifndef _di_level_0_parameter_checking_ - if (!rangess) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_rangess_adjust(length, rangess); - } -#endif // _di_f_string_rangess_adjust_ - -#ifndef _di_f_string_rangess_append_ - f_status_t f_string_rangess_append(const f_string_ranges_t source, f_string_rangess_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_rangess_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].used = 0; - - if (source.used) { - status = private_f_string_ranges_append_all(source, &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // _di_f_string_rangess_append_ - -#ifndef _di_f_string_rangess_append_all_ - f_status_t f_string_rangess_append_all(const f_string_rangess_t source, f_string_rangess_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_string_rangess_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } - - for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { - - destination->array[destination->used].used = 0; - - if (source.array[i].used) { - status = private_f_string_ranges_append_all(source.array[i], &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - } // for - - return F_none; - } -#endif // _di_f_string_rangess_append_all_ - -#ifndef _di_f_string_rangess_decimate_by_ - f_status_t f_string_rangess_decimate_by(const f_array_length_t amount, f_string_rangess_t * const rangess) { - #ifndef _di_level_0_parameter_checking_ - if (!rangess) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (rangess->size > amount) { - return private_f_string_rangess_adjust(rangess->size - amount, rangess); - } - - return private_f_string_rangess_adjust(0, rangess); - } -#endif // _di_f_string_rangess_decimate_by_ - -#ifndef _di_f_string_rangess_decrease_by_ - f_status_t f_string_rangess_decrease_by(const f_array_length_t amount, f_string_rangess_t * const rangess) { - #ifndef _di_level_0_parameter_checking_ - if (!rangess) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (rangess->size > amount) { - return private_f_string_rangess_resize(rangess->size - amount, rangess); - } - - return private_f_string_rangess_resize(0, rangess); - } -#endif // _di_f_string_rangess_decrease_by_ - -#ifndef _di_f_string_rangess_increase_ - f_status_t f_string_rangess_increase(const f_array_length_t step, f_string_rangess_t * const rangess) { - #ifndef _di_level_0_parameter_checking_ - if (!rangess) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && rangess->used + 1 > rangess->size) { - f_array_length_t size = rangess->used + step; - - if (size > F_array_length_t_size_d) { - if (rangess->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_rangess_resize(size, rangess); - } - - return F_data_not; - } -#endif // _di_f_string_rangess_increase_ - -#ifndef _di_f_string_rangess_increase_by_ - f_status_t f_string_rangess_increase_by(const f_array_length_t amount, f_string_rangess_t * const rangess) { - #ifndef _di_level_0_parameter_checking_ - if (!rangess) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (rangess->used + amount > rangess->size) { - if (rangess->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_rangess_resize(rangess->used + amount, rangess); - } - - return F_data_not; - } -#endif // _di_f_string_rangess_increase_by_ - -#ifndef _di_f_string_rangess_resize_ - f_status_t f_string_rangess_resize(const f_array_length_t length, f_string_rangess_t * const rangess) { - #ifndef _di_level_0_parameter_checking_ - if (!rangess) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_rangess_resize(length, rangess); - } -#endif // _di_f_string_rangess_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/range.h b/level_0/f_string/c/string/range.h index 4544808..bc6f818 100644 --- a/level_0/f_string/c/string/range.h +++ b/level_0/f_string/c/string/range.h @@ -42,425 +42,6 @@ extern "C" { range.stop = 0; #endif // _di_f_string_range_t_ -/** - * An array of string ranges. - * - * array: the array of string ranges. - * size: total amount of allocated space. - * used: total number of allocated spaces used. - */ -#ifndef _di_f_string_ranges_t_ - typedef struct { - f_string_range_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_ranges_t; - - #define f_string_ranges_t_initialize { 0, 0, 0 } - - #define macro_f_string_ranges_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_ranges_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_ranges_t_clear(ranges) macro_f_memory_structure_clear(ranges) - - #define macro_f_string_ranges_t_resize(status, ranges, length) status = f_string_ranges_resize(length, &ranges); - #define macro_f_string_ranges_t_adjust(status, ranges, length) status = f_string_ranges_adjust(length, &ranges); - - #define macro_f_string_ranges_t_delete_simple(ranges) f_string_ranges_resize(0, &ranges); - #define macro_f_string_ranges_t_destroy_simple(ranges) f_string_ranges_adjust(0, &ranges); - - #define macro_f_string_ranges_t_increase(status, step, ranges) status = f_string_ranges_increase(step, &ranges); - #define macro_f_string_ranges_t_increase_by(status, ranges, amount) status = f_string_ranges_increase_by(amount, &ranges); - #define macro_f_string_ranges_t_decrease_by(status, ranges, amount) status = f_string_ranges_decrease_by(amount, &ranges); - #define macro_f_string_ranges_t_decimate_by(status, ranges, amount) status = f_string_ranges_decimate_by(amount, &ranges); -#endif // _di_f_string_ranges_t_ - -/** - * This holds an array of f_string_ranges_t. - * - * array: The array of ranges arrays. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_string_rangess_t_ - typedef struct { - f_string_ranges_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_rangess_t; - - #define f_string_rangess_t_initialize { 0, 0, 0 } - - #define macro_f_string_rangess_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_rangess_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_rangess_t_clear(rangess) macro_f_memory_structures_clear(rangess) - - #define macro_f_string_rangess_t_resize(status, rangess, length) status = f_string_rangess_resize(length, &rangess); - #define macro_f_string_rangess_t_adjust(status, rangess, length) status = f_string_rangess_adjust(length, &rangess); - - #define macro_f_string_rangess_t_delete_simple(rangess) f_string_rangess_resize(0, &rangess); - #define macro_f_string_rangess_t_destroy_simple(rangess) f_string_rangess_adjust(0, &rangess); - - #define macro_f_string_rangess_t_increase(status, step, rangess) status = f_string_rangess_increase(step, &rangess); - #define macro_f_string_rangess_t_increase_by(status, rangess, amount) status = f_string_rangess_increase_by(amount, &rangess); - #define macro_f_string_rangess_t_decrease_by(status, rangess, amount) status = f_string_rangess_decrease_by(amount, &rangess); - #define macro_f_string_rangess_t_decimate_by(status, rangess, amount) status = f_string_rangess_decimate_by(amount, &rangess); -#endif // _di_f_string_rangess_t_ - -/** - * Resize the string ranges array. - * - * @param length - * The new size to use. - * @param ranges - * The string ranges array to resize. - * - * @return - * F_none on success. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_string_ranges_adjust_ - extern f_status_t f_string_ranges_adjust(const f_array_length_t length, f_string_ranges_t * const ranges); -#endif // _di_f_string_ranges_adjust_ - -/** - * Append the single source range onto the destination. - * - * @param source - * The source range to append. - * @param destination - * The destination ranges the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_ranges_append_ - extern f_status_t f_string_ranges_append(const f_string_range_t source, f_string_ranges_t * const destination); -#endif // _di_f_string_ranges_append_ - -/** - * Append the source ranges onto the destination. - * - * @param source - * The source ranges to append. - * @param destination - * The destination ranges the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_ranges_append_all_ - extern f_status_t f_string_ranges_append_all(const f_string_ranges_t source, f_string_ranges_t * const destination); -#endif // _di_f_string_ranges_append_all_ - -/** - * Resize the string ranges 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 decimate the size by. - * @param ranges - * The string ranges array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_ranges_decimate_by_ - extern f_status_t f_string_ranges_decimate_by(const f_array_length_t amount, f_string_ranges_t * const ranges); -#endif // _di_f_string_ranges_decimate_by_ - -/** - * Resize the string ranges 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 ranges - * The string ranges array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_ranges_decrease_by_ - extern f_status_t f_string_ranges_decrease_by(const f_array_length_t amount, f_string_ranges_t * const ranges); -#endif // _di_f_string_ranges_decrease_by_ - -/** - * Increase the size of the string ranges 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param ranges - * The string ranges array to resize. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * @return - * F_none on success. - * F_array_too_large (with error bit) if the new array length is too large. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_ranges_increase_ - extern f_status_t f_string_ranges_increase(const f_array_length_t step, f_string_ranges_t * const ranges); -#endif // _di_f_string_ranges_increase_ - -/** - * Resize the string ranges 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_d). - * 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 ranges - * The string ranges array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_ranges_increase_by_ - extern f_status_t f_string_ranges_increase_by(const f_array_length_t amount, f_string_ranges_t * const ranges); -#endif // _di_f_string_ranges_increase_by_ - -/** - * Resize the string ranges array. - * - * @param length - * The new size to use. - * @param ranges - * The string ranges array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_ranges_resize_ - extern f_status_t f_string_ranges_resize(const f_array_length_t length, f_string_ranges_t * const ranges); -#endif // _di_f_string_ranges_resize_ - -/** - * Resize the string rangess array. - * - * @param length - * The new size to use. - * @param rangess - * The string rangess array to resize. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_rangess_adjust_ - extern f_status_t f_string_rangess_adjust(const f_array_length_t length, f_string_rangess_t * const rangess); -#endif // _di_f_string_rangess_adjust_ - -/** - * Append the single source ranges onto the destination. - * - * @param source - * The source ranges to append. - * @param destination - * The destination rangess the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_rangess_append_ - extern f_status_t f_string_rangess_append(const f_string_ranges_t source, f_string_rangess_t * const destination); -#endif // _di_f_string_rangess_append_ - -/** - * Append the source rangess onto the destination. - * - * @param source - * The source rangess to append. - * @param destination - * The destination rangess the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is nothing to append (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_rangess_append_all_ - extern f_status_t f_string_rangess_append_all(const f_string_rangess_t source, f_string_rangess_t * const destination); -#endif // _di_f_string_rangess_append_all_ - -/** - * Resize the string rangess 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 decimate the size by. - * @param rangess - * The string rangess array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_rangess_decimate_by_ - extern f_status_t f_string_rangess_decimate_by(const f_array_length_t amount, f_string_rangess_t * const rangess); -#endif // _di_f_string_rangess_decimate_by_ - -/** - * Resize the string rangess 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 rangess - * The string rangess array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_rangess_decrease_by_ - extern f_status_t f_string_rangess_decrease_by(const f_array_length_t amount, f_string_rangess_t * const rangess); -#endif // _di_f_string_rangess_decrease_by_ - -/** - * Increase the size of the string rangess 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param rangess - * The string rangess array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_rangess_increase_ - extern f_status_t f_string_rangess_increase(const f_array_length_t step, f_string_rangess_t * const rangess); -#endif // _di_f_string_rangess_increase_ - -/** - * Resize the string rangess 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_d). - * 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 rangess - * The string rangess array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_rangess_increase_by_ - extern f_status_t f_string_rangess_increase_by(const f_array_length_t amount, f_string_rangess_t * const rangess); -#endif // _di_f_string_rangess_increase_by_ - -/** - * Resize the string rangess array. - * - * @param length - * The new size to use. - * @param rangess - * The string rangess array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_rangess_resize_ - extern f_status_t f_string_rangess_resize(const f_array_length_t length, f_string_rangess_t * const rangess); -#endif // _di_f_string_rangess_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/ranges.c b/level_0/f_string/c/string/ranges.c new file mode 100644 index 0000000..2626760 --- /dev/null +++ b/level_0/f_string/c/string/ranges.c @@ -0,0 +1,148 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-ranges.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_ranges_adjust_ + f_status_t f_string_ranges_adjust(const f_array_length_t length, f_string_ranges_t * const ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_ranges_adjust(length, ranges); + } +#endif // _di_f_string_ranges_adjust_ + +#ifndef _di_f_string_ranges_append_ + f_status_t f_string_ranges_append(const f_string_range_t source, f_string_ranges_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (destination->used + 1 > destination->size) { + const f_status_t status = private_f_string_ranges_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].start = source.start; + destination->array[destination->used++].stop = source.stop; + + return F_none; + } +#endif // _di_f_string_ranges_append_ + +#ifndef _di_f_string_ranges_append_all_ + f_status_t f_string_ranges_append_all(const f_string_ranges_t source, f_string_ranges_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + if (destination->used + source.used > destination->size) { + const f_status_t status = private_f_string_ranges_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_array_length_t i = 0; i < source.used; ++i) { + + destination->array[destination->used].start = source.array[i].start; + destination->array[destination->used++].stop = source.array[i].stop; + } // for + + return F_none; + } +#endif // _di_f_string_ranges_append_all_ + +#ifndef _di_f_string_ranges_decimate_by_ + f_status_t f_string_ranges_decimate_by(const f_array_length_t amount, f_string_ranges_t * const ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (ranges->size > amount) { + return private_f_string_ranges_adjust(ranges->size - amount, ranges); + } + + return private_f_string_ranges_adjust(0, ranges); + } +#endif // _di_f_string_ranges_decimate_by_ + +#ifndef _di_f_string_ranges_decrease_by_ + f_status_t f_string_ranges_decrease_by(const f_array_length_t amount, f_string_ranges_t * const ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (ranges->size > amount) { + return private_f_string_ranges_resize(ranges->size - amount, ranges); + } + + return private_f_string_ranges_resize(0, ranges); + } +#endif // _di_f_string_ranges_decrease_by_ + +#ifndef _di_f_string_ranges_increase_ + f_status_t f_string_ranges_increase(const f_array_length_t step, f_string_ranges_t * const ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && ranges->used + 1 > ranges->size) { + f_array_length_t size = ranges->used + step; + + if (size > F_array_length_t_size_d) { + if (ranges->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_ranges_resize(size, ranges); + } + + return F_data_not; + } +#endif // _di_f_string_ranges_increase_ + +#ifndef _di_f_string_ranges_increase_by_ + f_status_t f_string_ranges_increase_by(const f_array_length_t amount, f_string_ranges_t * const ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (ranges->used + amount > ranges->size) { + if (ranges->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_ranges_resize(ranges->used + amount, ranges); + } + + return F_data_not; + } +#endif // _di_f_string_ranges_increase_by_ + +#ifndef _di_f_string_ranges_resize_ + f_status_t f_string_ranges_resize(const f_array_length_t length, f_string_ranges_t * const ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_ranges_resize(length, ranges); + } +#endif // _di_f_string_ranges_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/ranges.h b/level_0/f_string/c/string/ranges.h new file mode 100644 index 0000000..d195d1b --- /dev/null +++ b/level_0/f_string/c/string/ranges.h @@ -0,0 +1,232 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines range string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_ranges_h +#define _F_string_ranges_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of string ranges. + * + * array: the array of string ranges. + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ +#ifndef _di_f_string_ranges_t_ + typedef struct { + f_string_range_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_ranges_t; + + #define f_string_ranges_t_initialize { 0, 0, 0 } + + #define macro_f_string_ranges_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_ranges_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_ranges_t_clear(ranges) macro_f_memory_structure_clear(ranges) + + #define macro_f_string_ranges_t_resize(status, ranges, length) status = f_string_ranges_resize(length, &ranges); + #define macro_f_string_ranges_t_adjust(status, ranges, length) status = f_string_ranges_adjust(length, &ranges); + + #define macro_f_string_ranges_t_delete_simple(ranges) f_string_ranges_resize(0, &ranges); + #define macro_f_string_ranges_t_destroy_simple(ranges) f_string_ranges_adjust(0, &ranges); + + #define macro_f_string_ranges_t_increase(status, step, ranges) status = f_string_ranges_increase(step, &ranges); + #define macro_f_string_ranges_t_increase_by(status, ranges, amount) status = f_string_ranges_increase_by(amount, &ranges); + #define macro_f_string_ranges_t_decrease_by(status, ranges, amount) status = f_string_ranges_decrease_by(amount, &ranges); + #define macro_f_string_ranges_t_decimate_by(status, ranges, amount) status = f_string_ranges_decimate_by(amount, &ranges); +#endif // _di_f_string_ranges_t_ + +/** + * Resize the string ranges array. + * + * @param length + * The new size to use. + * @param ranges + * The string ranges array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_string_ranges_adjust_ + extern f_status_t f_string_ranges_adjust(const f_array_length_t length, f_string_ranges_t * const ranges); +#endif // _di_f_string_ranges_adjust_ + +/** + * Append the single source range onto the destination. + * + * @param source + * The source range to append. + * @param destination + * The destination ranges the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_ranges_append_ + extern f_status_t f_string_ranges_append(const f_string_range_t source, f_string_ranges_t * const destination); +#endif // _di_f_string_ranges_append_ + +/** + * Append the source ranges onto the destination. + * + * @param source + * The source ranges to append. + * @param destination + * The destination ranges the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_ranges_append_all_ + extern f_status_t f_string_ranges_append_all(const f_string_ranges_t source, f_string_ranges_t * const destination); +#endif // _di_f_string_ranges_append_all_ + +/** + * Resize the string ranges 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 decimate the size by. + * @param ranges + * The string ranges array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_ranges_decimate_by_ + extern f_status_t f_string_ranges_decimate_by(const f_array_length_t amount, f_string_ranges_t * const ranges); +#endif // _di_f_string_ranges_decimate_by_ + +/** + * Resize the string ranges 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 ranges + * The string ranges array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_ranges_decrease_by_ + extern f_status_t f_string_ranges_decrease_by(const f_array_length_t amount, f_string_ranges_t * const ranges); +#endif // _di_f_string_ranges_decrease_by_ + +/** + * Increase the size of the string ranges 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param ranges + * The string ranges array to resize. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * @return + * F_none on success. + * F_array_too_large (with error bit) if the new array length is too large. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_ranges_increase_ + extern f_status_t f_string_ranges_increase(const f_array_length_t step, f_string_ranges_t * const ranges); +#endif // _di_f_string_ranges_increase_ + +/** + * Resize the string ranges 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_d). + * 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 ranges + * The string ranges array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_ranges_increase_by_ + extern f_status_t f_string_ranges_increase_by(const f_array_length_t amount, f_string_ranges_t * const ranges); +#endif // _di_f_string_ranges_increase_by_ + +/** + * Resize the string ranges array. + * + * @param length + * The new size to use. + * @param ranges + * The string ranges array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_ranges_resize_ + extern f_status_t f_string_ranges_resize(const f_array_length_t length, f_string_ranges_t * const ranges); +#endif // _di_f_string_ranges_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_ranges_h diff --git a/level_0/f_string/c/string/rangess.c b/level_0/f_string/c/string/rangess.c new file mode 100644 index 0000000..94cc8f7 --- /dev/null +++ b/level_0/f_string/c/string/rangess.c @@ -0,0 +1,165 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-ranges.h" +#include "private-rangess.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_rangess_adjust_ + f_status_t f_string_rangess_adjust(const f_array_length_t length, f_string_rangess_t * const rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_rangess_adjust(length, rangess); + } +#endif // _di_f_string_rangess_adjust_ + +#ifndef _di_f_string_rangess_append_ + f_status_t f_string_rangess_append(const f_string_ranges_t source, f_string_rangess_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_rangess_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].used = 0; + + if (source.used) { + status = private_f_string_ranges_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_rangess_append_ + +#ifndef _di_f_string_rangess_append_all_ + f_status_t f_string_rangess_append_all(const f_string_rangess_t source, f_string_rangess_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + source.used > destination->size) { + status = private_f_string_rangess_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].used = 0; + + if (source.array[i].used) { + status = private_f_string_ranges_append_all(source.array[i], &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + } // for + + return F_none; + } +#endif // _di_f_string_rangess_append_all_ + +#ifndef _di_f_string_rangess_decimate_by_ + f_status_t f_string_rangess_decimate_by(const f_array_length_t amount, f_string_rangess_t * const rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (rangess->size > amount) { + return private_f_string_rangess_adjust(rangess->size - amount, rangess); + } + + return private_f_string_rangess_adjust(0, rangess); + } +#endif // _di_f_string_rangess_decimate_by_ + +#ifndef _di_f_string_rangess_decrease_by_ + f_status_t f_string_rangess_decrease_by(const f_array_length_t amount, f_string_rangess_t * const rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (rangess->size > amount) { + return private_f_string_rangess_resize(rangess->size - amount, rangess); + } + + return private_f_string_rangess_resize(0, rangess); + } +#endif // _di_f_string_rangess_decrease_by_ + +#ifndef _di_f_string_rangess_increase_ + f_status_t f_string_rangess_increase(const f_array_length_t step, f_string_rangess_t * const rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && rangess->used + 1 > rangess->size) { + f_array_length_t size = rangess->used + step; + + if (size > F_array_length_t_size_d) { + if (rangess->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_rangess_resize(size, rangess); + } + + return F_data_not; + } +#endif // _di_f_string_rangess_increase_ + +#ifndef _di_f_string_rangess_increase_by_ + f_status_t f_string_rangess_increase_by(const f_array_length_t amount, f_string_rangess_t * const rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (rangess->used + amount > rangess->size) { + if (rangess->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_rangess_resize(rangess->used + amount, rangess); + } + + return F_data_not; + } +#endif // _di_f_string_rangess_increase_by_ + +#ifndef _di_f_string_rangess_resize_ + f_status_t f_string_rangess_resize(const f_array_length_t length, f_string_rangess_t * const rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_rangess_resize(length, rangess); + } +#endif // _di_f_string_rangess_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/rangess.h b/level_0/f_string/c/string/rangess.h new file mode 100644 index 0000000..ee86eca --- /dev/null +++ b/level_0/f_string/c/string/rangess.h @@ -0,0 +1,233 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines range string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_rangess_h +#define _F_string_rangess_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * This holds an array of f_string_ranges_t. + * + * array: The array of ranges arrays. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_string_rangess_t_ + typedef struct { + f_string_ranges_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_rangess_t; + + #define f_string_rangess_t_initialize { 0, 0, 0 } + + #define macro_f_string_rangess_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_rangess_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_rangess_t_clear(rangess) macro_f_memory_structures_clear(rangess) + + #define macro_f_string_rangess_t_resize(status, rangess, length) status = f_string_rangess_resize(length, &rangess); + #define macro_f_string_rangess_t_adjust(status, rangess, length) status = f_string_rangess_adjust(length, &rangess); + + #define macro_f_string_rangess_t_delete_simple(rangess) f_string_rangess_resize(0, &rangess); + #define macro_f_string_rangess_t_destroy_simple(rangess) f_string_rangess_adjust(0, &rangess); + + #define macro_f_string_rangess_t_increase(status, step, rangess) status = f_string_rangess_increase(step, &rangess); + #define macro_f_string_rangess_t_increase_by(status, rangess, amount) status = f_string_rangess_increase_by(amount, &rangess); + #define macro_f_string_rangess_t_decrease_by(status, rangess, amount) status = f_string_rangess_decrease_by(amount, &rangess); + #define macro_f_string_rangess_t_decimate_by(status, rangess, amount) status = f_string_rangess_decimate_by(amount, &rangess); +#endif // _di_f_string_rangess_t_ + +/** + * Resize the string rangess array. + * + * @param length + * The new size to use. + * @param rangess + * The string rangess array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_rangess_adjust_ + extern f_status_t f_string_rangess_adjust(const f_array_length_t length, f_string_rangess_t * const rangess); +#endif // _di_f_string_rangess_adjust_ + +/** + * Append the single source ranges onto the destination. + * + * @param source + * The source ranges to append. + * @param destination + * The destination rangess the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_rangess_append_ + extern f_status_t f_string_rangess_append(const f_string_ranges_t source, f_string_rangess_t * const destination); +#endif // _di_f_string_rangess_append_ + +/** + * Append the source rangess onto the destination. + * + * @param source + * The source rangess to append. + * @param destination + * The destination rangess the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_rangess_append_all_ + extern f_status_t f_string_rangess_append_all(const f_string_rangess_t source, f_string_rangess_t * const destination); +#endif // _di_f_string_rangess_append_all_ + +/** + * Resize the string rangess 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 decimate the size by. + * @param rangess + * The string rangess array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_rangess_decimate_by_ + extern f_status_t f_string_rangess_decimate_by(const f_array_length_t amount, f_string_rangess_t * const rangess); +#endif // _di_f_string_rangess_decimate_by_ + +/** + * Resize the string rangess 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 rangess + * The string rangess array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_rangess_decrease_by_ + extern f_status_t f_string_rangess_decrease_by(const f_array_length_t amount, f_string_rangess_t * const rangess); +#endif // _di_f_string_rangess_decrease_by_ + +/** + * Increase the size of the string rangess 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param rangess + * The string rangess array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_rangess_increase_ + extern f_status_t f_string_rangess_increase(const f_array_length_t step, f_string_rangess_t * const rangess); +#endif // _di_f_string_rangess_increase_ + +/** + * Resize the string rangess 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_d). + * 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 rangess + * The string rangess array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_rangess_increase_by_ + extern f_status_t f_string_rangess_increase_by(const f_array_length_t amount, f_string_rangess_t * const rangess); +#endif // _di_f_string_rangess_increase_by_ + +/** + * Resize the string rangess array. + * + * @param length + * The new size to use. + * @param rangess + * The string rangess array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_rangess_resize_ + extern f_status_t f_string_rangess_resize(const f_array_length_t length, f_string_rangess_t * const rangess); +#endif // _di_f_string_rangess_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_rangess_h diff --git a/level_0/f_string/c/string/static.h b/level_0/f_string/c/string/static.h index 9fe2389..5b03504 100644 --- a/level_0/f_string/c/string/static.h +++ b/level_0/f_string/c/string/static.h @@ -51,58 +51,6 @@ extern "C" { #endif // _di_f_string_static_t_ /** - * An array of static strings. - * - * array: The array of static strings. - * size: Total amount of space available. - * used: Total number of space used. - */ -#ifndef _di_f_string_statics_t_ - typedef struct { - f_string_static_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_statics_t; - - #define f_string_statics_t_initialize { 0, 0, 0 } - - #define macro_f_string_statics_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_statics_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_statics_t_clear(statics) \ - statics.array = 0; \ - statics.size = 0; \ - statics.used = 0; -#endif // _di_f_string_statics_t_ - -/** - * An array of static strings. - * - * array: The array of static strings. - * size: Total amount of space available. - * used: Total number of space used. - */ -#ifndef _di_f_string_staticss_t_ - typedef struct { - f_string_statics_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_staticss_t; - - #define f_string_staticss_t_initialize { 0, 0, 0 } - - #define macro_f_string_staticss_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_staticss_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_staticss_t_clear(staticss) \ - staticss.array = 0; \ - staticss.size = 0; \ - staticss.used = 0; -#endif // _di_f_string_staticss_t_ - -/** * Provide a static empty string. * * This is intended to represent an empty string. diff --git a/level_0/f_string/c/string/statics.c b/level_0/f_string/c/string/statics.c new file mode 100644 index 0000000..8649964 --- /dev/null +++ b/level_0/f_string/c/string/statics.c @@ -0,0 +1,9 @@ +#include "../string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/statics.h b/level_0/f_string/c/string/statics.h new file mode 100644 index 0000000..ab201e8 --- /dev/null +++ b/level_0/f_string/c/string/statics.h @@ -0,0 +1,49 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines static string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_statics_h +#define _F_string_statics_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of static strings. + * + * array: The array of static strings. + * size: Total amount of space available. + * used: Total number of space used. + */ +#ifndef _di_f_string_statics_t_ + typedef struct { + f_string_static_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_statics_t; + + #define f_string_statics_t_initialize { 0, 0, 0 } + + #define macro_f_string_statics_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_statics_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_statics_t_clear(statics) \ + statics.array = 0; \ + statics.size = 0; \ + statics.used = 0; +#endif // _di_f_string_statics_t_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_statics_h diff --git a/level_0/f_string/c/string/staticss.c b/level_0/f_string/c/string/staticss.c new file mode 100644 index 0000000..8649964 --- /dev/null +++ b/level_0/f_string/c/string/staticss.c @@ -0,0 +1,9 @@ +#include "../string.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/staticss.h b/level_0/f_string/c/string/staticss.h new file mode 100644 index 0000000..28b0d06 --- /dev/null +++ b/level_0/f_string/c/string/staticss.h @@ -0,0 +1,49 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines static string data. + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_staticss_h +#define _F_string_staticss_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of static strings. + * + * array: The array of static strings. + * size: Total amount of space available. + * used: Total number of space used. + */ +#ifndef _di_f_string_staticss_t_ + typedef struct { + f_string_statics_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_staticss_t; + + #define f_string_staticss_t_initialize { 0, 0, 0 } + + #define macro_f_string_staticss_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_staticss_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_staticss_t_clear(staticss) \ + staticss.array = 0; \ + staticss.size = 0; \ + staticss.used = 0; +#endif // _di_f_string_staticss_t_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_staticss_h diff --git a/level_0/f_string/c/string/triple.c b/level_0/f_string/c/string/triple.c index 68bb6f3..19bfbd9 100644 --- a/level_0/f_string/c/string/triple.c +++ b/level_0/f_string/c/string/triple.c @@ -1,337 +1,10 @@ #include "../string.h" #include "../private-string.h" -#include "private-triple.h" #ifdef __cplusplus extern "C" { #endif -#ifndef _di_f_string_triples_adjust_ - f_status_t f_string_triples_adjust(const f_array_length_t length, f_string_triples_t * const triples) { - #ifndef _di_level_0_parameter_checking_ - if (!triples) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_triples_adjust(length, triples); - } -#endif // _di_f_string_triples_adjust_ - -#ifndef _di_f_string_triples_append_ - f_status_t f_string_triples_append(const f_string_triple_t source, f_string_triples_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_triples_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].a.used = 0; - destination->array[destination->used].b.used = 0; - destination->array[destination->used].c.used = 0; - - if (source.a.used) { - status = private_f_string_append(source.a.string, source.a.used, &destination->array[destination->used].a); - if (F_status_is_error(status)) return status; - } - - if (source.b.used) { - status = private_f_string_append(source.b.string, source.b.used, &destination->array[destination->used].b); - if (F_status_is_error(status)) return status; - } - - if (source.c.used) { - status = private_f_string_append(source.c.string, source.c.used, &destination->array[destination->used].c); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // _di_f_string_triples_append_ - -#ifndef _di_f_string_triples_append_all_ - f_status_t f_string_triples_append_all(const f_string_triples_t source, f_string_triples_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_string_triples_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } - - for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { - - destination->array[destination->used].a.used = 0; - destination->array[destination->used].b.used = 0; - destination->array[destination->used].c.used = 0; - - if (source.array[i].a.used) { - status = private_f_string_append(source.array[i].a.string, source.array[i].a.used, &destination->array[destination->used].a); - if (F_status_is_error(status)) return status; - } - - if (source.array[i].b.used) { - status = private_f_string_append(source.array[i].b.string, source.array[i].b.used, &destination->array[destination->used].b); - if (F_status_is_error(status)) return status; - } - - if (source.array[i].c.used) { - status = private_f_string_append(source.array[i].c.string, source.array[i].c.used, &destination->array[destination->used].c); - if (F_status_is_error(status)) return status; - } - } // for - - return F_none; - } -#endif // _di_f_string_triples_append_all_ - -#ifndef _di_f_string_triples_decimate_by_ - f_status_t f_string_triples_decimate_by(const f_array_length_t amount, f_string_triples_t * const triples) { - #ifndef _di_level_0_parameter_checking_ - if (!triples) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (triples->size > amount) { - return private_f_string_triples_adjust(triples->size - amount, triples); - } - - return private_f_string_triples_adjust(0, triples); - } -#endif // _di_f_string_triples_decimate_by_ - -#ifndef _di_f_string_triples_decrease_by_ - f_status_t f_string_triples_decrease_by(const f_array_length_t amount, f_string_triples_t * const triples) { - #ifndef _di_level_0_parameter_checking_ - if (!triples) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (triples->size > amount) { - return private_f_string_triples_resize(triples->size - amount, triples); - } - - return private_f_string_triples_resize(0, triples); - } -#endif // _di_f_string_triples_decrease_by_ - -#ifndef _di_f_string_triples_increase_ - f_status_t f_string_triples_increase(const f_array_length_t step, f_string_triples_t * const triples) { - #ifndef _di_level_0_parameter_checking_ - if (!triples) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && triples->used + 1 > triples->size) { - f_array_length_t size = triples->used + F_memory_default_allocation_small_d; - - if (size > F_array_length_t_size_d) { - if (triples->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_triples_resize(size, triples); - } - - return F_data_not; - } -#endif // _di_f_string_triples_increase_ - -#ifndef _di_f_string_triples_increase_by_ - f_status_t f_string_triples_increase_by(const f_array_length_t amount, f_string_triples_t * const triples) { - #ifndef _di_level_0_parameter_checking_ - if (!triples) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (triples->used + amount > triples->size) { - if (triples->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_triples_resize(triples->used + amount, triples); - } - - return F_data_not; - } -#endif // _di_f_string_triples_increase_by_ - -#ifndef _di_f_string_triples_resize_ - f_status_t f_string_triples_resize(const f_array_length_t length, f_string_triples_t * const triples) { - #ifndef _di_level_0_parameter_checking_ - if (!triples) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_triples_resize(length, triples); - } -#endif // _di_f_string_triples_resize_ - -#ifndef _di_f_string_tripless_append_ - f_status_t f_string_tripless_append(const f_string_triples_t source, f_string_tripless_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_string_tripless_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } - - destination->array[destination->used].used = 0; - - if (source.used) { - status = private_f_string_triples_append_all(source, &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - - ++destination->used; - - return F_none; - } -#endif // _di_f_string_tripless_append_ - -#ifndef _di_f_string_tripless_append_all_ - f_status_t f_string_tripless_append_all(const f_string_tripless_t source, f_string_tripless_t * const destination) { - #ifndef _di_level_0_parameter_checking_ - if (!destination) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!source.used) return F_data_not; - - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_string_tripless_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } - - for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { - - destination->array[destination->used].used = 0; - - if (source.array[i].used) { - status = private_f_string_triples_append_all(source.array[i], &destination->array[destination->used]); - if (F_status_is_error(status)) return status; - } - } // for - - return F_none; - } -#endif // _di_f_string_tripless_append_all_ - -#ifndef _di_f_string_tripless_adjust_ - f_status_t f_string_tripless_adjust(const f_array_length_t length, f_string_tripless_t * const tripless) { - #ifndef _di_level_0_parameter_checking_ - if (!tripless) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_tripless_adjust(length, tripless); - } -#endif // _di_f_string_tripless_adjust_ - -#ifndef _di_f_string_tripless_decimate_by_ - f_status_t f_string_tripless_decimate_by(const f_array_length_t amount, f_string_tripless_t * const tripless) { - #ifndef _di_level_0_parameter_checking_ - if (!tripless) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (tripless->size > amount) { - return private_f_string_tripless_adjust(tripless->size - amount, tripless); - } - - return private_f_string_tripless_adjust(0, tripless); - } -#endif // _di_f_string_tripless_decimate_by_ - -#ifndef _di_f_string_tripless_decrease_by_ - f_status_t f_string_tripless_decrease_by(const f_array_length_t amount, f_string_tripless_t * const tripless) { - #ifndef _di_level_0_parameter_checking_ - if (!tripless) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (tripless->size > amount) { - return private_f_string_tripless_resize(tripless->size - amount, tripless); - } - - return private_f_string_tripless_resize(0, tripless); - } -#endif // _di_f_string_tripless_decrease_by_ - -#ifndef _di_f_string_tripless_increase_ - f_status_t f_string_tripless_increase(const f_array_length_t step, f_string_tripless_t * const tripless) { - #ifndef _di_level_0_parameter_checking_ - if (!tripless) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (step && tripless->used + 1 > tripless->size) { - f_array_length_t size = tripless->used + step; - - if (size > F_array_length_t_size_d) { - if (tripless->used + 1 > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_array_length_t_size_d; - } - - return private_f_string_tripless_resize(size, tripless); - } - - return F_data_not; - } -#endif // _di_f_string_tripless_increase_ - -#ifndef _di_f_string_tripless_increase_by_ - f_status_t f_string_tripless_increase_by(const f_array_length_t amount, f_string_tripless_t * const tripless) { - #ifndef _di_level_0_parameter_checking_ - if (!tripless) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - if (!amount) return F_data_not; - - if (tripless->used + amount > tripless->size) { - if (tripless->used + amount > F_array_length_t_size_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_string_tripless_resize(tripless->used + amount, tripless); - } - - return F_data_not; - } -#endif // _di_f_string_tripless_increase_by_ - -#ifndef _di_f_string_tripless_resize_ - f_status_t f_string_tripless_resize(const f_array_length_t length, f_string_tripless_t * const tripless) { - #ifndef _di_level_0_parameter_checking_ - if (!tripless) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - return private_f_string_tripless_resize(length, tripless); - } -#endif // _di_f_string_tripless_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/triple.h b/level_0/f_string/c/string/triple.h index 89d510b..24f36d2 100644 --- a/level_0/f_string/c/string/triple.h +++ b/level_0/f_string/c/string/triple.h @@ -56,428 +56,6 @@ extern "C" { macro_f_string_dynamic_t_destroy_simple(triple.c) #endif // _di_f_string_triple_t_ -/** - * An array of string triples. - * - * array: The array of string triples. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_string_triples_t_ - typedef struct { - f_string_triple_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_triples_t; - - #define f_string_triples_t_initialize f_string_statics_t_initialize - - #define macro_f_string_triples_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_triples_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_triples_t_clear(triples) macro_f_memory_structure_clear(triples) - - #define macro_f_string_triples_t_resize(status, triples, length) status = f_string_triples_resize(length, &triples); - #define macro_f_string_triples_t_adjust(status, triples, length) status = f_string_triples_adjust(length, &triples); - - #define macro_f_string_triples_t_delete_simple(triples) f_string_triples_resize(0, &triples); - #define macro_f_string_triples_t_destroy_simple(triples) f_string_triples_adjust(0, &triples); - - #define macro_f_string_triples_t_increase(status, step, triples) status = f_string_triples_increase(step, triples); - #define macro_f_string_triples_t_increase_by(status, triples, amount) status = f_string_triples_increase_by(amount, triples); - #define macro_f_string_triples_t_decrease_by(status, triples, amount) status = f_string_triples_decrease_by(amount, triples); - #define macro_f_string_triples_t_decimate_by(status, triples, amount) status = f_string_triples_decimate_by(amount, triples); -#endif // _di_f_string_triples_t_ - -/** - * An array of string tripless. - * - * array: The array of string triples. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_string_tripless_t_ - typedef struct { - f_string_triples_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_string_tripless_t; - - #define f_string_tripless_t_initialize f_string_statics_t_initialize - - #define macro_f_string_tripless_t_initialize(array, size, used) { array, size, used } - #define macro_f_string_tripless_t_initialize2(array, length) { array, length, length } - - #define macro_f_string_tripless_t_clear(tripless) macro_f_memory_structure_clear(tripless) - - #define macro_f_string_tripless_t_resize(status, tripless, length) status = f_string_tripless_resize(length, &tripless); - #define macro_f_string_tripless_t_adjust(status, tripless, length) status = f_string_tripless_adjust(length, &tripless); - - #define macro_f_string_tripless_t_delete_simple(tripless) f_string_tripless_resize(0, &tripless); - #define macro_f_string_tripless_t_destroy_simple(tripless) f_string_tripless_adjust(0, &tripless); - - #define macro_f_string_tripless_t_increase(status, step, tripless) status = f_string_tripless_increase(step, tripless); - #define macro_f_string_tripless_t_increase_by(status, tripless, amount) status = f_string_tripless_increase_by(amount, tripless); - #define macro_f_string_tripless_t_decrease_by(status, tripless, amount) status = f_string_tripless_decrease_by(amount, tripless); - #define macro_f_string_tripless_t_decimate_by(status, tripless, amount) status = f_string_tripless_decimate_by(amount, tripless); -#endif // _di_f_string_tripless_t_ - -/** - * Resize the string triples array. - * - * @param length - * The new size to use. - * @param triples - * The string triples array to resize. - * - * @return - * F_none on success. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_string_triples_adjust_ - extern f_status_t f_string_triples_adjust(const f_array_length_t length, f_string_triples_t * const triples); -#endif // _di_f_string_triples_adjust_ - -/** - * Append the single source triples onto the destination. - * - * @param source - * The source triple to append. - * @param destination - * The destination triples the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_triples_append_ - extern f_status_t f_string_triples_append(const f_string_triple_t source, f_string_triples_t * const destination); -#endif // _di_f_string_triples_append_ - -/** - * Append the source triples onto the destination. - * - * @param source - * The source triples to append. - * @param destination - * The destination triples the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_triples_append_all_ - extern f_status_t f_string_triples_append_all(const f_string_triples_t source, f_string_triples_t * const destination); -#endif // _di_f_string_triples_append_all_ - -/** - * Resize the string triples 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 decimate the size by. - * @param triples - * The string triples array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_triples_decimate_by_ - extern f_status_t f_string_triples_decimate_by(const f_array_length_t amount, f_string_triples_t * const triples); -#endif // _di_f_string_triples_decimate_by_ - -/** - * Resize the string triples 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 triples - * The string triples array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_triples_decrease_by_ - extern f_status_t f_string_triples_decrease_by(const f_array_length_t amount, f_string_triples_t * const triples); -#endif // _di_f_string_triples_decrease_by_ - -/** - * Increase the size of the string triples 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param triples - * The string triples array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_triples_increase_ - extern f_status_t f_string_triples_increase(const f_array_length_t step, f_string_triples_t * const triples); -#endif // _di_f_string_triples_increase_ - -/** - * Resize the string triples 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_d). - * 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 triples - * The string triples array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_triples_increase_by_ - extern f_status_t f_string_triples_increase_by(const f_array_length_t amount, f_string_triples_t * const triples); -#endif // _di_f_string_triples_increase_by_ - -/** - * Resize the string triples array. - * - * @param length - * The new size to use. - * @param triples - * The string triples array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_triples_resize_ - extern f_status_t f_string_triples_resize(const f_array_length_t length, f_string_triples_t * const triples); -#endif // _di_f_string_triples_resize_ - -/** - * Resize the string tripless array. - * - * @param length - * The new size to use. - * @param tripless - * The string tripless array to resize. - * - * @return - * F_none on success. - * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_string_tripless_adjust_ - extern f_status_t f_string_tripless_adjust(const f_array_length_t length, f_string_tripless_t * const tripless); -#endif // _di_f_string_tripless_adjust_ - -/** - * Append the single source triples onto the destination. - * - * @param source - * The source triples to append. - * @param destination - * The destination tripless the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_tripless_append_ - extern f_status_t f_string_tripless_append(const f_string_triples_t source, f_string_tripless_t * const destination); -#endif // _di_f_string_tripless_append_ - -/** - * Append the source tripless onto the destination. - * - * @param source - * The source tripless to append. - * @param destination - * The destination tripless the source is appended onto. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (size == 0). - * - * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if the combined string is too large. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_tripless_append_all_ - extern f_status_t f_string_tripless_append_all(const f_string_tripless_t source, f_string_tripless_t * const destination); -#endif // _di_f_string_tripless_append_all_ - -/** - * Resize the string tripless 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 decimate the size by. - * @param tripless - * The string tripless array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_tripless_decimate_by_ - extern f_status_t f_string_tripless_decimate_by(const f_array_length_t amount, f_string_tripless_t * const tripless); -#endif // _di_f_string_tripless_decimate_by_ - -/** - * Resize the string tripless 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 tripless - * The string tripless array to resize. - * - * @return - * F_none on success. - * F_data_not if amount is 0. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_tripless_decrease_by_ - extern f_status_t f_string_tripless_decrease_by(const f_array_length_t amount, f_string_tripless_t * const tripless); -#endif // _di_f_string_tripless_decrease_by_ - -/** - * Increase the size of the string tripless 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_d). - * If already set to the maximum buffer size, then the resize will fail. - * - * @param step - * The allocation step to use. - * Must be greater than 0. - * @param tripless - * The string tripless array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_tripless_increase_ - extern f_status_t f_string_tripless_increase(const f_array_length_t step, f_string_tripless_t * const tripless); -#endif // _di_f_string_tripless_increase_ - -/** - * Resize the string tripless 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_d). - * 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 tripless - * The string tripless array to resize. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). - * - * F_array_too_large (with error bit) if the new array length is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_tripless_increase_by_ - extern f_status_t f_string_tripless_increase_by(const f_array_length_t amount, f_string_tripless_t * const tripless); -#endif // _di_f_string_tripless_increase_by_ - -/** - * Resize the string tripless array. - * - * @param length - * The new size to use. - * @param tripless - * The string tripless array to adjust. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_f_string_tripless_resize_ - extern f_status_t f_string_tripless_resize(const f_array_length_t length, f_string_tripless_t * const tripless); -#endif // _di_f_string_tripless_resize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_string/c/string/triples.c b/level_0/f_string/c/string/triples.c new file mode 100644 index 0000000..bd87e8b --- /dev/null +++ b/level_0/f_string/c/string/triples.c @@ -0,0 +1,184 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-triples.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_triples_adjust_ + f_status_t f_string_triples_adjust(const f_array_length_t length, f_string_triples_t * const triples) { + #ifndef _di_level_0_parameter_checking_ + if (!triples) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_triples_adjust(length, triples); + } +#endif // _di_f_string_triples_adjust_ + +#ifndef _di_f_string_triples_append_ + f_status_t f_string_triples_append(const f_string_triple_t source, f_string_triples_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_triples_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].a.used = 0; + destination->array[destination->used].b.used = 0; + destination->array[destination->used].c.used = 0; + + if (source.a.used) { + status = private_f_string_append(source.a.string, source.a.used, &destination->array[destination->used].a); + if (F_status_is_error(status)) return status; + } + + if (source.b.used) { + status = private_f_string_append(source.b.string, source.b.used, &destination->array[destination->used].b); + if (F_status_is_error(status)) return status; + } + + if (source.c.used) { + status = private_f_string_append(source.c.string, source.c.used, &destination->array[destination->used].c); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_triples_append_ + +#ifndef _di_f_string_triples_append_all_ + f_status_t f_string_triples_append_all(const f_string_triples_t source, f_string_triples_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + source.used > destination->size) { + status = private_f_string_triples_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].a.used = 0; + destination->array[destination->used].b.used = 0; + destination->array[destination->used].c.used = 0; + + if (source.array[i].a.used) { + status = private_f_string_append(source.array[i].a.string, source.array[i].a.used, &destination->array[destination->used].a); + if (F_status_is_error(status)) return status; + } + + if (source.array[i].b.used) { + status = private_f_string_append(source.array[i].b.string, source.array[i].b.used, &destination->array[destination->used].b); + if (F_status_is_error(status)) return status; + } + + if (source.array[i].c.used) { + status = private_f_string_append(source.array[i].c.string, source.array[i].c.used, &destination->array[destination->used].c); + if (F_status_is_error(status)) return status; + } + } // for + + return F_none; + } +#endif // _di_f_string_triples_append_all_ + +#ifndef _di_f_string_triples_decimate_by_ + f_status_t f_string_triples_decimate_by(const f_array_length_t amount, f_string_triples_t * const triples) { + #ifndef _di_level_0_parameter_checking_ + if (!triples) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (triples->size > amount) { + return private_f_string_triples_adjust(triples->size - amount, triples); + } + + return private_f_string_triples_adjust(0, triples); + } +#endif // _di_f_string_triples_decimate_by_ + +#ifndef _di_f_string_triples_decrease_by_ + f_status_t f_string_triples_decrease_by(const f_array_length_t amount, f_string_triples_t * const triples) { + #ifndef _di_level_0_parameter_checking_ + if (!triples) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (triples->size > amount) { + return private_f_string_triples_resize(triples->size - amount, triples); + } + + return private_f_string_triples_resize(0, triples); + } +#endif // _di_f_string_triples_decrease_by_ + +#ifndef _di_f_string_triples_increase_ + f_status_t f_string_triples_increase(const f_array_length_t step, f_string_triples_t * const triples) { + #ifndef _di_level_0_parameter_checking_ + if (!triples) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && triples->used + 1 > triples->size) { + f_array_length_t size = triples->used + F_memory_default_allocation_small_d; + + if (size > F_array_length_t_size_d) { + if (triples->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_triples_resize(size, triples); + } + + return F_data_not; + } +#endif // _di_f_string_triples_increase_ + +#ifndef _di_f_string_triples_increase_by_ + f_status_t f_string_triples_increase_by(const f_array_length_t amount, f_string_triples_t * const triples) { + #ifndef _di_level_0_parameter_checking_ + if (!triples) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (triples->used + amount > triples->size) { + if (triples->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_triples_resize(triples->used + amount, triples); + } + + return F_data_not; + } +#endif // _di_f_string_triples_increase_by_ + +#ifndef _di_f_string_triples_resize_ + f_status_t f_string_triples_resize(const f_array_length_t length, f_string_triples_t * const triples) { + #ifndef _di_level_0_parameter_checking_ + if (!triples) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_triples_resize(length, triples); + } +#endif // _di_f_string_triples_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/triples.h b/level_0/f_string/c/string/triples.h new file mode 100644 index 0000000..deca5d5 --- /dev/null +++ b/level_0/f_string/c/string/triples.h @@ -0,0 +1,234 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines 3-tuple of string data called a triple (which is an ordered list of 3 strings). + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_triples_h +#define _F_string_triples_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of string triples. + * + * array: The array of string triples. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_string_triples_t_ + typedef struct { + f_string_triple_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_triples_t; + + #define f_string_triples_t_initialize f_string_statics_t_initialize + + #define macro_f_string_triples_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_triples_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_triples_t_clear(triples) macro_f_memory_structure_clear(triples) + + #define macro_f_string_triples_t_resize(status, triples, length) status = f_string_triples_resize(length, &triples); + #define macro_f_string_triples_t_adjust(status, triples, length) status = f_string_triples_adjust(length, &triples); + + #define macro_f_string_triples_t_delete_simple(triples) f_string_triples_resize(0, &triples); + #define macro_f_string_triples_t_destroy_simple(triples) f_string_triples_adjust(0, &triples); + + #define macro_f_string_triples_t_increase(status, step, triples) status = f_string_triples_increase(step, triples); + #define macro_f_string_triples_t_increase_by(status, triples, amount) status = f_string_triples_increase_by(amount, triples); + #define macro_f_string_triples_t_decrease_by(status, triples, amount) status = f_string_triples_decrease_by(amount, triples); + #define macro_f_string_triples_t_decimate_by(status, triples, amount) status = f_string_triples_decimate_by(amount, triples); +#endif // _di_f_string_triples_t_ + +/** + * Resize the string triples array. + * + * @param length + * The new size to use. + * @param triples + * The string triples array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_string_triples_adjust_ + extern f_status_t f_string_triples_adjust(const f_array_length_t length, f_string_triples_t * const triples); +#endif // _di_f_string_triples_adjust_ + +/** + * Append the single source triples onto the destination. + * + * @param source + * The source triple to append. + * @param destination + * The destination triples the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_triples_append_ + extern f_status_t f_string_triples_append(const f_string_triple_t source, f_string_triples_t * const destination); +#endif // _di_f_string_triples_append_ + +/** + * Append the source triples onto the destination. + * + * @param source + * The source triples to append. + * @param destination + * The destination triples the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_triples_append_all_ + extern f_status_t f_string_triples_append_all(const f_string_triples_t source, f_string_triples_t * const destination); +#endif // _di_f_string_triples_append_all_ + +/** + * Resize the string triples 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 decimate the size by. + * @param triples + * The string triples array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_triples_decimate_by_ + extern f_status_t f_string_triples_decimate_by(const f_array_length_t amount, f_string_triples_t * const triples); +#endif // _di_f_string_triples_decimate_by_ + +/** + * Resize the string triples 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 triples + * The string triples array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_triples_decrease_by_ + extern f_status_t f_string_triples_decrease_by(const f_array_length_t amount, f_string_triples_t * const triples); +#endif // _di_f_string_triples_decrease_by_ + +/** + * Increase the size of the string triples 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param triples + * The string triples array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_triples_increase_ + extern f_status_t f_string_triples_increase(const f_array_length_t step, f_string_triples_t * const triples); +#endif // _di_f_string_triples_increase_ + +/** + * Resize the string triples 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_d). + * 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 triples + * The string triples array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_triples_increase_by_ + extern f_status_t f_string_triples_increase_by(const f_array_length_t amount, f_string_triples_t * const triples); +#endif // _di_f_string_triples_increase_by_ + +/** + * Resize the string triples array. + * + * @param length + * The new size to use. + * @param triples + * The string triples array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_triples_resize_ + extern f_status_t f_string_triples_resize(const f_array_length_t length, f_string_triples_t * const triples); +#endif // _di_f_string_triples_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_triples_h diff --git a/level_0/f_string/c/string/tripless.c b/level_0/f_string/c/string/tripless.c new file mode 100644 index 0000000..90e5e07 --- /dev/null +++ b/level_0/f_string/c/string/tripless.c @@ -0,0 +1,165 @@ +#include "../string.h" +#include "../private-string.h" +#include "private-triples.h" +#include "private-tripless.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_string_tripless_append_ + f_status_t f_string_tripless_append(const f_string_triples_t source, f_string_tripless_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + 1 > destination->size) { + status = private_f_string_tripless_resize(destination->used + F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + } + + destination->array[destination->used].used = 0; + + if (source.used) { + status = private_f_string_triples_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + + ++destination->used; + + return F_none; + } +#endif // _di_f_string_tripless_append_ + +#ifndef _di_f_string_tripless_append_all_ + f_status_t f_string_tripless_append_all(const f_string_tripless_t source, f_string_tripless_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = F_none; + + if (destination->used + source.used > destination->size) { + status = private_f_string_tripless_resize(destination->used + source.used, destination); + if (F_status_is_error(status)) return status; + } + + for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].used = 0; + + if (source.array[i].used) { + status = private_f_string_triples_append_all(source.array[i], &destination->array[destination->used]); + if (F_status_is_error(status)) return status; + } + } // for + + return F_none; + } +#endif // _di_f_string_tripless_append_all_ + +#ifndef _di_f_string_tripless_adjust_ + f_status_t f_string_tripless_adjust(const f_array_length_t length, f_string_tripless_t * const tripless) { + #ifndef _di_level_0_parameter_checking_ + if (!tripless) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_tripless_adjust(length, tripless); + } +#endif // _di_f_string_tripless_adjust_ + +#ifndef _di_f_string_tripless_decimate_by_ + f_status_t f_string_tripless_decimate_by(const f_array_length_t amount, f_string_tripless_t * const tripless) { + #ifndef _di_level_0_parameter_checking_ + if (!tripless) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (tripless->size > amount) { + return private_f_string_tripless_adjust(tripless->size - amount, tripless); + } + + return private_f_string_tripless_adjust(0, tripless); + } +#endif // _di_f_string_tripless_decimate_by_ + +#ifndef _di_f_string_tripless_decrease_by_ + f_status_t f_string_tripless_decrease_by(const f_array_length_t amount, f_string_tripless_t * const tripless) { + #ifndef _di_level_0_parameter_checking_ + if (!tripless) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (tripless->size > amount) { + return private_f_string_tripless_resize(tripless->size - amount, tripless); + } + + return private_f_string_tripless_resize(0, tripless); + } +#endif // _di_f_string_tripless_decrease_by_ + +#ifndef _di_f_string_tripless_increase_ + f_status_t f_string_tripless_increase(const f_array_length_t step, f_string_tripless_t * const tripless) { + #ifndef _di_level_0_parameter_checking_ + if (!tripless) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && tripless->used + 1 > tripless->size) { + f_array_length_t size = tripless->used + step; + + if (size > F_array_length_t_size_d) { + if (tripless->used + 1 > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + size = F_array_length_t_size_d; + } + + return private_f_string_tripless_resize(size, tripless); + } + + return F_data_not; + } +#endif // _di_f_string_tripless_increase_ + +#ifndef _di_f_string_tripless_increase_by_ + f_status_t f_string_tripless_increase_by(const f_array_length_t amount, f_string_tripless_t * const tripless) { + #ifndef _di_level_0_parameter_checking_ + if (!tripless) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (tripless->used + amount > tripless->size) { + if (tripless->used + amount > F_array_length_t_size_d) { + return F_status_set_error(F_array_too_large); + } + + return private_f_string_tripless_resize(tripless->used + amount, tripless); + } + + return F_data_not; + } +#endif // _di_f_string_tripless_increase_by_ + +#ifndef _di_f_string_tripless_resize_ + f_status_t f_string_tripless_resize(const f_array_length_t length, f_string_tripless_t * const tripless) { + #ifndef _di_level_0_parameter_checking_ + if (!tripless) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_string_tripless_resize(length, tripless); + } +#endif // _di_f_string_tripless_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_string/c/string/tripless.h b/level_0/f_string/c/string/tripless.h new file mode 100644 index 0000000..28167fd --- /dev/null +++ b/level_0/f_string/c/string/tripless.h @@ -0,0 +1,234 @@ +/** + * FLL - Level 0 + * + * Project: String + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines 3-tuple of string data called a triple (which is an ordered list of 3 strings). + * + * This is auto-included by string.h and should not need to be explicitly included. + */ +#ifndef _F_string_tripless_h +#define _F_string_tripless_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * An array of string tripless. + * + * array: The array of string triples. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_string_tripless_t_ + typedef struct { + f_string_triples_t *array; + + f_array_length_t size; + f_array_length_t used; + } f_string_tripless_t; + + #define f_string_tripless_t_initialize f_string_statics_t_initialize + + #define macro_f_string_tripless_t_initialize(array, size, used) { array, size, used } + #define macro_f_string_tripless_t_initialize2(array, length) { array, length, length } + + #define macro_f_string_tripless_t_clear(tripless) macro_f_memory_structure_clear(tripless) + + #define macro_f_string_tripless_t_resize(status, tripless, length) status = f_string_tripless_resize(length, &tripless); + #define macro_f_string_tripless_t_adjust(status, tripless, length) status = f_string_tripless_adjust(length, &tripless); + + #define macro_f_string_tripless_t_delete_simple(tripless) f_string_tripless_resize(0, &tripless); + #define macro_f_string_tripless_t_destroy_simple(tripless) f_string_tripless_adjust(0, &tripless); + + #define macro_f_string_tripless_t_increase(status, step, tripless) status = f_string_tripless_increase(step, tripless); + #define macro_f_string_tripless_t_increase_by(status, tripless, amount) status = f_string_tripless_increase_by(amount, tripless); + #define macro_f_string_tripless_t_decrease_by(status, tripless, amount) status = f_string_tripless_decrease_by(amount, tripless); + #define macro_f_string_tripless_t_decimate_by(status, tripless, amount) status = f_string_tripless_decimate_by(amount, tripless); +#endif // _di_f_string_tripless_t_ + +/** + * Resize the string tripless array. + * + * @param length + * The new size to use. + * @param tripless + * The string tripless array to resize. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_string_tripless_adjust_ + extern f_status_t f_string_tripless_adjust(const f_array_length_t length, f_string_tripless_t * const tripless); +#endif // _di_f_string_tripless_adjust_ + +/** + * Append the single source triples onto the destination. + * + * @param source + * The source triples to append. + * @param destination + * The destination tripless the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_tripless_append_ + extern f_status_t f_string_tripless_append(const f_string_triples_t source, f_string_tripless_t * const destination); +#endif // _di_f_string_tripless_append_ + +/** + * Append the source tripless onto the destination. + * + * @param source + * The source tripless to append. + * @param destination + * The destination tripless the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * F_string_too_large (with error bit) if the combined string is too large. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_tripless_append_all_ + extern f_status_t f_string_tripless_append_all(const f_string_tripless_t source, f_string_tripless_t * const destination); +#endif // _di_f_string_tripless_append_all_ + +/** + * Resize the string tripless 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 decimate the size by. + * @param tripless + * The string tripless array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_tripless_decimate_by_ + extern f_status_t f_string_tripless_decimate_by(const f_array_length_t amount, f_string_tripless_t * const tripless); +#endif // _di_f_string_tripless_decimate_by_ + +/** + * Resize the string tripless 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 tripless + * The string tripless array to resize. + * + * @return + * F_none on success. + * F_data_not if amount is 0. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_tripless_decrease_by_ + extern f_status_t f_string_tripless_decrease_by(const f_array_length_t amount, f_string_tripless_t * const tripless); +#endif // _di_f_string_tripless_decrease_by_ + +/** + * Increase the size of the string tripless 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_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param tripless + * The string tripless array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_tripless_increase_ + extern f_status_t f_string_tripless_increase(const f_array_length_t step, f_string_tripless_t * const tripless); +#endif // _di_f_string_tripless_increase_ + +/** + * Resize the string tripless 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_d). + * 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 tripless + * The string tripless array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_tripless_increase_by_ + extern f_status_t f_string_tripless_increase_by(const f_array_length_t amount, f_string_tripless_t * const tripless); +#endif // _di_f_string_tripless_increase_by_ + +/** + * Resize the string tripless array. + * + * @param length + * The new size to use. + * @param tripless + * The string tripless array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_tripless_resize_ + extern f_status_t f_string_tripless_resize(const f_array_length_t length, f_string_tripless_t * const tripless); +#endif // _di_f_string_tripless_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_string_tripless_h diff --git a/level_0/f_string/data/build/settings b/level_0/f_string/data/build/settings index 9fcd079..34a9bb2 100644 --- a/level_0/f_string/data/build/settings +++ b/level_0/f_string/data/build/settings @@ -20,9 +20,10 @@ build_language c build_libraries -lc build_libraries-individual -lf_memory -build_sources_library string.c private-string.c string/common.c string/private-dynamic.c string/private-map.c string/private-map_multi.c string/private-quantity.c string/private-range.c string/private-triple.c string/dynamic.c string/map.c string/map_multi.c string/quantity.c string/range.c string/static.c string/triple.c +build_sources_library string.c private-string.c string/common.c string/private-dynamic.c string/private-dynamics.c string/private-dynamicss.c string/private-maps.c string/private-mapss.c string/private-map_multis.c string/private-map_multiss.c string/private-quantitys.c string/private-quantityss.c string/private-ranges.c string/private-rangess.c string/private-triples.c string/private-tripless.c +build_sources_library string/dynamic.c string/dynamics.c string/dynamicss.c string/map.c string/maps.c string/mapss.c string/map_multi.c string/map_multis.c string/map_multiss.c string/quantity.c string/quantitys.c string/quantityss.c string/range.c string/ranges.c string/rangess.c string/static.c string/statics.c string/staticss.c string/triple.c string/triples.c string/tripless.c -build_sources_headers string.h string/common.h string/dynamic.h string/map.h string/map_multi.h string/quantity.h string/range.h string/static.h string/triple.h +build_sources_headers string.h string/common.h string/dynamic.h string/dynamics.h string/dynamicss.h string/map.h string/maps.h string/mapss.h string/map_multi.h string/map_multis.h string/map_multiss.h string/quantity.h string/quantitys.h string/quantityss.h string/range.h string/ranges.h string/rangess.h string/static.h string/statics.h string/staticss.h string/triple.h string/triples.h string/tripless.h build_script yes build_shared yes