From: Kevin Day Date: Thu, 19 May 2022 05:56:28 +0000 (-0500) Subject: Update: Rewrite the f_serialize functions. X-Git-Tag: 0.5.10~116 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=22330623cd3a26b487d94b49e065439af1b79816;p=fll Update: Rewrite the f_serialize functions. The code is outdated and needs to be updated with the current practices. I remember being uncertain on what to name several of these functions. I didn't want an f_unserialize function because that would require a separate project (even if the naming makes sense). Perhaps I may do that in the future, but for now just use the words "from" and "to". --- diff --git a/level_0/f_serialize/c/private-serialize.c b/level_0/f_serialize/c/private-serialize.c index 2a19e0d..9c83501 100644 --- a/level_0/f_serialize/c/private-serialize.c +++ b/level_0/f_serialize/c/private-serialize.c @@ -5,30 +5,27 @@ extern "C" { #endif -#if !defined(_di_f_serialize_un_simple_find_) || !defined(_di_f_serialize_un_simple_get_) - f_status_t private_f_serialize_un_simple_find(const f_string_static_t serialize, const f_array_length_t index, f_string_range_t * const location) { +#if !defined(_di_f_serialize_from_simple_get_) || !defined(_di_f_serialize_from_simple_select_) + f_status_t private_f_serialize_from_simple_select(const f_string_static_t source, const f_array_length_t index, f_string_range_t * const range) { - f_array_length_t i = 0; f_array_length_t start = 0; f_array_length_t current = 0; unsigned short width = 0; - for (; i < serialize.used; i += width) { + for (f_array_length_t i = 0; i < source.used; i += width) { - width = macro_f_utf_byte_width(serialize.string[i]); + width = macro_f_utf_byte_width(source.string[i]); - if (serialize.string[i] == f_serialize_simple_splitter_s.string[0]) { + if (source.string[i] == f_serialize_to_simple_splitter_s.string[0]) { if (current == index) { if (start == i) { - - // provide an invalid start to stop range to communicate that there is no data. - location->start = 1; - location->stop = 0; + range->start = 1; + range->stop = 0; } else { - location->start = start; - location->stop = i - 1; + range->start = start; + range->stop = i - 1; } return F_none; @@ -36,24 +33,32 @@ extern "C" { start = i + width; ++current; + + // Handle case when splitter as at the end of the string, creating a new empty string. + if (start >= source.used && current == index) { + range->start = 1; + range->stop = 0; + + return F_none; + } } - else if (i == serialize.used) { + else if (i == source.used) { if (current == index) { - location->start = start; - location->stop = i - 1; + range->start = start; + range->stop = i - 1; } return F_none_eos; } - if (i + width > serialize.used) { + if (i + width > source.used) { return F_status_set_error(F_complete_not_utf_eos); } } // for return F_data_not_eos; } -#endif // !defined(_di_f_serialize_un_simple_find_) || !defined(_di_f_serialize_un_simple_get_) +#endif // !defined(_di_f_serialize_from_simple_get_) || !defined(_di_f_serialize_from_simple_select_) #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_serialize/c/private-serialize.h b/level_0/f_serialize/c/private-serialize.h index 2bf9848..400a1e7 100644 --- a/level_0/f_serialize/c/private-serialize.h +++ b/level_0/f_serialize/c/private-serialize.h @@ -16,16 +16,16 @@ extern "C" { #endif /** - * Private implementation of f_serialize_un_simple_get(). + * Private implementation of f_serialize_from_simple_get(). * * Intended to be shared to each of the different implementation variations. * - * @param serialize - * A serialize string to de-serialize. + * @param source + * A serialized string to de-serialize. * @param index - * An index position within the serialize string to get the deserialize positions of. - * @param location - * A location within the serialize string representing the string at the given index. + * The selected position within the serialize string to get the deserialize positions of. + * @param range + * A range within the serialize string representing the string at the given index. * * @return * F_none on success. @@ -35,9 +35,9 @@ extern "C" { * F_complete_not_utf_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * F_parameter (with error bit) if a parameter is invalid. */ -#if !defined(_di_f_serialize_un_simple_find_) || !defined(_di_f_serialize_un_simple_get_) - extern f_status_t private_f_serialize_un_simple_find(const f_string_static_t serialize, const f_array_length_t index, f_string_range_t * const location) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_serialize_un_simple_find_) || !defined(_di_f_serialize_un_simple_get_) +#if !defined(_di_f_serialize_from_simple_get_) || !defined(_di_f_serialize_from_simple_select_) + extern f_status_t private_f_serialize_from_simple_select(const f_string_static_t source, const f_array_length_t index, f_string_range_t * const range) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_serialize_from_simple_get_) || !defined(_di_f_serialize_from_simple_select_) #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_serialize/c/serialize.c b/level_0/f_serialize/c/serialize.c index bb45337..8cee1b6 100644 --- a/level_0/f_serialize/c/serialize.c +++ b/level_0/f_serialize/c/serialize.c @@ -5,201 +5,231 @@ extern "C" { #endif -#ifndef _di_f_serialize_simple_ - f_status_t f_serialize_simple(const f_string_static_t value, f_string_dynamic_t * const serialize) { +#ifndef _di_f_serialize_from_simple_ + f_status_t f_serialize_from_simple(const f_string_static_t source, f_string_dynamics_t * const destination) { #ifndef _di_level_0_parameter_checking_ - if (!serialize) return F_status_set_error(F_parameter); + 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; + f_array_length_t i = 0; + f_array_length_t start = 0; + f_array_length_t total = 0; + uint8_t width = 0; - if (serialize->used + value.used + 1 >= serialize->size) { - status = f_string_dynamic_resize(serialize->size + value.used + 1, serialize); - if (F_status_is_error(status)) return status; - } + do { + width = macro_f_utf_byte_width(source.string[i]); - if (!serialize->used) { - memcpy(serialize->string + serialize->used, value.string, sizeof(f_char_t) * value.used); - serialize->used += value.used; - } - else { - memcpy(serialize->string + serialize->used, f_serialize_simple_splitter_s.string, sizeof(f_char_t) * f_serialize_simple_splitter_s.used); - memcpy(serialize->string + serialize->used + f_serialize_simple_splitter_s.used, value.string, sizeof(f_char_t) * value.used); - serialize->used += value.used + 1; - } + if (i + width > source.used) { + total = i - start; - return F_none; - } -#endif // _di_f_serialize_simple_ + status = f_string_dynamics_increase(F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; -#ifndef _di_f_serialize_un_simple_ - f_status_t f_serialize_un_simple(const f_string_static_t serialize, f_string_dynamics_t * const strings) { - #ifndef _di_level_0_parameter_checking_ - if (!serialize.used) return F_status_set_error(F_parameter); - if (!strings) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ + destination->array[destination->used].used = 0; - f_status_t status = F_none; + status = f_string_append(source.string + start, total, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; - f_array_length_t i = 0; - f_array_length_t start = 0; + ++destination->used; - uint8_t width = 0; + return F_complete_not_utf_eos; + } + + if (source.string[i] == f_serialize_to_simple_splitter_s.string[0]) { + total = i - start; - while (i < serialize.used) { + status = f_string_dynamics_increase(F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; - width = macro_f_utf_byte_width(serialize.string[i]); + destination->array[destination->used].used = 0; - if (serialize.string[i] == f_serialize_simple_splitter_s.string[0] || i + 1 >= serialize.used) { - macro_f_memory_structure_increment(status, (*strings), 1, F_memory_default_allocation_small_d, macro_f_string_dynamics_t_resize, F_array_too_large); + status = f_string_append(source.string + start, total, &destination->array[destination->used]); if (F_status_is_error(status)) return status; - if (start == i) { - strings->array[strings->used].used = 0; - ++strings->used; + ++destination->used; + start = i + width; + + // Handle case when splitter as at the end of the string, creating a new empty string. + if (start == source.used) { + status = f_string_dynamics_increase(F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; + + destination->array[++destination->used].used = 0; } - else { - f_array_length_t total; + } - if (i + 1 >= serialize.used) { - total = (i - start) + 1; - } - else { + i += width; - // subtract one from stop point to disclused the f_serialize_simple_splitter_s character. - total = ((i - 1) - start) + 1; - } + } while (i < source.used); - if (total > strings->array[strings->used].size) { - macro_f_string_dynamic_t_clear(strings->array[strings->used]) + if (start < source.used) { + total = source.used - start; - status = f_string_dynamic_resize(total, &strings->array[strings->used]); - if (F_status_is_error(status)) return status; + status = f_string_dynamics_increase(F_memory_default_allocation_small_d, destination); + if (F_status_is_error(status)) return status; - strings->array[strings->used].size = total; - } + destination->array[destination->used].used = 0; - memcpy(strings->array[strings->used].string, serialize.string + start, sizeof(f_char_t) * total); + status = f_string_append(source.string + start, total, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; - strings->array[strings->used].used = total; - ++strings->used; - } + ++destination->used; + } - if (i + width > serialize.used) { - return F_status_set_error(F_complete_not_utf_eos); - } + return F_none; + } +#endif // _di_f_serialize_from_simple_ - start = i + width; - } - else if (i + width > serialize.used) { - return F_status_set_error(F_complete_not_utf_eos); - } +#ifndef _di_f_serialize_from_simple_get_ + f_status_t f_serialize_from_simple_get(const f_string_static_t source, const f_array_length_t index, f_string_dynamic_t * const destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ - i += width; - } // while + if (!source.used) return F_data_not; - return F_none; + f_string_range_t range = f_string_range_t_initialize; + + f_status_t status = private_f_serialize_from_simple_select(source, index, &range); + if (F_status_is_error(status)) return status; + + if (status == F_data_not_eos) { + return status; + } + + const f_array_length_t total = (range.stop - range.start) + 1; + + if (range.start <= range.stop) { + const f_status_t status_allocation = f_string_append(source.string + range.start, total, destination); + if (F_status_is_error(status_allocation)) return status_allocation; + } + + return status; } -#endif // _di_f_serialize_un_simple_ +#endif // _di_f_serialize_from_simple_get_ -#ifndef _di_f_serialize_un_simple_map_ - f_status_t f_serialize_un_simple_map(const f_string_static_t serialize, f_string_ranges_t * const locations) { +#ifndef _di_f_serialize_from_simple_range_ + f_status_t f_serialize_from_simple_range(const f_string_static_t source, f_string_ranges_t * const ranges) { #ifndef _di_level_0_parameter_checking_ - if (!serialize.used) return F_status_set_error(F_parameter); - if (!locations) return F_status_set_error(F_parameter); + if (!ranges) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - f_status_t status = F_none; + if (!source.used) return F_data_not; + f_status_t status = F_none; f_array_length_t i = 0; f_array_length_t start = 0; - + f_array_length_t total = 0; uint8_t width = 0; - for (; i < serialize.used; i += width) { + do { + width = macro_f_utf_byte_width(source.string[i]); - width = macro_f_utf_byte_width(serialize.string[i]); + if (i + width > source.used) { + total = i - start; - if (serialize.string[i] == f_serialize_simple_splitter_s.string[0] || i + 1 >= serialize.used) { - macro_f_memory_structure_increment(status, (*locations), 1, F_memory_default_allocation_small_d, macro_f_string_ranges_t_resize, F_array_too_large); + status = f_string_ranges_increase(F_memory_default_allocation_small_d, ranges); if (F_status_is_error(status)) return status; - if (start == i) { - - // provide an invalid start to stop range to communicate that there is no data. - locations->array[locations->used].start = 1; - locations->array[locations->used].stop = 0; - } - else if (i + 1 >= serialize.used) { - locations->array[locations->used].start = start; - locations->array[locations->used].stop = i; + if (total) { + ranges->array[ranges->used].start = start; + ranges->array[ranges->used++].stop = start + (total - 1); } else { - - // subtract one from stop point to disclused the f_serialize_simple_splitter_s character. - locations->array[locations->used].start = start; - locations->array[locations->used].stop = i - 1; + ranges->array[ranges->used].start = 1; + ranges->array[ranges->used++].stop = 0; } - ++locations->used; + return F_complete_not_utf_eos; + } + + if (source.string[i] == f_serialize_to_simple_splitter_s.string[0]) { + total = i - start; - if (i + width > serialize.used) { - return F_status_set_error(F_complete_not_utf_eos); + status = f_string_ranges_increase(F_memory_default_allocation_small_d, ranges); + if (F_status_is_error(status)) return status; + + if (total) { + ranges->array[ranges->used].start = start; + ranges->array[ranges->used++].stop = start + (total - 1); + } + else { + ranges->array[ranges->used].start = 1; + ranges->array[ranges->used++].stop = 0; } start = i + width; + + // Handle case when splitter as at the end of the string, creating a new empty string. + if (start == source.used) { + status = f_string_ranges_increase(F_memory_default_allocation_small_d, ranges); + if (F_status_is_error(status)) return status; + + ranges->array[ranges->used].start = 1; + ranges->array[ranges->used++].stop = 0; + } + } + + i += width; + + } while (i < source.used); + + if (start < source.used) { + total = source.used - start; + + status = f_string_ranges_increase(F_memory_default_allocation_small_d, ranges); + if (F_status_is_error(status)) return status; + + if (total) { + ranges->array[ranges->used].start = start; + ranges->array[ranges->used++].stop = start + (total - 1); } - else if (i + width > serialize.used) { - return F_status_set_error(F_complete_not_utf_eos); + else { + ranges->array[ranges->used].start = 1; + ranges->array[ranges->used++].stop = 0; } - } // for + } return F_none; } -#endif // _di_f_serialize_un_simple_map_ +#endif // _di_f_serialize_from_simple_range_ -#ifndef _di_f_serialize_un_simple_find_ - f_status_t f_serialize_un_simple_find(const f_string_static_t serialize, const f_array_length_t index, f_string_range_t * const range) { +#ifndef _di_f_serialize_from_simple_select_ + f_status_t f_serialize_from_simple_select(const f_string_static_t source, const f_array_length_t index, f_string_range_t * const range) { #ifndef _di_level_0_parameter_checking_ - if (!serialize.used) return F_status_set_error(F_parameter); if (!range) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_serialize_un_simple_find(serialize, index, range); + if (!source.used) return F_data_not; + + return private_f_serialize_from_simple_select(source, index, range); } -#endif // _di_f_serialize_un_simple_find_ +#endif // _di_f_serialize_from_simple_select_ -#ifndef _di_f_serialize_un_simple_get_ - f_status_t f_serialize_un_simple_get(const f_string_static_t serialize, const f_array_length_t index, f_string_dynamic_t * const dynamic) { +#ifndef _di_f_serialize_to_simple_ + f_status_t f_serialize_to_simple(const f_string_static_t source, f_string_dynamic_t * const destination) { #ifndef _di_level_0_parameter_checking_ - if (!serialize.used) return F_status_set_error(F_parameter); - if (!dynamic) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - f_string_range_t range = f_string_range_t_initialize; - - f_status_t status = private_f_serialize_un_simple_find(serialize, index, &range); - if (F_status_is_error(status)) return status; + if (!source.used) return F_data_not; - if (status == F_data_not_eos) { - dynamic->used = 0; - - return status; - } - - f_array_length_t total = (range.stop - range.start) + 1; + f_status_t status = F_none; - if (total >= dynamic->size) { - const f_status_t status_allocation = f_string_dynamic_resize(total, dynamic); - if (F_status_is_error(status_allocation)) return status_allocation; + if (destination->used) { + status = f_string_dynamic_append_assure(f_serialize_to_simple_splitter_s, destination); + if (F_status_is_error(status)) return status; } - memcpy(dynamic->string, serialize.string + range.start, sizeof(f_char_t) * total); - dynamic->used = total; + status = f_string_dynamic_append(source, destination); + if (F_status_is_error(status)) return status; - return status; + return F_none; } -#endif // _di_f_serialize_un_simple_get_ +#endif // _di_f_serialize_to_simple_ #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_serialize/c/serialize.h b/level_0/f_serialize/c/serialize.h index 677aad0..6f0526d 100644 --- a/level_0/f_serialize/c/serialize.h +++ b/level_0/f_serialize/c/serialize.h @@ -30,54 +30,73 @@ extern "C" { #endif /** - * Serialized a string using the Simple serialize algorithm. + * Deserialize the entire serialize string into multiple separate strings using the Simple serialize algorithm. * * The simple Serialize algorithm is akin to the PATH environment variable, example: PATH="/bin:/sbin:/usr/bin". * - * To generate the above example, this would be called 3 times, with the following strings: - * 1) value = "/bin", then: PATH="/bin". - * 2) value = "/sbin", then: PATH="/bin:/sbin". - * 3) value = "/usr/sbin", then: PATH="/bin:/sbin:/usr/sbin". + * After processing the above example, there would be strings derived from the following positions: + * 1) start = 0, stop = 3. + * 2) start = 5, stop = 9. + * 3) start = 11, stop = 18. * - * @param value - * The string to append onto serialize. - * @param serialize - * The dynamic string that represents a serialize set of strings. + * @param source + * A serialized string to deserialize. + * @param destination + * An array of strings deserialize from the source string. + * The individual strings will be NULL terminated after destination.used on success. + * All deserialized values are appended to the destination. * * @return * F_none on success. - * F_memory_not (with error bit) on out of memory. + * F_complete_not_utf_eos if an incomplete UTF-8 character is found at the end of the source. + * F_data_not on success and source.used is 0. + * * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from f_string_append(); + * Errors (with error bit) from f_string_dynamics_increase_by(); + * + * @see f_string_append() + * @see f_string_dynamics_increase_by() */ -#ifndef _di_f_serialize_simple_ - extern f_status_t f_serialize_simple(const f_string_static_t value, f_string_dynamic_t * const serialize); -#endif // _di_f_serialize_simple_ +#ifndef _di_f_serialize_from_simple_ + extern f_status_t f_serialize_from_simple(const f_string_static_t source, f_string_dynamics_t * const destination); +#endif // _di_f_serialize_from_simple_ /** - * De-serialize the entire serialize string into multiple separate strings using the Simple serialize algorithm. + * Unserialize and get a copy of a specific string using the Simple serialize algorithm. * * The simple Serialize algorithm is akin to the PATH environment variable, example: PATH="/bin:/sbin:/usr/bin". * - * After processing the above example, there would be the following positions: - * 1) start = 0, stop = 3. - * 2) start = 5, stop = 9. - * 3) start = 11, stop = 18. + * After processing the above example, there would be the following positions, for the given index: + * 1) with index = 0, start = 0, stop = 3. + * 2) with index = 1, start = 5, stop = 9. + * 3) with index = 2, start = 11, stop = 18. * - * @param serialize - * A serialize string to de-serialize. - * @param strings - * An array of strings de-serialize from serialize. + * @param source + * A serialized string to deserialize. + * @param index + * The selected position within the serialize string to get the deserialize positions of. + * @param destination + * The deserialized string from the specified index. + * This string is NULL terminated after destination.used on success. * * @return * F_none on success. - * F_complete_not_utf_eos if end of sting is reached before a complete UTF-8 character can be processed. - * F_array_too_large (with error bit) if a buffer would exceed maximum length. + * F_none_eos on success at end of string. + * F_data_not_eos if end of string reached before index was reached (dynamic->used is set to 0). + * F_data_not on success and source.used is 0. + * + * F_complete_not_utf_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * F_memory_not (with error bit) on out of memory. * F_parameter (with error bit) if a parameter is invalid. + * + * @see f_serialize_from_simple_select() + * @see f_string_append() */ -#ifndef _di_f_serialize_un_simple_ - extern f_status_t f_serialize_un_simple(const f_string_static_t serialize, f_string_dynamics_t * const strings); -#endif // _di_f_serialize_un_simple_ +#ifndef _di_f_serialize_from_simple_get_ + extern f_status_t f_serialize_from_simple_get(const f_string_static_t source, const f_array_length_t index, f_string_dynamic_t * const destination); +#endif // _di_f_serialize_from_simple_get_ /** * Identify string positions within a serialize string using the Simple serialize algorithm. @@ -89,78 +108,89 @@ extern "C" { * 2) start = 5, stop = 9. * 3) start = 11, stop = 18. * - * @param serialize - * A serialize string to de-serialize. - * @param locations - * The locations within the serialize string representing distinct separate strings. + * @param source + * A serialized string to deserialize. + * @param ranges + * The ranges within the serialize string representing distinct separate strings. + * All deserialized ranges are appended to the destination. * * @return * F_none on success. - * F_complete_not_utf_eos if end of sting is reached before a complete UTF-8 character can be processed. - * F_array_too_large (with error bit) if a buffer would exceed memory max length. - * F_memory_not (with error bit) on out of memory. + * F_complete_not_utf_eos if an incomplete UTF-8 character is found at the end of the source. + * F_data_not on success and source.used is 0. + * * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from f_string_ranges_increase() + * + * @see f_string_ranges_increase() */ -#ifndef _di_f_serialize_un_simple_map_ - extern f_status_t f_serialize_un_simple_map(const f_string_static_t serialize, f_string_ranges_t * const locations); -#endif // _di_f_serialize_un_simple_map_ +#ifndef _di_f_serialize_from_simple_range_ + extern f_status_t f_serialize_from_simple_range(const f_string_static_t source, f_string_ranges_t * const ranges); +#endif // _di_f_serialize_from_simple_range_ /** - * Unserialize and find the address for a specific string using the Simple serialize algorithm. + * Deserialize and select the address for a specific string using the Simple serialize algorithm. * - * The simple Serialize algorithm is akin to the PATH environment variable, example: PATH="/bin:/sbin:/usr/bin". + * The simple serialize algorithm is akin to the PATH environment variable, example: PATH="/bin:/sbin:/usr/bin". * * After processing the above example, there would be the following positions, for the given index: * 1) with index = 0, start = 0, stop = 3. * 2) with index = 1, start = 5, stop = 9. * 3) with index = 2, start = 11, stop = 18. * - * @param serialize - * A serialize string to de-serialize. + * @param source + * A serialized string to deserialize. * @param index * An index position within the serialize string to get the deserialize positions of. - * @param location - * A location within the serialize string representing the string at the given index. + * @param range + * A range within the serialized string representing the string at the given index. * * @return * F_none on success. * F_none_eos on success at end of string. + * F_data_not on success and source.used is 0. * F_data_not_eos if end of string reached before index was reached. + * * F_complete_not_utf_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * F_parameter (with error bit) if a parameter is invalid. */ -#ifndef _di_f_serialize_un_simple_find_ - extern f_status_t f_serialize_un_simple_find(const f_string_static_t serialize, const f_array_length_t index, f_string_range_t * const location); -#endif // _di_f_serialize_un_simple_find_ +#ifndef _di_f_serialize_from_simple_select_ + extern f_status_t f_serialize_from_simple_select(const f_string_static_t source, const f_array_length_t index, f_string_range_t * const range); +#endif // _di_f_serialize_from_simple_select_ /** - * Unserialize and get a copy of a specific string using the Simple serialize algorithm. + * Serialized a string using the Simple serialize algorithm. * * The simple Serialize algorithm is akin to the PATH environment variable, example: PATH="/bin:/sbin:/usr/bin". * - * After processing the above example, there would be the following positions, for the given index: - * 1) with index = 0, start = 0, stop = 3. - * 2) with index = 1, start = 5, stop = 9. - * 3) with index = 2, start = 11, stop = 18. + * To generate the above example, this would be called 3 times, with the following strings: + * 1) value = "/bin", then: PATH="/bin". + * 2) value = "/sbin", then: PATH="/bin:/sbin". + * 3) value = "/usr/sbin", then: PATH="/bin:/sbin:/usr/sbin". * - * @param serialize - * A serialize string to de-serialize. - * @param index - * An index position within the serialize string to get the deserialize positions of. - * @param dynamic - * The unserialize string from the specified index. + * @param source + * The string to append onto serialize. + * @param destination + * The dynamic string that to store the serialized string. + * This string will be NULL terminated after destination.used on success. + * All serialized values are appended to the destination. * * @return * F_none on success. - * F_none_eos on success at end of string. - * F_data_not_eos if end of string reached before index was reached (dynamic->used is set to 0). - * F_complete_not_utf_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. - * F_memory_not (with error bit) on out of memory. + * F_data_not on success and source.used is 0. + * * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from f_string_dynamic_append(); + * Errors (with error bit) from f_string_dynamic_append_assure(); + * + * @see f_string_dynamic_append() + * @see f_string_dynamic_append_assure() */ -#ifndef _di_f_serialize_un_simple_get_ - extern f_status_t f_serialize_un_simple_get(const f_string_static_t serialize, const f_array_length_t index, f_string_dynamic_t * const dynamic); -#endif // _di_f_serialize_un_simple_get_ +#ifndef _di_f_serialize_to_simple_ + extern f_status_t f_serialize_to_simple(const f_string_static_t source, f_string_dynamic_t * const destination); +#endif // _di_f_serialize_to_simple_ #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_serialize/c/serialize/common.c b/level_0/f_serialize/c/serialize/common.c index 99063dd..e80c31d 100644 --- a/level_0/f_serialize/c/serialize/common.c +++ b/level_0/f_serialize/c/serialize/common.c @@ -5,9 +5,9 @@ extern "C" { #endif #ifndef _di_f_serialize_splitter_s_ - const f_string_static_t f_serialize_simple_splitter_s = macro_f_string_static_t_initialize(F_serialize_simple_splitter_s, 0, F_serialize_simple_splitter_s_length); - const f_string_static_t f_serialize_delimited_splitter_s = macro_f_string_static_t_initialize(F_serialize_delimited_splitter_s, 0, F_serialize_delimited_splitter_s_length); const f_string_static_t f_serialize_delimited_delimiter_s = macro_f_string_static_t_initialize(F_serialize_delimited_delimiter_s, 0, F_serialize_delimited_delimiter_s_length); + const f_string_static_t f_serialize_delimited_splitter_s = macro_f_string_static_t_initialize(F_serialize_delimited_splitter_s, 0, F_serialize_delimited_splitter_s_length); + const f_string_static_t f_serialize_to_simple_splitter_s = macro_f_string_static_t_initialize(F_serialize_simple_splitter_s, 0, F_serialize_simple_splitter_s_length); #endif // _di_f_serialize_splitter_s_ #ifdef __cplusplus diff --git a/level_0/f_serialize/c/serialize/common.h b/level_0/f_serialize/c/serialize/common.h index 7686e37..5467848 100644 --- a/level_0/f_serialize/c/serialize/common.h +++ b/level_0/f_serialize/c/serialize/common.h @@ -17,17 +17,17 @@ extern "C" { #endif #ifndef _di_f_serialize_splitter_s_ - #define F_serialize_simple_splitter_s ":" - #define F_serialize_delimited_splitter_s "'" #define F_serialize_delimited_delimiter_s "\\" + #define F_serialize_delimited_splitter_s "'" + #define F_serialize_simple_splitter_s ":" - #define F_serialize_simple_splitter_s_length 1 - #define F_serialize_delimited_splitter_s_length 1 #define F_serialize_delimited_delimiter_s_length 1 + #define F_serialize_delimited_splitter_s_length 1 + #define F_serialize_simple_splitter_s_length 1 - extern const f_string_static_t f_serialize_simple_splitter_s; - extern const f_string_static_t f_serialize_delimited_splitter_s; extern const f_string_static_t f_serialize_delimited_delimiter_s; + extern const f_string_static_t f_serialize_delimited_splitter_s; + extern const f_string_static_t f_serialize_to_simple_splitter_s; #endif // _di_f_serialize_splitter_s_ #ifdef __cplusplus