There are a lot of string functions.
In this case, it seems worth more to use functions instead of relying on macros, given how common this is.
This does not update most of the existing code that may want to use this.
Future consideration will likely be made in regards to the array of array string types.
There is no intention to expand this process to other types.
}
#endif // _di_fl_string_dynamic_prepend_nulless_
+#ifndef _di_fl_string_dynamic_size_decrease_
+ f_return_status fl_string_dynamic_size_decrease(const f_string_length length, f_string_dynamic *string) {
+ #ifndef _di_level_1_parameter_checking_
+ if (length == 0) return F_status_set_error(F_parameter);
+ if (string == 0) return F_status_set_error(F_parameter);
+ #endif // _di_level_1_parameter_checking_
+
+ f_status status = F_none;
+
+ if (string->used - length > 0) {
+ f_macro_string_dynamic_resize(status, (*string), string->size - length);
+ }
+ else if (string->used - length <= 0) {
+ f_macro_string_dynamic_delete(status, (*string));
+ }
+
+ return status;
+ }
+#endif // _di_fl_string_dynamic_size_decrease_
+
+#ifndef _di_fl_string_dynamic_size_increase_
+ f_return_status fl_string_dynamic_size_increase(const f_string_length length, f_string_dynamic *string) {
+ #ifndef _di_level_1_parameter_checking_
+ if (length == 0) return F_status_set_error(F_parameter);
+ if (string == 0) return F_status_set_error(F_parameter);
+ #endif // _di_level_1_parameter_checking_
+
+ f_status status = F_none;
+
+ if (string->used + length > string->size) {
+ if (string->used + length > f_string_length_size) {
+ if (string->used == f_string_length_size) {
+ status = F_status_set_error(F_string_too_large);
+ }
+ else {
+ f_macro_string_dynamic_resize(status, (*string), f_string_length_size);
+ }
+ }
+ else {
+ f_macro_string_dynamic_resize(status, (*string), string->size + length);
+ }
+ }
+
+ return status;
+ }
+#endif // _di_fl_string_dynamic_size_increase_
+
+#ifndef _di_fl_string_dynamics_size_decrease_
+ f_return_status fl_string_dynamics_size_decrease(const f_array_length length, f_string_dynamics *strings) {
+ #ifndef _di_level_1_parameter_checking_
+ if (length == 0) return F_status_set_error(F_parameter);
+ if (strings == 0) return F_status_set_error(F_parameter);
+ #endif // _di_level_1_parameter_checking_
+
+ f_status status = F_none;
+
+ if (strings->used - length > 0) {
+ f_macro_string_dynamics_resize(status, (*strings), strings->size - length);
+ }
+ else if (strings->used - length <= 0) {
+ f_macro_string_dynamics_delete(status, (*strings));
+ }
+
+ return status;
+ }
+#endif // _di_fl_string_dynamics_size_decrease_
+
+#ifndef _di_fl_string_dynamics_size_increase_
+ f_return_status fl_string_dynamics_size_increase(const f_array_length length, f_string_dynamics *strings) {
+ #ifndef _di_level_1_parameter_checking_
+ if (length == 0) return F_status_set_error(F_parameter);
+ if (strings == 0) return F_status_set_error(F_parameter);
+ #endif // _di_level_1_parameter_checking_
+
+ f_status status = F_none;
+
+ if (strings->used + length > strings->size) {
+ if (strings->used + length > f_array_length_size) {
+ if (strings->used == f_array_length_size) {
+ status = F_status_set_error(F_string_too_large);
+ }
+ else {
+ f_macro_string_dynamics_resize(status, (*strings), f_array_length_size);
+ }
+ }
+ else {
+ f_macro_string_dynamics_resize(status, (*strings), strings->size + length);
+ }
+ }
+
+ return status;
+ }
+#endif // _di_fl_string_dynamics_size_increase_
+
#ifndef _di_fl_string_dynamic_rip_
f_return_status fl_string_dynamic_rip(const f_string_static source, const f_string_range range, f_string_dynamic *destination) {
#ifndef _di_level_1_parameter_checking_
}
#endif // _di_fl_string_dynamic_terminate_after_
+#ifndef _di_fl_string_lengths_size_decrease_
+ f_return_status fl_string_lengths_size_decrease(const f_array_length length, f_string_lengths *lengths) {
+ #ifndef _di_level_1_parameter_checking_
+ if (length == 0) return F_status_set_error(F_parameter);
+ if (lengths == 0) return F_status_set_error(F_parameter);
+ #endif // _di_level_1_parameter_checking_
+
+ f_status status = F_none;
+
+ if (lengths->used - length > 0) {
+ f_macro_string_lengths_resize(status, (*lengths), lengths->size - length);
+ }
+ else if (lengths->used - length <= 0) {
+ f_macro_string_lengths_delete(status, (*lengths));
+ }
+
+ return status;
+ }
+#endif // _di_fl_string_lengths_size_decrease_
+
+#ifndef _di_fl_string_lengths_size_increase_
+ f_return_status fl_string_lengths_size_increase(const f_array_length length, f_string_lengths *lengths) {
+ #ifndef _di_level_1_parameter_checking_
+ if (length == 0) return F_status_set_error(F_parameter);
+ if (lengths == 0) return F_status_set_error(F_parameter);
+ #endif // _di_level_1_parameter_checking_
+
+ f_status status = F_none;
+
+ if (lengths->used + length > lengths->size) {
+ if (lengths->used + length > f_array_length_size) {
+ if (lengths->used == f_array_length_size) {
+ status = F_status_set_error(F_string_too_large);
+ }
+ else {
+ f_macro_string_lengths_resize(status, (*lengths), f_array_length_size);
+ }
+ }
+ else {
+ f_macro_string_lengths_resize(status, (*lengths), lengths->size + length);
+ }
+ }
+
+ return status;
+ }
+#endif // _di_fl_string_lengths_size_increase_
+
#ifndef _di_fl_string_mash_
f_return_status fl_string_mash(const f_string glue, const f_string_length glue_length, const f_string source, const f_string_length length, f_string_dynamic *destination) {
#ifndef _di_level_1_parameter_checking_
#endif // _di_fl_string_dynamic_prepend_nulless_
/**
+ * Resize the dynamic string to a smaller size.
+ *
+ * This will resize making the string smaller based on the 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 length
+ * A positive number greater than 0 representing how much to decrease the size by.
+ * @param string
+ * The string to resize.
+ *
+ * @return
+ * F_none on success.
+ * F_memory_allocation (with error bit) on memory allocation error.
+ * F_memory_reallocation (with error bit) on memory reallocation error.
+ * F_parameter (with error bit) if a parameter is invalid.
+ * F_string_too_large (with error bit) if the combined string is too large.
+ */
+#ifndef _di_fl_string_dynamic_size_decrease_
+ extern f_return_status fl_string_dynamic_size_decrease(const f_string_length length, f_string_dynamic *string);
+#endif // _di_fl_string_dynamic_size_decrease_
+
+/**
+ * Resize the dynamic string 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_string_length_size).
+ * If already set to the maximum buffer size, then the resize will fail.
+ *
+ * @param length
+ * A positive number greater than 0 representing how much to increase the size by.
+ * @param string
+ * The string to resize.
+ *
+ * @return
+ * F_none on success.
+ * F_memory_allocation (with error bit) on memory allocation error.
+ * F_memory_reallocation (with error bit) on memory reallocation error.
+ * F_parameter (with error bit) if a parameter is invalid.
+ * F_string_too_large (with error bit) if the combined string is too large.
+ */
+#ifndef _di_fl_string_dynamic_size_increase_
+ extern f_return_status fl_string_dynamic_size_increase(const f_string_length length, f_string_dynamic *string);
+#endif // _di_fl_string_dynamic_size_increase_
+
+/**
+ * Resize the array of dynamic strings to a smaller size.
+ *
+ * This will resize making the string smaller based on the 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 length
+ * A positive number greater than 0 representing how much to decrease the size by.
+ * @param strings
+ * The string array to resize.
+ *
+ * @return
+ * F_none on success.
+ * F_memory_allocation (with error bit) on memory allocation error.
+ * F_memory_reallocation (with error bit) on memory reallocation error.
+ * F_parameter (with error bit) if a parameter is invalid.
+ * F_string_too_large (with error bit) if the combined string is too large.
+ */
+#ifndef _di_fl_string_dynamics_size_decrease_
+ extern f_return_status fl_string_dynamics_size_decrease(const f_array_length length, f_string_dynamics *strings);
+#endif // _di_fl_string_dynamics_size_decrease_
+
+/**
+ * Resize the array of dynamic strings 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_size).
+ * If already set to the maximum buffer size, then the resize will fail.
+ *
+ * @param length
+ * A positive number greater than 0 representing how much to increase the size by.
+ * @param strings
+ * The string array to resize.
+ *
+ * @return
+ * F_none on success.
+ * F_memory_allocation (with error bit) on memory allocation error.
+ * F_memory_reallocation (with error bit) on memory reallocation error.
+ * F_parameter (with error bit) if a parameter is invalid.
+ * F_string_too_large (with error bit) if the combined string is too large.
+ */
+#ifndef _di_fl_string_dynamics_size_increase_
+ extern f_return_status fl_string_dynamics_size_increase(const f_array_length length, f_string_dynamics *strings);
+#endif // _di_fl_string_dynamics_size_increase_
+
+/**
* Allocate a new string from the provided range in the buffer.
*
* Ignores leading and trailing whitespace.
#endif // _di_fl_string_dynamic_terminate_after_
/**
+ * Resize the array of string lengths to a smaller size.
+ *
+ * This will resize making the string smaller based on the 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 length
+ * A positive number greater than 0 representing how much to decrease the size by.
+ * @param strings
+ * The string array to resize.
+ *
+ * @return
+ * F_none on success.
+ * F_memory_allocation (with error bit) on memory allocation error.
+ * F_memory_reallocation (with error bit) on memory reallocation error.
+ * F_parameter (with error bit) if a parameter is invalid.
+ * F_string_too_large (with error bit) if the combined string is too large.
+ */
+#ifndef _di_fl_string_lengths_size_decrease_
+ extern f_return_status fl_string_length_size_decrease(const f_array_length length, f_string_lengths *lengths);
+#endif // _di_fl_string_lengths_size_decrease_
+
+/**
+ * Resize the array of string lengths 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_size).
+ * If already set to the maximum buffer size, then the resize will fail.
+ *
+ * @param length
+ * A positive number greater than 0 representing how much to increase the size by.
+ * @param strings
+ * The string array to resize.
+ *
+ * @return
+ * F_none on success.
+ * F_memory_allocation (with error bit) on memory allocation error.
+ * F_memory_reallocation (with error bit) on memory reallocation error.
+ * F_parameter (with error bit) if a parameter is invalid.
+ * F_string_too_large (with error bit) if the combined string is too large.
+ */
+#ifndef _di_fl_string_lengths_size_increase_
+ extern f_return_status fl_string_lengths_size_increase(const f_array_length length, f_string_lengths *lengths);
+#endif // _di_fl_string_lengths_size_increase_
+
+/**
* Append the source string onto the destination with the glue in between.
*
* If the destination string is empty, then no glue is appended.
}
else {
if (destination->used == destination->size) {
- f_macro_string_dynamic_resize(status, (*destination), destination->size + f_fss_default_allocation_step_string);
+ status = fl_string_dynamic_size_increase(f_fss_default_allocation_step_string, destination);
if (F_status_is_error(status)) return status;
}
#include <level_1/fss_macro.h>
#include <level_1/fss_status.h>
#include <level_1/fss_basic.h>
+#include <level_1/string.h>
#ifdef __cplusplus
extern "C" {
}
else {
if (buffer->used == buffer->size) {
- f_macro_string_dynamic_resize(status, (*buffer), buffer->size + f_fss_default_allocation_step_string);
+ status = fl_string_dynamic_size_increase(f_fss_default_allocation_step_string, buffer);
if (F_status_is_error(status)) return status;
}
#include <level_1/fss_basic_list.h>
#include <level_1/fss_status.h>
#include <level_1/fss_macro.h>
+#include <level_1/string.h>
#ifdef __cplusplus
extern "C" {
}
else {
if (buffer->used == buffer->size) {
- f_macro_string_dynamic_resize(status, (*buffer), buffer->size + f_fss_default_allocation_step_string);
+ status = fl_string_dynamic_size_increase(f_fss_default_allocation_step_string, buffer);
if (F_status_is_error(status)) return status;
}